alexandria-book-collection-manager 0.6.9.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +68 -0
  4. data/.rubocop_todo.yml +200 -0
  5. data/CHANGELOG.md +23 -0
  6. data/COPYING +339 -0
  7. data/ChangeLog.0 +3598 -0
  8. data/Gemfile +9 -0
  9. data/INSTALL.rdoc +156 -0
  10. data/PACKAGING +36 -0
  11. data/README.md +88 -0
  12. data/RELEASE_CHECKLIST +18 -0
  13. data/Rakefile +264 -0
  14. data/TODO +24 -0
  15. data/alexandria-book-collection-manager.gemspec +35 -0
  16. data/alexandria.desktop.in +10 -0
  17. data/bin/alexandria +82 -0
  18. data/doc/AUTHORS +60 -0
  19. data/doc/BUGS +31 -0
  20. data/doc/FAQ +369 -0
  21. data/doc/HACKING +19 -0
  22. data/doc/NEWS +341 -0
  23. data/doc/alexandria.1 +120 -0
  24. data/doc/cuecat_support.rdoc +67 -0
  25. data/lib/alexandria.rb +85 -0
  26. data/lib/alexandria/about.rb +82 -0
  27. data/lib/alexandria/book_providers.rb +411 -0
  28. data/lib/alexandria/book_providers/adlibris.rb +235 -0
  29. data/lib/alexandria/book_providers/amazon_aws.rb +261 -0
  30. data/lib/alexandria/book_providers/amazon_ecs_util.rb +405 -0
  31. data/lib/alexandria/book_providers/barnes_and_noble.rb +229 -0
  32. data/lib/alexandria/book_providers/bol_it.rb +162 -0
  33. data/lib/alexandria/book_providers/deastore.rb +277 -0
  34. data/lib/alexandria/book_providers/douban.rb +135 -0
  35. data/lib/alexandria/book_providers/ibs_it.rb +149 -0
  36. data/lib/alexandria/book_providers/mcu.rb +177 -0
  37. data/lib/alexandria/book_providers/proxis.rb +205 -0
  38. data/lib/alexandria/book_providers/pseudomarc.rb +185 -0
  39. data/lib/alexandria/book_providers/renaud.rb +142 -0
  40. data/lib/alexandria/book_providers/siciliano.rb +271 -0
  41. data/lib/alexandria/book_providers/thalia.rb +197 -0
  42. data/lib/alexandria/book_providers/web.rb +59 -0
  43. data/lib/alexandria/book_providers/webster_it.rb +173 -0
  44. data/lib/alexandria/book_providers/worldcat.rb +251 -0
  45. data/lib/alexandria/book_providers/z3950.rb +422 -0
  46. data/lib/alexandria/config.rb +8 -0
  47. data/lib/alexandria/console.rb +31 -0
  48. data/lib/alexandria/execution_queue.rb +96 -0
  49. data/lib/alexandria/export_library.rb +536 -0
  50. data/lib/alexandria/import_library.rb +316 -0
  51. data/lib/alexandria/import_library_csv.rb +270 -0
  52. data/lib/alexandria/logging.rb +159 -0
  53. data/lib/alexandria/models/book.rb +72 -0
  54. data/lib/alexandria/models/library.rb +714 -0
  55. data/lib/alexandria/net.rb +53 -0
  56. data/lib/alexandria/preferences.rb +324 -0
  57. data/lib/alexandria/scanners.rb +42 -0
  58. data/lib/alexandria/scanners/cuecat.rb +118 -0
  59. data/lib/alexandria/scanners/keyboard.rb +57 -0
  60. data/lib/alexandria/smart_library.rb +525 -0
  61. data/lib/alexandria/ui.rb +53 -0
  62. data/lib/alexandria/ui/builder_base.rb +43 -0
  63. data/lib/alexandria/ui/callbacks.rb +389 -0
  64. data/lib/alexandria/ui/completion_models.rb +228 -0
  65. data/lib/alexandria/ui/dialogs/about_dialog.rb +59 -0
  66. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +640 -0
  67. data/lib/alexandria/ui/dialogs/alert_dialog.rb +68 -0
  68. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +43 -0
  69. data/lib/alexandria/ui/dialogs/barcode_animation.rb +159 -0
  70. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +210 -0
  71. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +432 -0
  72. data/lib/alexandria/ui/dialogs/export_dialog.rb +172 -0
  73. data/lib/alexandria/ui/dialogs/import_dialog.rb +205 -0
  74. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +85 -0
  75. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +639 -0
  76. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +153 -0
  77. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +67 -0
  78. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +587 -0
  79. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +56 -0
  80. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +432 -0
  81. data/lib/alexandria/ui/dndable.rb +81 -0
  82. data/lib/alexandria/ui/gtk_thread_help.rb +88 -0
  83. data/lib/alexandria/ui/icons.rb +100 -0
  84. data/lib/alexandria/ui/iconview.rb +91 -0
  85. data/lib/alexandria/ui/iconview_tooltips.rb +162 -0
  86. data/lib/alexandria/ui/init.rb +93 -0
  87. data/lib/alexandria/ui/libraries_combo.rb +75 -0
  88. data/lib/alexandria/ui/listview.rb +310 -0
  89. data/lib/alexandria/ui/main_app.rb +67 -0
  90. data/lib/alexandria/ui/multi_drag_treeview.rb +150 -0
  91. data/lib/alexandria/ui/sidepane.rb +194 -0
  92. data/lib/alexandria/ui/sound.rb +107 -0
  93. data/lib/alexandria/ui/ui_manager.rb +1308 -0
  94. data/lib/alexandria/undo_manager.rb +78 -0
  95. data/lib/alexandria/utils.rb +30 -0
  96. data/lib/alexandria/version.rb +24 -0
  97. data/lib/alexandria/web_themes.rb +75 -0
  98. data/misc/sounds/README +15 -0
  99. data/misc/sounds/bad_scan.csd +62 -0
  100. data/misc/sounds/good_scan.csd +61 -0
  101. data/misc/sounds/scanning.csd +46 -0
  102. data/po/ChangeLog +488 -0
  103. data/po/Makefile +44 -0
  104. data/po/README +29 -0
  105. data/po/commit-po +72 -0
  106. data/po/cs.po +1437 -0
  107. data/po/cy.po +1521 -0
  108. data/po/de.po +1400 -0
  109. data/po/el.po +1379 -0
  110. data/po/es.po +1376 -0
  111. data/po/fr.po +1420 -0
  112. data/po/ga.po +1359 -0
  113. data/po/gl.po +1397 -0
  114. data/po/it.po +1406 -0
  115. data/po/ja.po +1355 -0
  116. data/po/mk.po +1373 -0
  117. data/po/nb.po +1386 -0
  118. data/po/nl.po +1405 -0
  119. data/po/pl.po +1373 -0
  120. data/po/pt.po +1398 -0
  121. data/po/pt_BR.po +1409 -0
  122. data/po/ru.po +1372 -0
  123. data/po/sk.po +1380 -0
  124. data/po/sv.po +1402 -0
  125. data/po/uk.po +1423 -0
  126. data/po/zh_TW.po +1394 -0
  127. data/schemas/alexandria.schemas +300 -0
  128. data/share/alexandria/glade/acquire_dialog__builder.glade +201 -0
  129. data/share/alexandria/glade/book_properties_dialog__builder.glade +910 -0
  130. data/share/alexandria/glade/main_app__builder.glade +229 -0
  131. data/share/alexandria/glade/new_book_dialog__builder.glade +379 -0
  132. data/share/alexandria/glade/preferences_dialog__builder.glade +733 -0
  133. data/share/alexandria/icons/alexandria.png +0 -0
  134. data/share/alexandria/icons/alexandria_small.png +0 -0
  135. data/share/alexandria/icons/book.png +0 -0
  136. data/share/alexandria/icons/book_icon.png +0 -0
  137. data/share/alexandria/icons/book_small.png +0 -0
  138. data/share/alexandria/icons/cuecat.png +0 -0
  139. data/share/alexandria/icons/cuecat_inactive.png +0 -0
  140. data/share/alexandria/icons/favorite_tag.png +0 -0
  141. data/share/alexandria/icons/less.png +0 -0
  142. data/share/alexandria/icons/library.png +0 -0
  143. data/share/alexandria/icons/library_small.png +0 -0
  144. data/share/alexandria/icons/lookup.png +0 -0
  145. data/share/alexandria/icons/more.png +0 -0
  146. data/share/alexandria/icons/no_cover.png +0 -0
  147. data/share/alexandria/icons/smart_library.png +0 -0
  148. data/share/alexandria/icons/smart_library_small.png +0 -0
  149. data/share/alexandria/icons/star_set.png +0 -0
  150. data/share/alexandria/icons/star_unset.png +0 -0
  151. data/share/alexandria/icons/view_as_icons.png +0 -0
  152. data/share/alexandria/icons/view_as_list.png +0 -0
  153. data/share/alexandria/ui/menus.xml +91 -0
  154. data/share/alexandria/ui/popups.xml +91 -0
  155. data/share/alexandria/web-themes/clean/clean.css +85 -0
  156. data/share/alexandria/web-themes/clean/preview.jpg +0 -0
  157. data/share/alexandria/web-themes/list/list.css +105 -0
  158. data/share/alexandria/web-themes/list/preview.jpg +0 -0
  159. data/share/app-icon/16x16/alexandria.png +0 -0
  160. data/share/app-icon/16x16/alexandria.svg +263 -0
  161. data/share/app-icon/22x22/alexandria.png +0 -0
  162. data/share/app-icon/22x22/alexandria.svg +465 -0
  163. data/share/app-icon/24x24/alexandria.png +0 -0
  164. data/share/app-icon/32x32/alexandria.png +0 -0
  165. data/share/app-icon/32x32/alexandria.svg +813 -0
  166. data/share/app-icon/32x32/alexandria.xpm +241 -0
  167. data/share/app-icon/48x48/alexandria.png +0 -0
  168. data/share/app-icon/scalable/alexandria.svg +700 -0
  169. data/share/gnome/help/alexandria/C/about.xml +44 -0
  170. data/share/gnome/help/alexandria/C/adding-books.xml +339 -0
  171. data/share/gnome/help/alexandria/C/alexandria.xml +185 -0
  172. data/share/gnome/help/alexandria/C/bugs.xml +18 -0
  173. data/share/gnome/help/alexandria/C/editing-book-properties.xml +124 -0
  174. data/share/gnome/help/alexandria/C/exporting.xml +81 -0
  175. data/share/gnome/help/alexandria/C/figures/adding_books_acquire_from_scanner_process.png +0 -0
  176. data/share/gnome/help/alexandria/C/figures/adding_books_add_by_isbn.png +0 -0
  177. data/share/gnome/help/alexandria/C/figures/adding_books_isbn_import.png +0 -0
  178. data/share/gnome/help/alexandria/C/figures/adding_books_manual_details.png +0 -0
  179. data/share/gnome/help/alexandria/C/figures/adding_books_rename_library_after_import.png +0 -0
  180. data/share/gnome/help/alexandria/C/figures/adding_books_search_results.png +0 -0
  181. data/share/gnome/help/alexandria/C/figures/editing_book_properties_info.png +0 -0
  182. data/share/gnome/help/alexandria/C/figures/editing_book_properties_loaning.png +0 -0
  183. data/share/gnome/help/alexandria/C/figures/exporting_information_html.png +0 -0
  184. data/share/gnome/help/alexandria/C/figures/getting_started_first_launched.png +0 -0
  185. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view.png +0 -0
  186. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view_search.png +0 -0
  187. data/share/gnome/help/alexandria/C/figures/settings_providers_new_z3950.png +0 -0
  188. data/share/gnome/help/alexandria/C/figures/smart_libraries_new_smart_library.png +0 -0
  189. data/share/gnome/help/alexandria/C/figures/working_with_libraries_library_pane.png +0 -0
  190. data/share/gnome/help/alexandria/C/getting-started.xml +154 -0
  191. data/share/gnome/help/alexandria/C/gnu-fdl-1.2.xml +543 -0
  192. data/share/gnome/help/alexandria/C/introduction.xml +142 -0
  193. data/share/gnome/help/alexandria/C/searching.xml +90 -0
  194. data/share/gnome/help/alexandria/C/settings.xml +140 -0
  195. data/share/gnome/help/alexandria/C/smart-libraries.xml +160 -0
  196. data/share/gnome/help/alexandria/C/working-with-libraries.xml +76 -0
  197. data/share/gnome/help/alexandria/ChangeLog +99 -0
  198. data/share/gnome/help/alexandria/fr/alexandria.xml +2292 -0
  199. data/share/gnome/help/alexandria/fr/figures/alexandria_add_button.png +0 -0
  200. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_isbn_1.png +0 -0
  201. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_search_1.png +0 -0
  202. data/share/gnome/help/alexandria/fr/figures/alexandria_add_manually.png +0 -0
  203. data/share/gnome/help/alexandria/fr/figures/alexandria_add_z3950.png +0 -0
  204. data/share/gnome/help/alexandria/fr/figures/alexandria_close_button.png +0 -0
  205. data/share/gnome/help/alexandria/fr/figures/alexandria_edit_info.png +0 -0
  206. data/share/gnome/help/alexandria/fr/figures/alexandria_export_web_page.png +0 -0
  207. data/share/gnome/help/alexandria/fr/figures/alexandria_importing.png +0 -0
  208. data/share/gnome/help/alexandria/fr/figures/alexandria_library_pane.png +0 -0
  209. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view.png +0 -0
  210. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view_search.png +0 -0
  211. data/share/gnome/help/alexandria/fr/figures/alexandria_loaning.png +0 -0
  212. data/share/gnome/help/alexandria/fr/figures/alexandria_main_window.png +0 -0
  213. data/share/gnome/help/alexandria/fr/figures/alexandria_remove_button.png +0 -0
  214. data/share/gnome/help/alexandria/ja/about.xml +33 -0
  215. data/share/gnome/help/alexandria/ja/adding-books.xml +314 -0
  216. data/share/gnome/help/alexandria/ja/alexandria.xml +172 -0
  217. data/share/gnome/help/alexandria/ja/bugs.xml +11 -0
  218. data/share/gnome/help/alexandria/ja/editing-book-properties.xml +100 -0
  219. data/share/gnome/help/alexandria/ja/exporting.xml +98 -0
  220. data/share/gnome/help/alexandria/ja/figures/adding_books_acquire_from_scanner_process.png +0 -0
  221. data/share/gnome/help/alexandria/ja/figures/adding_books_add_by_isbn.png +0 -0
  222. data/share/gnome/help/alexandria/ja/figures/adding_books_isbn_import.png +0 -0
  223. data/share/gnome/help/alexandria/ja/figures/adding_books_manual_details.png +0 -0
  224. data/share/gnome/help/alexandria/ja/figures/adding_books_rename_library_after_import.png +0 -0
  225. data/share/gnome/help/alexandria/ja/figures/adding_books_search_results.png +0 -0
  226. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_info.png +0 -0
  227. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_loaning.png +0 -0
  228. data/share/gnome/help/alexandria/ja/figures/exporting_information_html.png +0 -0
  229. data/share/gnome/help/alexandria/ja/figures/getting_started_first_launched.png +0 -0
  230. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view.png +0 -0
  231. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view_search.png +0 -0
  232. data/share/gnome/help/alexandria/ja/figures/settings_providers_new_z3950.png +0 -0
  233. data/share/gnome/help/alexandria/ja/figures/smart_libraries_new_smart_library.png +0 -0
  234. data/share/gnome/help/alexandria/ja/figures/working_with_libraries_library_pane.png +0 -0
  235. data/share/gnome/help/alexandria/ja/getting-started.xml +144 -0
  236. data/share/gnome/help/alexandria/ja/gnu-fdl-1.2.xml +541 -0
  237. data/share/gnome/help/alexandria/ja/introduction.xml +134 -0
  238. data/share/gnome/help/alexandria/ja/searching.xml +104 -0
  239. data/share/gnome/help/alexandria/ja/settings.xml +129 -0
  240. data/share/gnome/help/alexandria/ja/smart-libraries.xml +140 -0
  241. data/share/gnome/help/alexandria/ja/working-with-libraries.xml +88 -0
  242. data/share/menu/alexandria +7 -0
  243. data/share/omf/alexandria/alexandria-C.omf.in +27 -0
  244. data/share/omf/alexandria/alexandria-fr.omf.in +30 -0
  245. data/share/sounds/alexandria/bad_scan.ogg +0 -0
  246. data/share/sounds/alexandria/bad_scan.wav +0 -0
  247. data/share/sounds/alexandria/good_scan.ogg +0 -0
  248. data/share/sounds/alexandria/good_scan.wav +0 -0
  249. data/share/sounds/alexandria/scanning.ogg +0 -0
  250. data/share/sounds/alexandria/scanning.wav +0 -0
  251. data/spec/alexandria/library_spec.rb +205 -0
  252. data/spec/alexandria/preferences_spec.rb +22 -0
  253. data/spec/alexandria/scanners/cuecat_spec.rb +68 -0
  254. data/spec/alexandria/smart_library_spec.rb +22 -0
  255. data/spec/alexandria/ui/dialogs_spec.rb +90 -0
  256. data/spec/alexandria/ui/iconview_spec.rb +27 -0
  257. data/spec/alexandria/ui/listview_spec.rb +28 -0
  258. data/spec/alexandria/ui/main_app_spec.rb +48 -0
  259. data/spec/alexandria/ui/sidepane_spec.rb +27 -0
  260. data/spec/alexandria/ui/ui_manager_spec.rb +26 -0
  261. data/spec/alexandria/ui/ui_utilities_spec.rb +60 -0
  262. data/spec/alexandria/utilities_spec.rb +50 -0
  263. data/spec/data/libraries/0.6.1-noisbn/My Library/0201398257.yaml +10 -0
  264. data/spec/data/libraries/0.6.1-noisbn/My Library/1565920007.yaml +10 -0
  265. data/spec/data/libraries/0.6.1/My Library/0192812173.yaml +9 -0
  266. data/spec/data/libraries/0.6.1/My Library/0201398257.cover +0 -0
  267. data/spec/data/libraries/0.6.1/My Library/0201398257.yaml +10 -0
  268. data/spec/data/libraries/0.6.1/My Library/1565920007.yaml +10 -0
  269. data/spec/data/libraries/0.6.2/My Library/9780140266146.cover +0 -0
  270. data/spec/data/libraries/0.6.2/My Library/9780140266146.yaml +16 -0
  271. data/spec/data/libraries/0.6.2/My Library/9780140278781.cover +0 -0
  272. data/spec/data/libraries/0.6.2/My Library/9780140278781.yaml +21 -0
  273. data/spec/data/libraries/0.6.2/My Library/9780571147168.cover +0 -0
  274. data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +20 -0
  275. data/spec/data/libraries/0.6.2/My Library/9780575079038.cover +0 -0
  276. data/spec/data/libraries/0.6.2/My Library/9780575079038.yaml +20 -0
  277. data/spec/data/libraries/0.6.2/My Library/9780755322800.cover +0 -0
  278. data/spec/data/libraries/0.6.2/My Library/9780755322800.yaml +20 -0
  279. data/spec/spec_helper.rb +46 -0
  280. data/tasks/rdoc.rake +6 -0
  281. data/tasks/setup.rb +30 -0
  282. data/tasks/spec.rake +29 -0
  283. data/tasks/test.rake +38 -0
  284. data/test/application_test.rb +39 -0
  285. data/test/book_test.rb +34 -0
  286. data/test/data/isbns.txt +3 -0
  287. data/test/isbn_test.rb +68 -0
  288. data/test/providers_test.rb +254 -0
  289. data/test/test_helper.rb +42 -0
  290. data/util/rake/fileinstall.rb +313 -0
  291. data/util/rake/gettextgenerate.rb +158 -0
  292. data/util/rake/omfgenerate.rb +79 -0
  293. metadata +452 -0
@@ -0,0 +1,162 @@
1
+ # Copyright (C) 2007 Marco Costantini
2
+ # Copyright (C) 2014 Matijs van Zuijlen
3
+ # based on ibs_it.rb by Claudio Belotti
4
+ #
5
+ # Alexandria is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # Alexandria is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public
16
+ # License along with Alexandria; see the file COPYING. If not,
17
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
+ # Fifth Floor, Boston, MA 02110-1301 USA.
19
+
20
+ require 'fileutils'
21
+ require 'net/http'
22
+ require 'open-uri'
23
+ # require 'cgi'
24
+
25
+ module Alexandria
26
+ class BookProviders
27
+ class BOL_itProvider < GenericProvider
28
+ BASE_URI = 'http://www.bol.it'
29
+ CACHE_DIR = File.join(Alexandria::Library::DIR, '.bol_it_cache')
30
+ REFERER = BASE_URI
31
+ LOCALE = 'libri' # possible locales are: "libri", "inglesi", "video", "musica", "choco"
32
+ def initialize
33
+ super('BOL_it', 'BOL (Italy)')
34
+ FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR)
35
+ # no preferences for the moment
36
+ at_exit { clean_cache }
37
+ end
38
+
39
+ def search(criterion, type)
40
+ criterion = criterion.convert('ISO-8859-1', 'UTF-8')
41
+ req = BASE_URI + '/' + LOCALE + '/'
42
+ req += case type
43
+ when SEARCH_BY_ISBN
44
+ 'scheda/'
45
+
46
+ when SEARCH_BY_TITLE
47
+ 'risultatoricerca?action=bolrisultatoricerca&skin=bol&filtro_ricerca=BOL&quick_type=Titolo&titolo='
48
+
49
+ when SEARCH_BY_AUTHORS
50
+ 'risultatoricerca?action=bolrisultatoricerca&skin=bol&filtro_ricerca=BOL&quick_type=Autore&titolo='
51
+
52
+ when SEARCH_BY_KEYWORD
53
+ 'risultatoricerca?action=bolrisultatoricerca&skin=bol&filtro_ricerca=BOL&quick_type=Parola%20chiave&titolo='
54
+
55
+ else
56
+ raise InvalidSearchTypeError
57
+
58
+ end
59
+
60
+ ## warning: this provider uses pages like http://www.bol.it/libri/scheda/ea978888584104 with 12 numbers, without the checksum
61
+ criterion = 'ea' + Library.canonicalise_ean(criterion)[0..-2] + '.html' if type == SEARCH_BY_ISBN
62
+ req += CGI.escape(criterion)
63
+ p req if $DEBUG
64
+ data = transport.get(URI.parse(req))
65
+ if type == SEARCH_BY_ISBN
66
+ to_book(data) # rescue raise NoResultsError
67
+ else
68
+ begin
69
+ results = []
70
+ each_book_page(data) do |code, _title|
71
+ results << to_book(transport.get(URI.parse(BASE_URI + "/#{LOCALE}/scheda/ea" + code)))
72
+ end
73
+ return results
74
+ rescue
75
+ raise NoResultsError
76
+ end
77
+ end
78
+ end
79
+
80
+ def url(book)
81
+ BASE_URI + "/#{LOCALE}/scheda/ea" + Library.canonicalise_ean(book.isbn)[0..-2] + '.html'
82
+ end
83
+
84
+ #######
85
+ private
86
+ #######
87
+
88
+ def to_book(data)
89
+ raise NoResultsError if /Scheda libro non completa \(TP null\)/.match(data)
90
+ data = data.convert('UTF-8', 'ISO-8859-1')
91
+
92
+ md = /<INPUT type =hidden name ="mailTitolo" value="([^"]+)/.match(data)
93
+ raise 'No title' unless md
94
+ title = CGI.unescape(md[1].strip)
95
+
96
+ authors = []
97
+ if (md = /<INPUT type =HIDDEN name ="mailAutore" value="([^"]+)/.match(data))
98
+ md[1].strip.split(', ').each { |a| authors << CGI.unescape(a.strip) }
99
+ end
100
+
101
+ md = /<INPUT type =HIDDEN name ="mailEAN" value="([^"]+)/.match(data)
102
+ raise 'No ISBN' unless md
103
+ isbn = md[1].strip
104
+ isbn += String(Library.ean_checksum(Library.extract_numbers(isbn)))
105
+
106
+ # raise unless
107
+ md = /<INPUT type =HIDDEN name ="mailEditore" value="([^"]+)/.match(data)
108
+ publisher = CGI.unescape(md[1].strip) or md
109
+
110
+ # raise unless
111
+ md = /<INPUT type =HIDDEN name ="mailFormato" value="([^"]+)/.match(data)
112
+ edition = CGI.unescape(md[1].strip) or md
113
+
114
+ if (md = /#{edition}\&nbsp\;\|\&nbsp\;(\d+)\&nbsp\;\|\&nbsp\;/.match(data))
115
+ nr_pages = CGI.unescape(md[1].strip)
116
+ elsif (md = / (\d+) pagine \| /.match(data))
117
+ nr_pages = CGI.unescape(md[1].strip)
118
+ end
119
+ if nr_pages != '0' and !nr_pages.nil?
120
+ edition = nr_pages + ' p., ' + edition
121
+ end
122
+
123
+ publish_year = nil
124
+ if (md = /<INPUT type =HIDDEN name ="mailAnnoPubbl" value="([^"]+)/.match(data))
125
+ publish_year = CGI.unescape(md[1].strip).to_i
126
+ publish_year = nil if publish_year == 0
127
+ end
128
+
129
+ cover_url = BASE_URI + '/bol/includes/tornaImmagine.jsp?cdSoc=BL&ean=' + isbn[0..11] + '&tipoOggetto=PIB&cdSito=BL' # use "FRB" instead of "PIB" for smaller images
130
+ cover_filename = isbn + '.tmp'
131
+ Dir.chdir(CACHE_DIR) do
132
+ File.open(cover_filename, 'w') do |file|
133
+ file.write open(cover_url, 'Referer' => REFERER).read
134
+ end
135
+ end
136
+
137
+ medium_cover = CACHE_DIR + '/' + cover_filename
138
+ if File.size(medium_cover) > 43 and File.size(medium_cover) != 2382 # 2382 is the size of the fake image "copertina non disponibile"
139
+ puts medium_cover + ' has non-0 size' if $DEBUG
140
+ return [Book.new(title, authors, isbn, publisher, publish_year, edition), medium_cover]
141
+ end
142
+ puts medium_cover + ' has 0 size, removing ...' if $DEBUG
143
+ File.delete(medium_cover)
144
+ [Book.new(title, authors, isbn, publisher, publish_year, edition)]
145
+ end
146
+
147
+ def each_book_page(data)
148
+ raise if data.scan(/<a href="\/#{LOCALE}\/scheda\/ea(\d+)\.html;jsessionid=[^"]+">\s*Scheda completa\s*<\/a>/) { |a| yield a }.empty?
149
+ end
150
+
151
+ def clean_cache
152
+ # FIXME begin ... rescue ... end?
153
+ Dir.chdir(CACHE_DIR) do
154
+ Dir.glob('*.tmp') do |file|
155
+ puts 'removing ' + file if $DEBUG
156
+ File.delete(file)
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,277 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2009 Cathal Mc Ginley
4
+ # Copyright (C) 2011, 2014 Matijs van Zuijlen
5
+ #
6
+ # Alexandria is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation; either version 2 of the
9
+ # License, or (at your option) any later version.
10
+ #
11
+ # Alexandria is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public
17
+ # License along with Alexandria; see the file COPYING. If not,
18
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
+ # Fifth Floor, Boston, MA 02110-1301 USA.
20
+
21
+ # New DeaStore provider, taken from the Palatina MetaDataSource and
22
+ # modified to fit the structure of Alexandria book providers.
23
+ # (24 Feb 2009)
24
+
25
+ require 'cgi'
26
+ require 'alexandria/net'
27
+ require 'alexandria/book_providers/web'
28
+
29
+ module Alexandria
30
+ class BookProviders
31
+ class DeaStoreProvider < WebsiteBasedProvider
32
+ include Alexandria::Logging
33
+
34
+ SITE = 'http://www.deastore.com'
35
+ BASE_SEARCH_URL = "#{SITE}/search/italian_books/0/%s/%s" # type/term
36
+
37
+ def initialize
38
+ super('DeaStore', 'DeaStore (Italy)')
39
+ prefs.read
40
+ @agent = nil
41
+ end
42
+
43
+ def agent
44
+ unless @agent
45
+ @agent = Alexandria::WWWAgent.new
46
+ @agent.language = :it
47
+ end
48
+ @agent
49
+ end
50
+
51
+ def get_book_from_search_result(result)
52
+ log.debug { "Fetching book from #{result[:url]}" }
53
+ html_data = agent.get(result[:url])
54
+ # File.open("rsltflarn#{Time.now().usec()}.html", 'wb') do |f|
55
+ # f.write(html_data.body)
56
+ # end
57
+ parse_result_data(html_data.body)
58
+ end
59
+
60
+ def search(criterion, type)
61
+ begin
62
+ criterion = criterion.convert('ISO-8859-1', 'UTF-8') # still needed??
63
+ rescue GLib::ConvertError
64
+ log.info { "Cannot search for non-ISO-8859-1 terms at DeaStore : #{criterion}" }
65
+ raise NoResultsError
66
+ end
67
+ html_data = agent.get(create_search_uri(type, criterion))
68
+ # File.open("flarn#{Time.now().usec()}.html", 'wb') do |f|
69
+ # f.write(html_data.body)
70
+ # end
71
+ results = parse_search_result_data(html_data.body)
72
+ raise NoResultsError if results.empty?
73
+
74
+ if type == SEARCH_BY_ISBN
75
+ get_book_from_search_result(results.first)
76
+ else
77
+ results.map { |result| get_book_from_search_result(result) }
78
+ end
79
+ end
80
+
81
+ # it isn't possible to create a URL for a book given only the ISBN...
82
+ def url(_book)
83
+ nil
84
+ end
85
+
86
+ private
87
+
88
+ def create_search_uri(search_type, search_term)
89
+ # bah! very, very similar to the siciliano code! refactor out this duplication
90
+ search_type_code = { SEARCH_BY_ISBN => 'isbn',
91
+ SEARCH_BY_TITLE => 'title',
92
+ SEARCH_BY_AUTHORS => 'author',
93
+ SEARCH_BY_KEYWORD => 'keywords'
94
+ }[search_type] or 'keywords'
95
+
96
+ search_term_encoded = search_term
97
+ if search_type == SEARCH_BY_ISBN
98
+ search_term_encoded = Library.canonicalise_isbn(search_term) # isbn-10
99
+ else
100
+ search_term_encoded = CGI.escape(search_term)
101
+ end
102
+
103
+ uri = BASE_SEARCH_URL % [search_type_code, search_term_encoded]
104
+ log.debug { uri }
105
+ uri
106
+ end
107
+
108
+ def parse_search_result_data(html)
109
+ doc = html_to_doc(html)
110
+ book_search_results = []
111
+
112
+ result_divs = doc.search('div.scheda_prodotto')
113
+ result_divs.each do |div|
114
+ begin
115
+ # The layout...
116
+ # a > img
117
+ # div.scheda_content
118
+ # a[link->productpage] title ## a.titolo_link
119
+ # p (genre I think) ## !ignore
120
+ # a[link->author] author ## a.info
121
+ # p.editore (publisher? editor?)
122
+ # p Data di pubblicazione: \n 2009
123
+ # p.prezzo (price)
124
+
125
+ # cover_url = ''
126
+ # cover_images = div/'a/img'
127
+ # unless cover_images.empty?
128
+ # img = cover_images.first
129
+ # image_url = img['src']
130
+ # if image_url =~ /^http/
131
+ # cover_url = '' # image_url
132
+ # elsif image_url[0..0] != '/'
133
+ # cover_url = "#{SITE}/#{image_url}"
134
+ # else
135
+ # cover_url = "#{SITE}#{image_url}"
136
+ # end
137
+ # log.debug { "Search Cover Image URL #{cover_url}" }
138
+
139
+ # end
140
+
141
+ content = div / 'div.scheda_content'
142
+ title_link = (content / :a).first
143
+ title = normalize(title_link.inner_text)
144
+ link_to_description = title_link['href']
145
+ lookup_url = "#{SITE}#{link_to_description}"
146
+
147
+ authors = []
148
+ (content / 'a.info').each do |link|
149
+ authors << normalize(link.inner_text)
150
+ end
151
+
152
+ result = {}
153
+ result[:author] = authors.first # HACK, what about multiple authors
154
+ result[:title] = title
155
+ result[:url] = lookup_url
156
+
157
+ publishers = (content / 'p.editore')
158
+ unless publishers.empty?
159
+ result[:publisher] = normalize(publishers.first.inner_text)
160
+ end
161
+
162
+ book_search_results << result
163
+ rescue => ex
164
+ trace = ex.backtrace.join("\n> ")
165
+ log.error { "Failed parsing DeaStore search page #{ex.message}\n#{trace}" }
166
+ end
167
+ end
168
+ book_search_results
169
+ end
170
+
171
+ def parse_result_data(html)
172
+ doc = html_to_doc(html)
173
+ data = doc % 'div#dati_scheda'
174
+ # sotto_data_hdr = doc % 'div.sotto_schede/h1.titolo_sotto[text()*="Informazioni generali"]/..'
175
+ # title
176
+ title_span = data % 'h1.titolo_scheda'
177
+ title = normalize(title_span.inner_text)
178
+ # cover
179
+ cover_link = nil
180
+ cover_img = data / 'a/img'
181
+ unless cover_img.empty?
182
+ cover_link = cover_img.first['src']
183
+ end
184
+ # author(s)
185
+ authors = []
186
+ author_span = data % 'span.int_scheda[text()*=Autore]'
187
+ unless author_span
188
+ author_span = data % 'span.int_scheda[text()*=cura]' # editor
189
+ end
190
+ if author_span
191
+ author_links = author_span / 'a.info'
192
+ authors = []
193
+ author_links.each do |link|
194
+ authors << normalize(link.inner_html)
195
+ end
196
+ end
197
+ # if author_span
198
+ # author_links = author_span/'a.info'
199
+ # author_links.each do |link|
200
+ # authors << normalize(link.inner_text)
201
+ # end
202
+ # end
203
+ # publisher
204
+ publisher_par = data % 'span.int_scheda[text()*=Editore]/..'
205
+ publisher_link = publisher_par % 'a.info'
206
+ publisher = normalize(publisher_link.inner_text)
207
+ # skip 'Collana', (ummm, possibly genre information, Babelfish
208
+ # says "Necklace")
209
+ # format
210
+ format_par = data % 'span.int_scheda[text()*=Formato]/..'
211
+ format_par.inner_text =~ /:[\s]*(.+)[\s]*$/
212
+ binding = normalize(Regexp.last_match[1])
213
+ # year
214
+ date_par = data % 'span.int_scheda[text()*=Data di pubblicazione]/..'
215
+ date_par.inner_text =~ /:[\s]*([12][0-9]{3})[\s]*$/
216
+ publish_year = nil
217
+ if Regexp.last_match[1]
218
+ publish_year = Regexp.last_match[1].to_i
219
+ end
220
+ isbn_spans = data / 'div.sotto/span.isbn'
221
+ isbns = []
222
+ isbn_spans.each do |span|
223
+ span.inner_text =~ /:[\s]*(.+)[\s]*$/
224
+ isbns << Regexp.last_match[1]
225
+ end
226
+ isbn = nil
227
+ unless isbns.empty?
228
+ isbn = Library.canonicalise_isbn(isbns.first)
229
+ end
230
+ # Editore & Imprint : as publisher info above...
231
+ # pages
232
+ # page_par = data % 'span.int_scheda[text()*=Pagine]/..'
233
+ # if page_par
234
+ # page_par.inner_text =~ /:[\s]*([0-9]+)[\s]*$/
235
+ # pages = $1.to_i
236
+ # end
237
+ # synopsis_div = doc % 'div.sotto_schede' # exclude the first span though
238
+ # book = Book.new(title, isbns.first, authors)
239
+ # if publisher
240
+ # book.publisher = Publisher.new(publisher)
241
+ # end
242
+ # if format
243
+ # book.binding = CoverBinding.new(format, binding_type(format))
244
+ # end
245
+ # cover
246
+ image_url = nil
247
+ if cover_link
248
+ if cover_link =~ /^http/
249
+ # e.g. http://images.btol.com/ContentCafe/Jacket.aspx?\
250
+ # Return=1&amp;Type=M&amp;Value=9788873641803&amp;password=\
251
+ # CC70580&amp;userID=DEA40305
252
+ # seems not to work, or to be blank anyway, so set to nil
253
+ image_url = nil
254
+ elsif cover_link[0..0] != '/'
255
+ image_url = "#{SITE}/#{cover_link}"
256
+ else
257
+ image_url = "#{SITE}#{cover_link}"
258
+ end
259
+ log.debug { "Cover Image URL:: #{image_url}" }
260
+ end
261
+ book = Book.new(title, authors, isbn, publisher, publish_year, binding)
262
+ return [book, image_url]
263
+ rescue => ex
264
+ trace = ex.backtrace.join("\n> ")
265
+ log.error { "Failed parsing DeaStore product page #{ex.message}\n#{trace}" }
266
+ return nil
267
+ end
268
+
269
+ def normalize(str)
270
+ unless str.nil?
271
+ str = str.squeeze(' ').strip
272
+ end
273
+ str
274
+ end
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,135 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2009 Cathal Mc Ginley
4
+ # Copyright (C) 2010 Sun Ning
5
+ #
6
+ # Alexandria is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation; either version 2 of the
9
+ # License, or (at your option) any later version.
10
+ #
11
+ # Alexandria is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public
17
+ # License along with Alexandria; see the file COPYING. If not,
18
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
+ # Fifth Floor, Boston, MA 02110-1301 USA.
20
+
21
+ # http://book.douban.com/
22
+ # Douban.com book repository, provides many Chinese books.
23
+
24
+ # Author: Sun Ning <classicning@gmail.com>, http://sunng.info/
25
+
26
+ require 'cgi'
27
+ require 'alexandria/net'
28
+ require 'yaml'
29
+
30
+ module Alexandria
31
+ class BookProviders
32
+ class DoubanProvider < GenericProvider
33
+ include Alexandria::Logging
34
+
35
+ SITE = 'http://www.douban.com'
36
+ BASE_URL = 'http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json'
37
+
38
+ def initialize
39
+ super('Douban', 'Douban (China)')
40
+ prefs.read
41
+ end
42
+
43
+ def url(_book)
44
+ nil
45
+ end
46
+
47
+ def search(criterion, type)
48
+ keyword = criterion
49
+ request_url = BASE_URL % CGI.escape(keyword)
50
+
51
+ search_response = transport.get_response(URI.parse(request_url))
52
+
53
+ results = parse_search_result(search_response.body)
54
+ if results.length == 0
55
+ raise NoResultsError
56
+ end
57
+
58
+ if type == SEARCH_BY_ISBN
59
+ return results.first
60
+ else
61
+ return results
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ # The YAML parser in Ruby 1.8.6 chokes on the extremely
68
+ # compressed inline-style of JSON returned by Douban. (Also, it
69
+ # doesn't un-escape forward slashes).
70
+ #
71
+ # This is a quick-and-dirty method to pre-process the JSON into
72
+ # YAML-parseable format, so that we don't have to drag in a new
73
+ # dependency.
74
+ def json2yaml(json)
75
+ # insert spaces after : and , except within strings
76
+ # i.e. when followed by numeral, quote, { or [
77
+ yaml = json.gsub(/(\:|\,)([0-9'"{\[])/) do |_match|
78
+ "#{Regexp.last_match[1]} #{Regexp.last_match[2]}"
79
+ end
80
+ yaml.gsub!(/\\\//, '/') # unescape forward slashes
81
+ yaml
82
+ end
83
+
84
+ public
85
+
86
+ def parse_search_result(response)
87
+ book_search_results = []
88
+ begin
89
+ # dbresult = JSON.parse(response)
90
+ dbresult = YAML.load(json2yaml(response))
91
+ # File.open(",douban.yaml", "wb") {|f| f.write(json2yaml(response)) }
92
+ if dbresult['opensearch:totalResults']['$t'].to_i > 0
93
+ for item in dbresult['entry']
94
+ name = item['title']['$t']
95
+ isbn = nil
96
+ publisher = nil
97
+ pubdate = nil
98
+ binding = nil
99
+ for av in item['db:attribute']
100
+ if av['@name'] == 'isbn13'
101
+ isbn = av['$t']
102
+ end
103
+ if av['@name'] == 'publisher'
104
+ publisher = av['$t']
105
+ end
106
+ if av['@name'] == 'pubdate'
107
+ pubdate = av['$t']
108
+ end
109
+ if av['@name'] == 'binding'
110
+ binding = av['$t']
111
+ end
112
+ end
113
+ if item['author']
114
+ authors = item['author'].map { |a| a['name']['$t'] }
115
+ else
116
+ authors = []
117
+ end
118
+ image_url = nil
119
+ for av in item['link']
120
+ if av['@rel'] == 'image'
121
+ image_url = av['@href']
122
+ end
123
+ end
124
+ book = Book.new(name, authors, isbn, publisher, pubdate, binding)
125
+ book_search_results << [book, image_url]
126
+ end
127
+ end
128
+ rescue => ex
129
+ log.warn(ex.backtrace.join('\n'))
130
+ end
131
+ book_search_results
132
+ end
133
+ end
134
+ end
135
+ end