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,149 @@
1
+ # Copyright (C) 2005-2006 Claudio Belotti
2
+ # Copyright (C) 2014 Matijs van Zuijlen
3
+ #
4
+ # Alexandria is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License as
6
+ # published by the Free Software Foundation; either version 2 of the
7
+ # License, or (at your option) any later version.
8
+ #
9
+ # Alexandria is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public
15
+ # License along with Alexandria; see the file COPYING. If not,
16
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
+ # Fifth Floor, Boston, MA 02110-1301 USA.
18
+
19
+ require 'fileutils'
20
+ require 'net/http'
21
+ require 'open-uri'
22
+ # require 'cgi'
23
+
24
+ module Alexandria
25
+ class BookProviders
26
+ class IBS_itProvider < GenericProvider
27
+ BASE_URI = 'http://www.internetbookshop.it'
28
+ CACHE_DIR = File.join(Alexandria::Library::DIR, '.ibs_it_cache')
29
+ REFERER = BASE_URI
30
+ def initialize
31
+ super('IBS_it', 'Internet Bookshop (Italy)')
32
+ FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR)
33
+ # no preferences for the moment
34
+ at_exit { clean_cache }
35
+ end
36
+
37
+ def search(criterion, type)
38
+ criterion = criterion.convert('ISO-8859-1', 'UTF-8')
39
+ req = BASE_URI + '/ser/'
40
+ req += case type
41
+ when SEARCH_BY_ISBN
42
+ 'serdsp.asp?isbn='
43
+
44
+ when SEARCH_BY_TITLE
45
+ 'serpge.asp?Type=keyword&T='
46
+
47
+ when SEARCH_BY_AUTHORS
48
+ 'serpge.asp?Type=keyword&A='
49
+
50
+ when SEARCH_BY_KEYWORD
51
+ 'serpge.asp?Type=keyword&S='
52
+
53
+ else
54
+ raise InvalidSearchTypeError
55
+
56
+ end
57
+
58
+ req += CGI.escape(criterion)
59
+ p req if $DEBUG
60
+ data = transport.get(URI.parse(req))
61
+ if type == SEARCH_BY_ISBN
62
+ to_book(data) # rescue raise NoResultsError
63
+ else
64
+ begin
65
+ results = []
66
+ each_book_page(data) do |code, _title|
67
+ results << to_book(transport.get(URI.parse('http://www.internetbookshop.it/ser/serdsp.asp?cc=' + code)))
68
+ end
69
+ return results
70
+ rescue
71
+ raise NoResultsError
72
+ end
73
+ end
74
+ end
75
+
76
+ def url(book)
77
+ 'http://www.internetbookshop.it/ser/serdsp.asp?isbn=' + book.isbn
78
+ end
79
+
80
+ #######
81
+ private
82
+ #######
83
+
84
+ def to_book(data)
85
+ raise NoResultsError if /<b>Il libro che hai cercato non &egrave; presente nel nostro catalogo<\/b><br>/.match(data)
86
+ data = data.convert('UTF-8', 'ISO-8859-1')
87
+
88
+ md = />Titolo<\/td><td valign="top" class="lbarrasup">([^<]+)/.match(data)
89
+ raise 'No title' unless md
90
+ title = CGI.unescape(md[1].strip)
91
+
92
+ authors = []
93
+ if (md = /<b>Autore<\/b><\/td>.+<b>([^<]+)/.match(data))
94
+ md[0].strip.gsub(/<.*?>|Autore/m, ' ').split('; ').each { |a| authors << CGI.unescape(a.strip) }
95
+ end
96
+
97
+ md = /<input type=\"hidden\" name=\"isbn\" value=\"([^"]+)\">/i.match(data)
98
+ raise 'No ISBN' unless md
99
+ isbn = md[1].strip
100
+
101
+ # raise "No publisher" unless
102
+ md = /<b>Editore<\/b><\/td>.+<b>([^<]+)/.match(data)
103
+ publisher = CGI.unescape(md[1].strip) or md
104
+
105
+ # raise "No edition" unless
106
+ md = /Dati<\/b><\/td><td valign="top">([^<]+)/.match(data)
107
+ edition = CGI.unescape(md[1].strip) or md
108
+
109
+ publish_year = nil
110
+ if (md = /Anno<\/b><\/td><td valign="top">([^<]+)/.match(data))
111
+ publish_year = CGI.unescape(md[1].strip).to_i
112
+ publish_year = nil if publish_year == 0
113
+ end
114
+
115
+ md = /src="http:\/\/giotto.ibs.it\/cop\/copt13.asp\?f=(\d+)">/.match(data)
116
+ cover_url = 'http://giotto.ibs.it/cop/copt13.asp?f=' + md[1] # use copa13.asp, copt13.asp, copj13.asp, for small, medium, big image
117
+ cover_filename = isbn + '.tmp'
118
+ Dir.chdir(CACHE_DIR) do
119
+ File.open(cover_filename, 'w') do |file|
120
+ file.write open(cover_url, 'Referer' => REFERER).read
121
+ end
122
+ end
123
+
124
+ medium_cover = CACHE_DIR + '/' + cover_filename
125
+ if File.size(medium_cover) > 0 and File.size(medium_cover) != 1822 # 1822 is the size of the fake image "copertina non disponibile"
126
+ puts medium_cover + ' has non-0 size' if $DEBUG
127
+ return [Book.new(title, authors, isbn, publisher, publish_year, edition), medium_cover]
128
+ end
129
+ puts medium_cover + ' has 0 size, removing ...' if $DEBUG
130
+ File.delete(medium_cover)
131
+ [Book.new(title, authors, isbn, publisher, publish_year, edition)]
132
+ end
133
+
134
+ def each_book_page(data)
135
+ raise if data.scan(/<a href="http:\/\/www.internetbookshop.it\/ser\/serdsp.asp\?shop=1&amp;cc=([\w\d]+)"><b>([^<]+)/) { |a| yield a }.empty?
136
+ end
137
+
138
+ def clean_cache
139
+ # FIXME begin ... rescue ... end?
140
+ Dir.chdir(CACHE_DIR) do
141
+ Dir.glob('*.tmp') do |file|
142
+ puts 'removing ' + file if $DEBUG
143
+ File.delete(file)
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,177 @@
1
+ # Copyright (C) 2004 Javier Fernandez-Sanguino
2
+ # Copyright (C) 2007 Javier Fernandez-Sanguino and Marco Costantini
3
+ # Modifications Copyright (C) 2011 Matijs van Zuijlen
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 'cgi'
21
+ require 'net/http'
22
+
23
+ # http://www.mcu.es/libro/CE/AgenciaISBN/BBDDLibros/Sobre.html
24
+ # http://www.mcu.es/comun/bases/isbn/ISBN.html
25
+
26
+ module Alexandria
27
+ class BookProviders
28
+ class MCUProvider < GenericProvider
29
+ include Logging
30
+ include GetText
31
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
32
+
33
+ LANGUAGES = {
34
+ 'es' => '1'
35
+ }
36
+
37
+ # BASE_URI = "http://www.mcu.es/cgi-bin/BRSCGI3701?"
38
+ BASE_URI = 'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?'
39
+ def initialize
40
+ super('MCU', _('Spanish Culture Ministry'))
41
+ # No preferences
42
+ prefs.read
43
+ end
44
+
45
+ def search(criterion, type)
46
+ prefs.read
47
+ begin
48
+ criterion = criterion.convert('ISO-8859-1', 'UTF-8') # still needed??
49
+ rescue GLib::ConvertError
50
+ log.info { "Cannot search for non-ISO-8859-1 terms at MCU : #{criterion}" }
51
+ raise NoResultsError
52
+ end
53
+ print "Doing search with MCU #{criterion}, type: #{type}\n" if $DEBUG # for DEBUGing
54
+ req = BASE_URI + 'CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1-1000&SEPARADOR=&'
55
+ req += case type
56
+ when SEARCH_BY_ISBN
57
+ "WGEN-C=&WISB-C=#{CGI.escape(criterion)}&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
58
+
59
+ when SEARCH_BY_TITLE
60
+ "WGEN-C=&WISB-C=&WAUT-C=&WTIT-C=#{CGI.escape(criterion)}&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
61
+
62
+ when SEARCH_BY_AUTHORS
63
+ "WGEN-C=&WISB-C=&WAUT-C=#{CGI.escape(criterion)}&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
64
+
65
+ when SEARCH_BY_KEYWORD
66
+ "WGEN-C=#{CGI.escape(criterion)}&WISB-C=&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
67
+
68
+ else
69
+ raise InvalidSearchTypeError
70
+ end
71
+ products = {}
72
+ print "Request page is #{req}\n" if $DEBUG # for DEBUGing
73
+ transport.get(URI.parse(req)).each do |line|
74
+ # line = line.convert("ISO-8859-1", "UTF-8")
75
+ print "Reading line: #{line}" if $DEBUG # for DEBUGing
76
+ if (line =~ /CMD=VERDOC.*&DOCN=([^&]*)&NDOC=([^&]*)/) and (!products[Regexp.last_match[1]]) and (book = parseBook(Regexp.last_match[1], Regexp.last_match[2])) then
77
+ products[Regexp.last_match[1]] = book
78
+ puts Regexp.last_match[1] if $DEBUG # for DEBUGing
79
+ end
80
+ end
81
+
82
+ raise NoResultsError if products.values.empty?
83
+ type == SEARCH_BY_ISBN ? products.values.first : products.values
84
+ end
85
+
86
+ def url(book)
87
+ isbn = Library.canonicalise_isbn(book.isbn)
88
+ "http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1&SEPARADOR=&WGEN-C=&WISB-C=#{isbn}&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
89
+ rescue => ex
90
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
91
+ nil
92
+ end
93
+
94
+ #######
95
+ private
96
+ #######
97
+
98
+ def parseBook(docn, ndoc)
99
+ detailspage = 'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERDOC&CONF=AEISPA.cnf&BASE=ISBN&DOCN=' + docn + '&NDOC=' + ndoc
100
+ print "Looking at detailspage: #{detailspage}\n" if $DEBUG # for DEBUGing
101
+ product = {}
102
+ product['authors'] = []
103
+ robotstate = 0
104
+ transport.get(URI.parse(detailspage)).each do |line|
105
+ # This is a very crude robot interpreter
106
+ # Note that the server provides more information
107
+ # we don't store:
108
+ # - Language - Description
109
+ # - Binding - Price
110
+ # - Colection - Theme
111
+ # - CDU - Last update
112
+
113
+ # There seems to be an issue with accented chars..
114
+ line = line.convert('UTF-8', 'ISO-8859-1')
115
+ print "Reading line (robotstate #{robotstate}): #{line}" if $DEBUG # for DEBUGing
116
+ if line =~ /^<\/td>$/ or line =~ /^<\/tr>$/
117
+ robotstate = 0
118
+ elsif robotstate == 1 and line =~ /^([^<]+)</
119
+ author = Regexp.last_match[1].gsub('&nbsp;', ' ').sub(/ +$/, '')
120
+ if author.length > 3 then
121
+ # Only add authors of appropiate length
122
+ product['authors'] << author
123
+ print "Authors are #{product['authors']}\n" if $DEBUG # for DEBUGing
124
+ robotstate = 0
125
+ end
126
+ elsif robotstate == 2 and line =~ /^(.*)$/ # The title es the next line to title declaration and has not tags on web src code
127
+ product['name'] = Regexp.last_match[1].strip
128
+ print "Name is #{product['name']}\n" if $DEBUG # for DEBUGing
129
+ robotstate = 0
130
+ elsif robotstate == 3 and line =~ /^([0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]).*/
131
+ product['isbn'] = Regexp.last_match[1]
132
+ print "ISBN is #{product['isbn']}\n" if $DEBUG # for DEBUGing
133
+ robotstate = 0
134
+ elsif robotstate == 4 and line =~ /^([^<]+)</
135
+ product['manufacturer'] = Regexp.last_match[1].strip
136
+ print "Manufacturer is #{product['manufacturer']}\n" if $DEBUG # for DEBUGing
137
+ robotstate = 0
138
+ # elsif robotstate == 5 and line =~ /^([^<]+)</
139
+ elsif robotstate == 5 and line =~ /<span>([^<]+)</
140
+ product['media'] = Regexp.last_match[1].strip
141
+ print "Media is #{product['media']}\n" if $DEBUG # for DEBUGing
142
+ robotstate = 0
143
+ elsif line =~ /^.*>Autor:\s*</
144
+ robotstate = 1
145
+ elsif line =~ /^.*>T(.|&iacute;)tulo:\s*</
146
+ robotstate = 2
147
+ elsif line =~ /^.*>ISBN \(13\):\s*</
148
+ robotstate = 3
149
+ elsif line =~ /^.*>Publicaci(.|&oacute;)n:\s*</
150
+ robotstate = 4
151
+ elsif line =~ /^.*>Encuadernaci(.|&oacute;)n:\s*</
152
+ robotstate = 5
153
+ end
154
+ end
155
+
156
+ # TODO: This provider does not include picture for books
157
+ # %w{name isbn media manufacturer}.each do |field|
158
+ # print "Checking #{field} for nil\n" if $DEBUG # for DEBUGing
159
+ # product[field]="" if product[field].nil?
160
+ # end
161
+
162
+ print "Creating new book\n" if $DEBUG # for DEBUGing
163
+ book = Book.new(product['name'],
164
+ product['authors'],
165
+ product['isbn'].delete('-'),
166
+ product['manufacturer'],
167
+ nil, # TODO: furnish publish year
168
+ product['media'])
169
+ if book.title.nil?
170
+ log.warn { "No title was returned for #{book.isbn}" }
171
+ book.title = ''
172
+ end
173
+ [book]
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,205 @@
1
+ # Copyright (C) 2009 Cathal Mc Ginley
2
+ # Copyright (C) 2014 Matijs van Zuijlen
3
+ #
4
+ # Alexandria is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License as
6
+ # published by the Free Software Foundation; either version 2 of the
7
+ # License, or (at your option) any later version.
8
+ #
9
+ # Alexandria is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public
15
+ # License along with Alexandria; see the file COPYING. If not,
16
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
+ # Fifth Floor, Boston, MA 02110-1301 USA.
18
+
19
+ # New Proxis provider, taken from Palatina MetaDataSource and modified
20
+ # for Alexandria. (20 Dec 2009)
21
+
22
+ require 'cgi'
23
+ require 'alexandria/book_providers/web'
24
+
25
+ module Alexandria
26
+ class BookProviders
27
+ class ProxisProvider < WebsiteBasedProvider
28
+ # include GetText
29
+ include Alexandria::Logging
30
+ # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
31
+
32
+ # Proxis essentially has three book databases, NL, FR and EN.
33
+ # Currently, this provider only searches the NL database, since
34
+ # it adds most to Alexandria (Amazon already has French and
35
+ # English titles).
36
+
37
+ SITE = 'http://www.proxis.nl'
38
+ BASE_SEARCH_URL = "#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
39
+ '&shop=100001NL&SelRubricLevel1Id=100001NL'
40
+ ISBN_REDIRECT_BASE_URL = "#{SITE}/NLNL/Search/Index.aspx?search=%s" \
41
+ '&shop=100001NL&SelRubricLevel1Id=100001NL'
42
+
43
+ def initialize
44
+ super('Proxis', 'Proxis (Belgium)')
45
+ # prefs.add("lang", _("Language"), "fr",
46
+ # LANGUAGES.keys)
47
+ prefs.read
48
+ end
49
+
50
+ ## criterion = criterion.convert("windows-1252", "UTF-8")
51
+ ## is the above still needed??
52
+ ## current pages are returned in UTF-8, so I think probably not!
53
+
54
+ def search(criterion, type)
55
+ req = create_search_uri(type, criterion)
56
+ puts req if $DEBUG
57
+ html_data = transport.get_response(URI.parse(req))
58
+
59
+ results = parse_search_result_data(html_data.body)
60
+ raise NoResultsError if results.empty?
61
+ if type == SEARCH_BY_ISBN
62
+ get_book_from_search_result(results.first)
63
+ else
64
+ results.map { |result| get_book_from_search_result(result) }
65
+ end
66
+ end
67
+
68
+ def create_search_uri(search_type, search_term)
69
+ if search_type == SEARCH_BY_ISBN
70
+ BASE_SEARCH_URL % Library.canonicalise_ean(search_term)
71
+ else
72
+ BASE_SEARCH_URL % CGI.escape(search_term)
73
+ end
74
+ end
75
+
76
+ def get_book_from_search_result(result)
77
+ log.debug { "Fetching book from #{result[:lookup_url]}" }
78
+ html_data = transport.get_response(URI.parse(result[:lookup_url]))
79
+ parse_result_data(html_data.body)
80
+ end
81
+
82
+ def url(book)
83
+ if book.isbn.nil? or book.isbn.empty?
84
+ ISBN_REDIRECT_BASE_URL % Library.canonicalise_ean(book.isbn)
85
+ else
86
+ nil
87
+ end
88
+ end
89
+
90
+ ## from Palatina
91
+ def text_of(node)
92
+ if node.nil?
93
+ nil
94
+ else
95
+ if node.text?
96
+ node.to_html
97
+ elsif node.elem?
98
+ if node.children.nil?
99
+ return nil
100
+ else
101
+ node_text = node.children.map { |n| text_of(n) }.join
102
+ node_text.strip.squeeze(' ')
103
+ end
104
+ end
105
+ # node.inner_html.strip
106
+ end
107
+ end
108
+
109
+ def parse_search_result_data(html)
110
+ doc = html_to_doc(html)
111
+ book_search_results = []
112
+ items = (doc.search('table.searchResult tr'))
113
+ items.each do |item|
114
+ result = {}
115
+ title_link = item % 'h5 a'
116
+ if title_link
117
+ result[:title] = text_of(title_link)
118
+ result[:lookup_url] = title_link['href']
119
+ unless result[:lookup_url] =~ /^http/
120
+ result[:lookup_url] = "#{SITE}#{result[:lookup_url]}"
121
+ end
122
+ end
123
+ book_search_results << result
124
+ end
125
+ # require 'pp'
126
+ # pp book_search_results
127
+ # raise :Ruckus
128
+ book_search_results
129
+ end
130
+
131
+ def data_for_header(th)
132
+ tr = th.parent
133
+ td = tr.at('td')
134
+ if td
135
+ text_of(td)
136
+ else
137
+ nil
138
+ end
139
+ end
140
+
141
+ def parse_result_data(html)
142
+ doc = html_to_doc(html)
143
+ book_data = {}
144
+ book_data[:authors] = []
145
+ # TITLE
146
+ if (title_header = doc.search('div.detailBlock h3'))
147
+ header_spans = title_header.first.search('span')
148
+ title = text_of(header_spans.first)
149
+ if title =~ /(.+)-$/
150
+ title = Regexp.last_match[1].strip
151
+ end
152
+ book_data[:title] = title
153
+ end
154
+
155
+ info_headers = doc.search('table.productInfoTable th')
156
+
157
+ isbns = []
158
+ unless info_headers.empty?
159
+ info_headers.each do |th|
160
+ if th.inner_text =~ /(ISBN|EAN)/
161
+ isbns << data_for_header(th)
162
+ end
163
+ end
164
+ book_data[:isbn] = Library.canonicalise_ean(isbns.first)
165
+ end
166
+
167
+ # book = Book.new(title, ISBN.get(isbns.first))
168
+
169
+ unless info_headers.empty?
170
+ info_headers.each do |th|
171
+ header_text = th.inner_text
172
+ if header_text =~ /Type/
173
+ book_data[:binding] = data_for_header(th)
174
+ elsif header_text =~ /Verschijningsdatum/
175
+ date = data_for_header(th)
176
+ date =~ /\/([\d]{4})/
177
+ book_data[:publish_year] = Regexp.last_match[1].to_i
178
+ elsif header_text =~ /Auteur/
179
+ book_data[:authors] << data_for_header(th)
180
+ elsif header_text =~ /Uitgever/
181
+ book_data[:publisher] = data_for_header(th)
182
+ end
183
+ end
184
+ end
185
+
186
+ image_url = nil
187
+ if (cover_img = doc.at("img[@id$='imgProduct']"))
188
+ if cover_img['src'] =~ /^http/
189
+ image_url = cover_img['src']
190
+ else
191
+ image_url = "#{SITE}/#{cover_img['src']}" # TODO use html <base>
192
+ end
193
+ if image_url =~ /ProductNoCover/
194
+ image_url = nil
195
+ end
196
+ end
197
+
198
+ book = Book.new(book_data[:title], book_data[:authors],
199
+ book_data[:isbn], book_data[:publisher],
200
+ book_data[:publish_year], book_data[:binding])
201
+ [book, image_url]
202
+ end
203
+ end
204
+ end
205
+ end