alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -*- ruby -*-
2
4
  #
3
5
  # Copyright (C) 2009 Cathal Mc Ginley
@@ -26,35 +28,36 @@
26
28
 
27
29
  # NOTE: this modified version is based on the Alexandria WorldCat provider.
28
30
 
29
- require 'cgi'
30
- require 'alexandria/net'
31
- require 'alexandria/book_providers/web'
31
+ require "cgi"
32
+ require "alexandria/net"
33
+ require "alexandria/book_providers/web"
32
34
 
33
35
  module Alexandria
34
36
  class BookProviders
35
37
  class BarnesAndNobleProvider < WebsiteBasedProvider
36
- include Alexandria::Logging
38
+ include Logging
37
39
 
38
- SITE = 'http://www.barnesandnoble.com'.freeze
40
+ SITE = "http://www.barnesandnoble.com"
39
41
 
40
- BASE_ISBN_SEARCH_URL = 'http://www.barnesandnoble.com/s/%s'.freeze
42
+ BASE_ISBN_SEARCH_URL = "http://www.barnesandnoble.com/s/%s"
41
43
 
42
- BASE_SEARCH_URL = 'http://search.barnesandnoble.com/booksearch' \
43
- '/results.asp?%s=%s'.freeze # type, term
44
+ BASE_SEARCH_URL = "http://search.barnesandnoble.com/booksearch" \
45
+ "/results.asp?%s=%s" # type, term
44
46
 
45
47
  def initialize
46
- super('BarnesAndNoble', 'BarnesAndNoble')
48
+ super("BarnesAndNoble", "BarnesAndNoble")
47
49
  @agent = nil
48
50
  prefs.read
49
51
  end
50
52
 
51
53
  def agent
52
- @agent = Alexandria::WWWAgent.new unless @agent
54
+ @agent ||= Alexandria::WWWAgent.new
53
55
  @agent
54
56
  end
55
57
 
56
58
  def fetch_redirectly(uri_str, limit = 5)
57
- raise NoResultsError, 'HTTP redirect too deep' if limit.zero?
59
+ raise NoResultsError, _("HTTP redirect too deep") if limit.zero?
60
+
58
61
  if limit < 10
59
62
  sleep 0.1
60
63
  log.debug { "Redirectly :: #{uri_str}" }
@@ -64,12 +67,10 @@ module Alexandria
64
67
  response = agent.get(uri_str)
65
68
  log.debug { response.inspect }
66
69
  case response
67
- when Net::HTTPSuccess then response
68
- when Net::HTTPRedirection then
69
- redirect = URI.parse response['Location']
70
- if redirect.relative?
71
- redirect = URI.parse(uri_str) + redirect
72
- end
70
+ when Net::HTTPSuccess then response
71
+ when Net::HTTPRedirection
72
+ redirect = URI.parse response["Location"]
73
+ redirect = URI.parse(uri_str) + redirect if redirect.relative?
73
74
  fetch_redirectly(redirect.to_s, (limit - 1))
74
75
  else
75
76
  response.error!
@@ -78,7 +79,7 @@ module Alexandria
78
79
 
79
80
  def search(criterion, type)
80
81
  req = create_search_uri(type, criterion)
81
- puts "Requesting #{req}" if $DEBUG
82
+ log.debug { "Requesting #{req}" }
82
83
  html_data = fetch_redirectly(req)
83
84
 
84
85
  if type == SEARCH_BY_ISBN
@@ -93,22 +94,22 @@ module Alexandria
93
94
 
94
95
  def url(book)
95
96
  create_search_uri(SEARCH_BY_ISBN, book.isbn)
96
- rescue => ex
97
+ rescue StandardError => ex
97
98
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
98
99
  nil
99
100
  end
100
101
 
101
102
  def create_search_uri(search_type, search_term)
102
103
  (search_type_code = {
103
- SEARCH_BY_AUTHORS => 'ATH',
104
- SEARCH_BY_TITLE => 'TTL',
105
- SEARCH_BY_KEYWORD => 'WRD' # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
106
- }[search_type]) || ''
104
+ SEARCH_BY_AUTHORS => "ATH",
105
+ SEARCH_BY_TITLE => "TTL",
106
+ SEARCH_BY_KEYWORD => "WRD" # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
107
+ }[search_type]) || ""
107
108
  if search_type == SEARCH_BY_ISBN
108
109
  BASE_ISBN_SEARCH_URL % Library.canonicalise_ean(search_term) # isbn-13
109
110
  else
110
111
  search_term_encoded = CGI.escape(search_term)
111
- BASE_SEARCH_URL % [search_type_code, search_term_encoded]
112
+ format(BASE_SEARCH_URL, search_type_code, search_term_encoded)
112
113
  end
113
114
  end
114
115
 
@@ -127,19 +128,19 @@ module Alexandria
127
128
  result = {}
128
129
  # img = div % 'div.book-image/a/img'
129
130
  # result[:image_url] = img['src'] if img
130
- title_header = div % 'h2'
131
- title_links = title_header / 'a'
131
+ title_header = div % "h2"
132
+ title_links = title_header / "a"
132
133
  result[:title] = title_links.first.inner_text
133
- result[:url] = title_links.first['href']
134
+ result[:url] = title_links.first["href"]
134
135
 
135
136
  book_search_results << result
136
137
  end
137
- rescue => ex
138
+ rescue StandardError => ex
138
139
  trace = ex.backtrace.join("\n> ")
139
- log.warn {
140
- 'Failed parsing search results for Barnes & Noble ' \
140
+ log.warn do
141
+ "Failed parsing search results for Barnes & Noble " \
141
142
  "#{ex.message} #{trace}"
142
- }
143
+ end
143
144
  end
144
145
  book_search_results
145
146
  end
@@ -149,8 +150,8 @@ module Alexandria
149
150
  begin
150
151
  book_data = {}
151
152
 
152
- dl = (doc / 'dl').first
153
- dts = dl.children_of_type('dt')
153
+ dl = (doc / "dl").first
154
+ dts = dl.children_of_type("dt")
154
155
  dts.each do |dt|
155
156
  value = dt.next_sibling.inner_text
156
157
  case dt.inner_text
@@ -165,44 +166,44 @@ module Alexandria
165
166
  end
166
167
  end
167
168
 
168
- meta = doc / 'meta'
169
+ meta = doc / "meta"
169
170
  meta.each do |it|
170
171
  attrs = it.attributes
171
- property = attrs['property']
172
+ property = attrs["property"]
172
173
  next unless property
174
+
173
175
  case property
174
- when 'og:title'
175
- book_data[:title] = attrs['content']
176
- when 'og:image'
177
- book_data[:image_url] = attrs['content']
176
+ when "og:title"
177
+ book_data[:title] = attrs["content"]
178
+ when "og:image"
179
+ book_data[:image_url] = attrs["content"]
178
180
  end
179
181
  end
180
182
 
181
- author_links = doc / 'span.contributors a'
183
+ author_links = doc / "span.contributors a"
182
184
  authors = author_links.map(&:inner_text)
183
185
  book_data[:authors] = authors
184
186
 
185
- book_data[:binding] = ''
186
- selected_format = (doc / '#availableFormats li.selected a.tabTitle').first
187
- if selected_format
188
- book_data[:binding] = selected_format.inner_text
189
- end
187
+ book_data[:binding] = ""
188
+ selected_format = (doc / "#availableFormats li.selected a.tabTitle").first
189
+ book_data[:binding] = selected_format.inner_text if selected_format
190
190
 
191
191
  book = Book.new(book_data[:title], book_data[:authors],
192
192
  book_data[:isbn], book_data[:publisher],
193
193
  book_data[:publication_year],
194
194
  book_data[:binding])
195
- return [book, book_data[:image_url]]
196
- rescue => ex
195
+ [book, book_data[:image_url]]
196
+ rescue StandardError => ex
197
197
  raise ex if ex.instance_of? NoResultsError
198
+
198
199
  trace = ex.backtrace.join("\n> ")
199
- log.warn {
200
- 'Failed parsing search results for BarnesAndNoble ' \
200
+ log.warn do
201
+ "Failed parsing search results for BarnesAndNoble " \
201
202
  "#{ex.message} #{trace}"
202
- }
203
+ end
203
204
  raise NoResultsError
204
205
  end
205
206
  end
206
- end # class BarnesAndNobleProvider
207
- end # class BookProviders
208
- end # module Alexandria
207
+ end
208
+ end
209
+ end
@@ -1,42 +1,28 @@
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.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
15
4
  #
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.
5
+ # See the file README.md for authorship and licensing information.
20
6
 
21
7
  # http://book.douban.com/
22
8
  # Douban.com book repository, provides many Chinese books.
23
9
 
24
10
  # Author: Sun Ning <classicning@gmail.com>, http://sunng.info/
25
11
 
26
- require 'cgi'
27
- require 'alexandria/net'
28
- require 'yaml'
12
+ require "cgi"
13
+ require "alexandria/net"
14
+ require "yaml"
29
15
 
30
16
  module Alexandria
31
17
  class BookProviders
32
18
  class DoubanProvider < GenericProvider
33
- include Alexandria::Logging
19
+ include Logging
34
20
 
35
- SITE = 'http://www.douban.com'.freeze
36
- BASE_URL = 'http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json'.freeze
21
+ SITE = "http://www.douban.com"
22
+ BASE_URL = "http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json"
37
23
 
38
24
  def initialize
39
- super('Douban', 'Douban (China)')
25
+ super("Douban", "Douban (China)")
40
26
  prefs.read
41
27
  end
42
28
 
@@ -54,9 +40,9 @@ module Alexandria
54
40
  raise NoResultsError if results.empty?
55
41
 
56
42
  if type == SEARCH_BY_ISBN
57
- return results.first
43
+ results.first
58
44
  else
59
- return results
45
+ results
60
46
  end
61
47
  end
62
48
 
@@ -72,10 +58,10 @@ module Alexandria
72
58
  def json2yaml(json)
73
59
  # insert spaces after : and , except within strings
74
60
  # i.e. when followed by numeral, quote, { or [
75
- yaml = json.gsub(/(\:|\,)([0-9'"{\[])/) do |_match|
61
+ yaml = json.gsub(/(:|,)([0-9'"{\[])/) do |_match|
76
62
  "#{Regexp.last_match[1]} #{Regexp.last_match[2]}"
77
63
  end
78
- yaml.gsub!(/\\\//, '/') # unescape forward slashes
64
+ yaml.gsub!(%r{\\/}, "/") # unescape forward slashes
79
65
  yaml
80
66
  end
81
67
 
@@ -85,43 +71,35 @@ module Alexandria
85
71
  book_search_results = []
86
72
  begin
87
73
  # dbresult = JSON.parse(response)
88
- dbresult = YAML.load(json2yaml(response))
74
+ dbresult = YAML.safe_load(json2yaml(response))
89
75
  # File.open(",douban.yaml", "wb") {|f| f.write(json2yaml(response)) }
90
- if dbresult['opensearch:totalResults']['$t'].to_i > 0
91
- for item in dbresult['entry']
92
- name = item['title']['$t']
76
+ if dbresult["opensearch:totalResults"]["$t"].to_i > 0
77
+ dbresult["entry"].each do |item|
78
+ name = item["title"]["$t"]
93
79
  isbn = nil
94
80
  publisher = nil
95
81
  pubdate = nil
96
82
  binding = nil
97
- for av in item['db:attribute']
98
- isbn = av['$t'] if av['@name'] == 'isbn13'
99
- if av['@name'] == 'publisher'
100
- publisher = av['$t']
101
- end
102
- if av['@name'] == 'pubdate'
103
- pubdate = av['$t']
104
- end
105
- if av['@name'] == 'binding'
106
- binding = av['$t']
107
- end
83
+ item["db:attribute"].each do |av|
84
+ isbn = av["$t"] if av["@name"] == "isbn13"
85
+ publisher = av["$t"] if av["@name"] == "publisher"
86
+ pubdate = av["$t"] if av["@name"] == "pubdate"
87
+ binding = av["$t"] if av["@name"] == "binding"
108
88
  end
109
- authors = if item['author']
110
- item['author'].map { |a| a['name']['$t'] }
89
+ authors = if item["author"]
90
+ item["author"].map { |a| a["name"]["$t"] }
111
91
  else
112
92
  []
113
93
  end
114
94
  image_url = nil
115
- for av in item['link']
116
- if av['@rel'] == 'image'
117
- image_url = av['@href']
118
- end
95
+ item["link"].each do |av|
96
+ image_url = av["@href"] if av["@rel"] == "image"
119
97
  end
120
98
  book = Book.new(name, authors, isbn, publisher, pubdate, binding)
121
99
  book_search_results << [book, image_url]
122
100
  end
123
101
  end
124
- rescue => ex
102
+ rescue StandardError => ex
125
103
  log.warn(ex.backtrace.join('\n'))
126
104
  end
127
105
  book_search_results
@@ -1,32 +1,20 @@
1
- # Copyright (C) 2009 Cathal Mc Ginley
2
- # Copyright (C) 2014-2016 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.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
13
4
  #
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.
5
+ # See the file README.md for authorship and licensing information.
18
6
 
19
7
  # New Proxis provider, taken from Palatina MetaDataSource and modified
20
8
  # for Alexandria. (20 Dec 2009)
21
9
 
22
- require 'cgi'
23
- require 'alexandria/book_providers/web'
10
+ require "cgi"
11
+ require "alexandria/book_providers/web"
24
12
 
25
13
  module Alexandria
26
14
  class BookProviders
27
15
  class ProxisProvider < WebsiteBasedProvider
28
16
  # include GetText
29
- include Alexandria::Logging
17
+ include Logging
30
18
  # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
31
19
 
32
20
  # Proxis essentially has three book databases, NL, FR and EN.
@@ -34,14 +22,14 @@ module Alexandria
34
22
  # it adds most to Alexandria (Amazon already has French and
35
23
  # English titles).
36
24
 
37
- SITE = 'http://www.proxis.nl'.freeze
25
+ SITE = "http://www.proxis.nl"
38
26
  BASE_SEARCH_URL = "#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
39
- '&shop=100001NL&SelRubricLevel1Id=100001NL'.freeze
27
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
40
28
  ISBN_REDIRECT_BASE_URL = "#{SITE}/NLNL/Search/Index.aspx?search=%s" \
41
- '&shop=100001NL&SelRubricLevel1Id=100001NL'.freeze
29
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
42
30
 
43
31
  def initialize
44
- super('Proxis', 'Proxis (Belgium)')
32
+ super("Proxis", "Proxis (Belgium)")
45
33
  # prefs.add("lang", _("Language"), "fr",
46
34
  # LANGUAGES.keys)
47
35
  prefs.read
@@ -49,11 +37,12 @@ module Alexandria
49
37
 
50
38
  def search(criterion, type)
51
39
  req = create_search_uri(type, criterion)
52
- puts req if $DEBUG
40
+ log.debug { req }
53
41
  html_data = transport.get_response(URI.parse(req))
54
42
 
55
43
  results = parse_search_result_data(html_data.body)
56
44
  raise NoResultsError if results.empty?
45
+
57
46
  if type == SEARCH_BY_ISBN
58
47
  get_book_from_search_result(results.first)
59
48
  else
@@ -85,32 +74,29 @@ module Alexandria
85
74
  def text_of(node)
86
75
  if node.nil?
87
76
  nil
88
- else
89
- if node.text?
90
- node.to_html
91
- elsif node.elem?
92
- if node.children.nil?
93
- nil
94
- else
95
- node_text = node.children.map { |n| text_of(n) }.join
96
- node_text.strip.squeeze(' ')
97
- end
77
+ elsif node.text?
78
+ node.to_html
79
+ elsif node.elem?
80
+ if node.children.nil?
81
+ nil
82
+ else
83
+ node_text = node.children.map { |n| text_of(n) }.join
84
+ node_text.strip.squeeze(" ")
98
85
  end
99
- # node.inner_html.strip
100
86
  end
101
87
  end
102
88
 
103
89
  def parse_search_result_data(html)
104
90
  doc = html_to_doc(html)
105
91
  book_search_results = []
106
- items = doc.search('table.searchResult tr')
92
+ items = doc.search("table.searchResult tr")
107
93
  items.each do |item|
108
94
  result = {}
109
- title_link = item % 'h5 a'
95
+ title_link = item % "h5 a"
110
96
  if title_link
111
97
  result[:title] = text_of(title_link)
112
- result[:lookup_url] = title_link['href']
113
- unless result[:lookup_url] =~ /^http/
98
+ result[:lookup_url] = title_link["href"]
99
+ unless result[:lookup_url].start_with?("http")
114
100
  result[:lookup_url] = "#{SITE}#{result[:lookup_url]}"
115
101
  end
116
102
  end
@@ -122,9 +108,9 @@ module Alexandria
122
108
  book_search_results
123
109
  end
124
110
 
125
- def data_for_header(th)
126
- tr = th.parent
127
- td = tr.at('td')
111
+ def data_for_header(header)
112
+ tr = header.parent
113
+ td = tr.at("td")
128
114
  text_of(td) if td
129
115
  end
130
116
 
@@ -133,23 +119,19 @@ module Alexandria
133
119
  book_data = {}
134
120
  book_data[:authors] = []
135
121
  # TITLE
136
- if (title_header = doc.search('div.detailBlock h3'))
137
- header_spans = title_header.first.search('span')
122
+ if (title_header = doc.search("div.detailBlock h3"))
123
+ header_spans = title_header.first.search("span")
138
124
  title = text_of(header_spans.first)
139
- if title =~ /(.+)-$/
140
- title = Regexp.last_match[1].strip
141
- end
125
+ title = Regexp.last_match[1].strip if title =~ /(.+)-$/
142
126
  book_data[:title] = title
143
127
  end
144
128
 
145
- info_headers = doc.search('table.productInfoTable th')
129
+ info_headers = doc.search("table.productInfoTable th")
146
130
 
147
131
  isbns = []
148
132
  unless info_headers.empty?
149
133
  info_headers.each do |th|
150
- if th.inner_text =~ /(ISBN|EAN)/
151
- isbns << data_for_header(th)
152
- end
134
+ isbns << data_for_header(th) if /(ISBN|EAN)/.match?(th.inner_text)
153
135
  end
154
136
  book_data[:isbn] = Library.canonicalise_ean(isbns.first)
155
137
  end
@@ -159,15 +141,16 @@ module Alexandria
159
141
  unless info_headers.empty?
160
142
  info_headers.each do |th|
161
143
  header_text = th.inner_text
162
- if header_text =~ /Type/
144
+ case header_text
145
+ when /Type/
163
146
  book_data[:binding] = data_for_header(th)
164
- elsif header_text =~ /Verschijningsdatum/
147
+ when /Verschijningsdatum/
165
148
  date = data_for_header(th)
166
- date =~ /\/([\d]{4})/
149
+ date =~ %r{/(\d{4})}
167
150
  book_data[:publish_year] = Regexp.last_match[1].to_i
168
- elsif header_text =~ /Auteur/
151
+ when /Auteur/
169
152
  book_data[:authors] << data_for_header(th)
170
- elsif header_text =~ /Uitgever/
153
+ when /Uitgever/
171
154
  book_data[:publisher] = data_for_header(th)
172
155
  end
173
156
  end
@@ -175,12 +158,12 @@ module Alexandria
175
158
 
176
159
  image_url = nil
177
160
  if (cover_img = doc.at("img[@id$='imgProduct']"))
178
- image_url = if cover_img['src'] =~ /^http/
179
- cover_img['src']
161
+ image_url = if cover_img["src"].start_with?("http")
162
+ cover_img["src"]
180
163
  else
181
164
  "#{SITE}/#{cover_img['src']}" # TODO: use html <base>
182
165
  end
183
- image_url = nil if image_url =~ /ProductNoCover/
166
+ image_url = nil if /ProductNoCover/.match?(image_url)
184
167
  end
185
168
 
186
169
  book = Book.new(book_data[:title], book_data[:authors],