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,235 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2009 Cathal Mc Ginley
4
+ # Copyright (C) 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
+ # AdLibris Bokhandel AB http://www.adlibris.com/se/
22
+ # Swedish online book store
23
+
24
+ # New AdLibris provider, taken from the Palatina MetaDataSource and
25
+ # modified to fit the structure of Alexandria book providers.
26
+ # (26 Feb 2009)
27
+
28
+ require 'cgi'
29
+ require 'alexandria/book_providers/web'
30
+
31
+ module Alexandria
32
+ class BookProviders
33
+ class AdLibrisProvider < WebsiteBasedProvider
34
+ include Alexandria::Logging
35
+
36
+ SITE = 'http://www.adlibris.com/se/'
37
+
38
+ BASE_SEARCH_URL = "#{SITE}searchresult.aspx?search=advanced&%s=%s" \
39
+ '&fromproduct=False' # type/term
40
+
41
+ PRODUCT_URL = "#{SITE}product.aspx?isbn=%s"
42
+
43
+ def initialize
44
+ super('AdLibris', 'AdLibris (Sweden)')
45
+ prefs.read
46
+ # @ent = HTMLEntities.new
47
+ end
48
+
49
+ ## search (copied from new WorldCat search)
50
+ def search(criterion, type)
51
+ req = create_search_uri(type, criterion)
52
+ log.info { "Fetching #{req} " }
53
+ html_data = transport.get_response(URI.parse(req))
54
+
55
+ if type == SEARCH_BY_ISBN
56
+ parse_result_data(html_data.body)
57
+ else
58
+ results = parse_search_result_data(html_data.body)
59
+ raise NoResultsError if results.empty?
60
+
61
+ results.map { |result| get_book_from_search_result(result) }
62
+ end
63
+ end
64
+
65
+ ## url
66
+ def url(book)
67
+ create_search_uri(SEARCH_BY_ISBN, book.isbn)
68
+ rescue => ex
69
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
70
+ nil
71
+ end
72
+
73
+ private
74
+
75
+ def create_search_uri(search_type, search_term)
76
+ if search_type == SEARCH_BY_ISBN
77
+ PRODUCT_URL % Library.canonicalise_isbn(search_term)
78
+ else
79
+ search_type_code = {
80
+ SEARCH_BY_AUTHORS => 'author',
81
+ SEARCH_BY_TITLE => 'title',
82
+ SEARCH_BY_KEYWORD => 'keyword'
83
+ }[search_type] or 'keyword'
84
+ search_term_encoded = CGI.escape(search_term)
85
+ BASE_SEARCH_URL % [search_type_code, search_term_encoded]
86
+ end
87
+ end
88
+
89
+ # TODO use Iconv to pre-convert the html.body to UTF-8 everywhere
90
+ # before sending it to the parser methods
91
+
92
+ def get_book_from_search_result(rslt)
93
+ html_data = transport.get_response(URI.parse(rslt[:lookup_url]))
94
+ parse_result_data(html_data.body)
95
+ end
96
+
97
+ def parse_search_result_data(html)
98
+ # adlibris site presents data in ISO-8859-1, so change it to UTF-8
99
+ # html = Iconv.conv("UTF-8", "ISO-8859-1", html)
100
+ # doc = Hpricot(html)
101
+ doc = html_to_doc(html)
102
+ book_search_results = []
103
+
104
+ search_hit = doc.search("div'searchResult")[0]
105
+ return [] unless search_hit
106
+
107
+ (search_hit / 'ul.ulSearch table').each do |t|
108
+
109
+ result = {}
110
+ if (title_data = (t % 'div.divTitle'))
111
+ result[:title] = (title_data % :a).inner_text
112
+ lookup_url = (title_data % :a)['href']
113
+ end
114
+ result[:lookup_url] = "#{SITE}#{lookup_url}"
115
+
116
+ book_search_results << result
117
+
118
+ end
119
+ book_search_results
120
+ end
121
+
122
+ # def binding_type(binding) # swedish string
123
+ # # hrm, this is a HACK and not currently working
124
+ # # perhaps use regexes instead...
125
+ # {"inbunden" => :hardback,
126
+ # "pocket" => :paperback,
127
+ # "storpocket" => :paperback,
128
+ # "kartonnage" => :hardback,
129
+ # "kassettbok" => :audiobook}[binding.downcase] or :paperback
130
+ # # H&#228;ftad == Paperback
131
+ # end
132
+
133
+ def normalize(text)
134
+ # unless text.nil?
135
+ # text = @ent.decode(text).strip
136
+ # end
137
+ text
138
+ end
139
+
140
+ def parse_result_data(html)
141
+ # adlibris site presents data in ISO-8859-1, so change it to UTF-8
142
+ # html = Iconv.conv("UTF-8", "ISO-8859-1", html)
143
+ ## File.open(',log.html', 'wb') {|f| f.write('<?xml encoding="utf-8"?>'); f.write(html) } # DEBUG
144
+ # doc = Hpricot(html)
145
+ doc = html_to_doc(html)
146
+ begin
147
+
148
+ title = nil
149
+ if (h1 = doc.at('div.productTitleFormat h1'))
150
+ title = text_of(h1)
151
+ else
152
+ raise NoResultsError, 'title not found on page'
153
+ end
154
+
155
+ product = doc.at('div.product')
156
+ ul_info = doc.at('ul.info') # NOTE, two of these
157
+
158
+ author_cells = ul_info.search('li.liAuthor') # css-like search
159
+ authors = []
160
+ author_cells.each do |li|
161
+ author_name = text_of(li.search('h2 > a')[0])
162
+
163
+ authors << author_name
164
+ end
165
+
166
+ publisher = nil
167
+ if (publisher_elem = product.search('li[@id$="liPublisher"] a').first)
168
+ publisher = text_of(publisher_elem)
169
+ end
170
+
171
+ binding = nil
172
+ if (format = doc.search('div.productTitleFormat span').first)
173
+ binding = text_of(format)
174
+ if binding =~ /\(([^\)]+)\)/
175
+ binding = Regexp.last_match[1]
176
+ end
177
+ end
178
+
179
+ year = nil
180
+ if (published = product.search('span[@id$="Published"]').first)
181
+ publication = published.inner_text
182
+ if publication =~ /([12][0-9]{3})/
183
+ year = Regexp.last_match[1].to_i
184
+ end
185
+ end
186
+
187
+ isbns = []
188
+ isbn_tds = doc.search("li[@id *= 'liISBN'] td[text()]")
189
+
190
+ isbn_tds.each do |isbn_td|
191
+ isbn = isbn_td.inner_text
192
+ unless isbn =~ /[0-9x]{10,13}/i
193
+ next
194
+ end
195
+ isbn.gsub(/(\n|\r)/, ' ')
196
+ if isbn =~ /:[\s]*([0-9x]+)/i
197
+ isbn = Regexp.last_match[1]
198
+ end
199
+ isbns << isbn
200
+ end
201
+ isbn = isbns.first
202
+ if isbn
203
+ isbn = Library.canonicalise_isbn(isbn)
204
+ end
205
+
206
+ # cover
207
+ image_url = nil
208
+ if (cover_img = doc.search('span.imageWithShadow img[@id$="ProductImageNotLinked"]').first)
209
+ if cover_img['src'] =~ /^http\:\/\//
210
+ image_url = cover_img['src']
211
+ else
212
+ image_url = "#{SITE}/#{cover_img['src']}" # HACK use html base
213
+ end
214
+ if image_url =~ /noimage.gif$/
215
+ # no point downloading a "no image" graphic
216
+ # Alexandria has its own generic book icon...
217
+ image_url = nil
218
+ end
219
+
220
+ end
221
+
222
+ book = Book.new(title, authors, isbn, publisher, year, binding)
223
+
224
+ return [book, image_url]
225
+ rescue => ex
226
+ raise ex if ex.instance_of? NoResultsError
227
+ trace = ex.backtrace.join("\n> ")
228
+ log.warn {'Failed parsing search results for AdLibris ' \
229
+ "#{ex.message} #{trace}" }
230
+ raise NoResultsError
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,261 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2008 Cathal Mc Ginley
3
+ # Copyright (C) 2014 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
+ # http://en.wikipedia.org/wiki/Amazon
21
+
22
+ require 'hpricot'
23
+ require 'alexandria/book_providers/amazon_ecs_util'
24
+
25
+ module Alexandria
26
+ class BookProviders
27
+ class AmazonProvider < GenericProvider
28
+ include Logging
29
+ include GetText
30
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
31
+
32
+ # CACHE_DIR = File.join(Alexandria::Library::DIR, '.amazon_cache')
33
+
34
+ LOCALES = ['ca', 'de', 'fr', 'jp', 'uk', 'us']
35
+
36
+ def initialize
37
+ super('Amazon', 'Amazon')
38
+ # prefs.add("enabled", _("Enabled"), true, [true,false])
39
+ prefs.add('locale', _('Locale'), 'us', AmazonProvider::LOCALES)
40
+ prefs.add('dev_token', _('Access key ID'), '')
41
+ prefs.add('secret_key', _('Secret access key'), '')
42
+ prefs.add('associate_tag', _('Associate Tag'), '')
43
+
44
+ prefs.read
45
+ token = prefs.variable_named('dev_token')
46
+ # kill old (shorter) tokens, or previously distributed Access Key Id (see #26250)
47
+
48
+ if token
49
+ if (token.value != token.value.strip)
50
+ token.new_value = token.value.strip
51
+ end
52
+ end
53
+ if token and (token.value.size != 20 or token.value == '0J356Z09CN88KB743582')
54
+ token.new_value = ''
55
+ end
56
+
57
+ secret = prefs.variable_named('secret_key')
58
+ if secret
59
+ if (secret.value != secret.value.strip)
60
+ secret.new_value = secret.value.strip
61
+ end
62
+ end
63
+
64
+ associate = prefs.variable_named('associate_tag')
65
+ if associate
66
+ if associate.value.strip.empty?
67
+ associate.new_value = 'rubyalexa-20'
68
+ end
69
+ if (associate.value != associate.value.strip)
70
+ associate.new_value = associate.value.strip
71
+ end
72
+ end
73
+ end
74
+
75
+ def search(criterion, type)
76
+ prefs.read
77
+
78
+ if prefs['secret_key'].empty?
79
+ raise Amazon::RequestError.new('Secret Access Key required for Authentication: you must sign up for your own Amazon AWS account')
80
+ end
81
+
82
+ if (config = Alexandria::Preferences.instance.http_proxy_config)
83
+ host, port, user, pass = config
84
+ url = 'http://'
85
+ url += user + ':' + pass + '@' if user and pass
86
+ url += host + ':' + port.to_s
87
+ ENV['http_proxy'] = url
88
+ end
89
+
90
+ access_key_id = prefs['dev_token']
91
+
92
+ Amazon::Ecs.options = { aWS_access_key_id: access_key_id,
93
+ associateTag: prefs['associate_tag'] }
94
+ Amazon::Ecs.secret_access_key = prefs['secret_key']
95
+ # #req.cache = Amazon::Search::Cache.new(CACHE_DIR)
96
+ locales = AmazonProvider::LOCALES.dup
97
+ locales.delete prefs['locale']
98
+ locales.unshift prefs['locale']
99
+ locales.reverse!
100
+
101
+ begin
102
+ request_locale = locales.pop.intern
103
+ products = []
104
+ case type
105
+ when SEARCH_BY_ISBN
106
+ criterion = Library.canonicalise_isbn(criterion)
107
+ # This isn't ideal : I'd like to do an ISBN/EAN-specific search
108
+ res = Amazon::Ecs.item_search(criterion, response_group: 'ItemAttributes,Images', country: request_locale)
109
+ res.items.each do |item|
110
+ products << item
111
+ end
112
+ # #req.asin_search(criterion) do |product|
113
+
114
+ # Shouldn't happen.
115
+ # raise TooManyResultsError if products.length > 1
116
+
117
+ # I had assumed that publishers were bogusly publishing
118
+ # multiple editions of a book with the same ISBN, and
119
+ # Amazon was distinguishing between them. So we'll log
120
+ # this case, and arbitrarily return the FIRST item
121
+
122
+ # Actually, this may be due to Amazon recommending a
123
+ # preferred later edition of a book, in spite of our
124
+ # searching on a single ISBN it can return more than one
125
+ # result with different ISBNs
126
+
127
+ if products.length > 1
128
+ log.warn { "ISBN search at Amazon[#{request_locale}] got #{products.length} results; returning the first result only" }
129
+ end
130
+
131
+ when SEARCH_BY_TITLE
132
+ res = Amazon::Ecs.item_search(criterion, response_group: 'ItemAttributes,Images', country: request_locale)
133
+
134
+ res.items.each do |item|
135
+ if /#{criterion}/i.match(item.get('itemattributes/title'))
136
+ products << item
137
+ end
138
+ end
139
+ # #req.keyword_search(criterion) do |product|
140
+
141
+ when SEARCH_BY_AUTHORS
142
+ criterion = "author:#{criterion}"
143
+ res = Amazon::Ecs.item_search(criterion, response_group: 'ItemAttributes,Images', country: request_locale, type: 'Power')
144
+ res.items.each do |item|
145
+ products << item
146
+ end
147
+ # #req.author_search(criterion) do |product|
148
+
149
+ when SEARCH_BY_KEYWORD
150
+ res = Amazon::Ecs.item_search(criterion, response_group: 'ItemAttributes,Images', country: request_locale)
151
+
152
+ res.items.each do |item|
153
+ products << item
154
+ end
155
+
156
+ else
157
+ raise InvalidSearchTypeError
158
+ end
159
+ if products.empty?
160
+ raise Amazon::RequestError, 'No products'
161
+ end
162
+ # raise NoResultsError if products.empty?
163
+ rescue Amazon::RequestError => re
164
+ log.debug { "Got Amazon::RequestError at #{request_locale}: #{re}" }
165
+ retry unless locales.empty?
166
+ raise NoResultsError
167
+ end
168
+
169
+ results = []
170
+ products.each do |item|
171
+ next unless item.get('itemattributes/productgroup') == 'Book'
172
+ atts = item.search_and_convert('itemattributes')
173
+ title = normalize(atts.get('title'))
174
+
175
+ # Work around Amazon US encoding bug. Amazon US apparently
176
+ # interprets UTF-8 titles as ISO-8859 titles and then converts
177
+ # the garbled titles to UTF-8. This tries to convert back into
178
+ # valid UTF-8. It does not always work - see isbn 2259196098
179
+ # (from the mailing list) for an example.
180
+ # if req.locale == 'us'
181
+ # title = title.convert('ISO-8859-1','UTF-8')
182
+ # end
183
+ # Cathal Mc Ginley 2008-02-18, still a problem for that ISBN!! Yep 2009-12-09!
184
+
185
+ media = normalize(atts.get('binding'))
186
+ media = nil if media == 'Unknown Binding'
187
+
188
+ isbn = normalize(atts.get('isbn'))
189
+ if isbn and Library.valid_isbn?(isbn)
190
+ isbn = Library.canonicalise_ean(isbn)
191
+ else
192
+ isbn = nil # it may be an ASIN which is not an ISBN
193
+ end
194
+ # hack, extract year by regexp (not Y10K compatible :-)
195
+ /([1-9][0-9]{3})/ =~ atts.get('publicationdate')
196
+ publishing_year = Regexp.last_match[1] ? Regexp.last_match[1].to_i : nil
197
+ book = Book.new(title,
198
+ atts.get_array('author').map { |x| normalize(x) },
199
+ isbn,
200
+ normalize(atts.get('manufacturer')),
201
+ publishing_year,
202
+ media)
203
+
204
+ image_url = item.get('mediumimage/url')
205
+ log.info { "Found at Amazon[#{request_locale}]: #{book.title}" }
206
+ results << [book, image_url]
207
+ end
208
+ if type == SEARCH_BY_ISBN
209
+ if results.size == 1
210
+ return results.first
211
+ else
212
+ log.info { 'Found multiple results for lookup: checking each' }
213
+ query_isbn_canon = Library.canonicalise_ean(criterion)
214
+ results.each do |rslt|
215
+ book = rslt[0]
216
+ book_isbn_canon = Library.canonicalise_ean(book.isbn)
217
+ if query_isbn_canon == book_isbn_canon
218
+ return rslt
219
+ end
220
+ log.debug { "rejected possible result #{book}" }
221
+ end
222
+ # gone through all and no ISBN match, so just return first result
223
+ log.info { 'no more results to check. Returning first result, just an approximation' }
224
+ return results.first
225
+ end
226
+ else
227
+ return results
228
+ end
229
+ end
230
+
231
+ def url(book)
232
+ isbn = Library.canonicalise_isbn(book.isbn)
233
+ url = case prefs['locale']
234
+ when 'fr'
235
+ 'http://www.amazon.fr/exec/obidos/ASIN/%s'
236
+ when 'uk'
237
+ 'http://www.amazon.co.uk/exec/obidos/ASIN/%s'
238
+ when 'de'
239
+ 'http://www.amazon.de/exec/obidos/ASIN/%s'
240
+ when 'ca'
241
+ 'http://www.amazon.ca/exec/obidos/ASIN/%s'
242
+ when 'jp'
243
+ 'http://www.amazon.jp/exec/obidos/ASIN/%s'
244
+ when 'us'
245
+ 'http://www.amazon.com/exec/obidos/ASIN/%s'
246
+ end
247
+ url % isbn
248
+ rescue => ex
249
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
250
+ nil
251
+ end
252
+
253
+ def normalize(str)
254
+ unless str.nil?
255
+ str = str.squeeze(' ').strip
256
+ end
257
+ str
258
+ end
259
+ end
260
+ end
261
+ end