alexandria-book-collection-manager 0.7.3 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ruby.yml +77 -0
- data/.gitignore +4 -1
- data/.rubocop.yml +86 -36
- data/.rubocop_todo.yml +58 -161
- data/.simplecov +5 -2
- data/CHANGELOG.md +56 -2
- data/Gemfile +4 -3
- data/INSTALL.md +23 -11
- data/README.md +52 -41
- data/Rakefile +78 -75
- data/alexandria-book-collection-manager.gemspec +50 -44
- data/bin/alexandria +12 -22
- data/doc/FAQ +1 -2
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +25 -23
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +86 -91
- data/lib/alexandria/book_providers/adlibris.rb +37 -74
- data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
- data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
- data/lib/alexandria/book_providers/douban.rb +25 -41
- data/lib/alexandria/book_providers/proxis.rb +34 -29
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +60 -64
- data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
- data/lib/alexandria/book_providers/web.rb +5 -5
- data/lib/alexandria/book_providers/worldcat.rb +66 -95
- data/lib/alexandria/book_providers/z3950.rb +153 -169
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +3 -3
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +13 -12
- data/lib/alexandria/export_format.rb +8 -8
- data/lib/alexandria/export_library.rb +128 -127
- data/lib/alexandria/import_library.rb +102 -126
- data/lib/alexandria/import_library_csv.rb +41 -41
- data/lib/alexandria/library_collection.rb +6 -5
- data/lib/alexandria/library_sort_order.rb +4 -2
- data/lib/alexandria/library_store.rb +39 -28
- data/lib/alexandria/logging.rb +10 -14
- data/lib/alexandria/models/book.rb +5 -4
- data/lib/alexandria/models/library.rb +63 -53
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +66 -63
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +110 -112
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
- data/lib/alexandria/ui/alert_dialog.rb +66 -0
- data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -38
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
- data/lib/alexandria/ui/builder_base.rb +1 -1
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +187 -155
- data/lib/alexandria/ui/completion_models.rb +8 -22
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +7 -7
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
- data/lib/alexandria/ui/icons.rb +38 -43
- data/lib/alexandria/ui/iconview.rb +12 -10
- data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +30 -41
- data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
- data/lib/alexandria/ui/libraries_combo.rb +15 -14
- data/lib/alexandria/ui/listview.rb +69 -67
- data/lib/alexandria/ui/main_app.rb +24 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +8 -9
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
- data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +11 -13
- data/lib/alexandria/ui/ui_manager.rb +216 -200
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +21 -21
- data/po/Makefile +2 -2
- data/po/cs.po +992 -875
- data/po/cy.po +961 -874
- data/po/de.po +990 -865
- data/po/el.po +989 -865
- data/po/es.po +985 -861
- data/po/fr.po +987 -867
- data/po/ga.po +908 -820
- data/po/gl.po +980 -860
- data/po/it.po +986 -864
- data/po/ja.po +969 -849
- data/po/mk.po +984 -860
- data/po/nb.po +979 -859
- data/po/nl.po +983 -860
- data/po/pl.po +1018 -971
- data/po/pt.po +988 -857
- data/po/pt_BR.po +983 -863
- data/po/ru.po +994 -871
- data/po/sk.po +989 -867
- data/po/sv.po +976 -856
- data/po/uk.po +972 -858
- data/po/zh_TW.po +974 -854
- data/schemas/alexandria.schemas +24 -2
- data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
- data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
- data/share/alexandria/glade/main_app__builder.glade +6 -21
- data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
- data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
- data/share/gnome/help/alexandria/C/introduction.xml +0 -4
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +62 -156
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +6 -11
- data/spec/alexandria/export_library_spec.rb +47 -58
- data/spec/alexandria/library_spec.rb +121 -109
- data/spec/alexandria/library_store_spec.rb +8 -8
- data/spec/alexandria/preferences_spec.rb +44 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +15 -15
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +59 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +7 -34
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +51 -0
- data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +44 -20
- data/spec/end_to_end/basic_run_spec.rb +21 -38
- data/spec/fixtures/cover.jpg +0 -0
- data/spec/spec_helper.rb +54 -10
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +11 -11
- data/util/rake/fileinstall.rb +38 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +158 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/renaud.rb +0 -155
- data/lib/alexandria/book_providers/thalia.rb +0 -198
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -162
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
- data/tasks/dogtail.rake +0 -6
@@ -19,8 +19,8 @@
|
|
19
19
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
20
20
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
21
21
|
|
22
|
-
require
|
23
|
-
require
|
22
|
+
require "singleton"
|
23
|
+
require "observer"
|
24
24
|
|
25
25
|
module Alexandria
|
26
26
|
# FIXME: Use delegation instead of inheritance.
|
@@ -29,27 +29,28 @@ module Alexandria
|
|
29
29
|
include Singleton
|
30
30
|
include Observable
|
31
31
|
include GetText
|
32
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
32
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
33
33
|
|
34
34
|
SEARCH_BY_ISBN, SEARCH_BY_TITLE, SEARCH_BY_AUTHORS,
|
35
35
|
SEARCH_BY_KEYWORD = (0..3).to_a
|
36
36
|
|
37
37
|
class SearchError < StandardError; end
|
38
38
|
class NoResultsError < SearchError; end
|
39
|
-
class ProviderSkippedError < NoResultsError; end # not an error :^(
|
40
|
-
class SearchEmptyError < SearchError; end # sigh, again not really an error
|
41
39
|
class TooManyResultsError < SearchError; end
|
42
40
|
class InvalidSearchTypeError < SearchError; end
|
43
41
|
|
42
|
+
# These errors are not really errors
|
43
|
+
class ProviderSkippedError < NoResultsError; end
|
44
|
+
class SearchEmptyError < SearchError; end
|
45
|
+
|
44
46
|
def self.search(criterion, type)
|
45
47
|
factory_n = 0
|
46
|
-
# puts "book_providers search #{self.instance.count_observers}"
|
47
48
|
|
48
49
|
begin
|
49
50
|
factory = instance[factory_n]
|
50
|
-
|
51
|
+
log.debug { factory.fullname + " lookup" }
|
51
52
|
unless factory.enabled
|
52
|
-
|
53
|
+
log.debug { factory.fullname + " disabled!, skipping..." }
|
53
54
|
raise ProviderSkippedError
|
54
55
|
end
|
55
56
|
instance.changed
|
@@ -64,14 +65,14 @@ module Alexandria
|
|
64
65
|
instance.notify_observers(:not_found, factory.fullname) # new
|
65
66
|
raise NoResultsError
|
66
67
|
else
|
67
|
-
log.info {
|
68
|
+
log.info { "found at " + factory.fullname }
|
68
69
|
instance.changed
|
69
70
|
instance.notify_observers(:found, factory.fullname) # new
|
70
|
-
|
71
|
+
results
|
71
72
|
end
|
72
|
-
rescue StandardError =>
|
73
|
-
if
|
74
|
-
unless
|
73
|
+
rescue StandardError => ex
|
74
|
+
if ex.is_a? NoResultsError
|
75
|
+
unless ex.instance_of? ProviderSkippedError
|
75
76
|
instance.changed
|
76
77
|
instance.notify_observers(:not_found, factory.fullname) # new
|
77
78
|
Thread.new { sleep(0.5) }.join
|
@@ -80,41 +81,41 @@ module Alexandria
|
|
80
81
|
instance.changed
|
81
82
|
instance.notify_observers(:error, factory.fullname) # new
|
82
83
|
Thread.new { sleep(0.5) }.join # hrmmmm, to make readable...
|
83
|
-
trace =
|
84
|
-
log.warn { "Provider #{factory.name} encountered error: #{
|
84
|
+
trace = ex.backtrace.join("\n >")
|
85
|
+
log.warn { "Provider #{factory.name} encountered error: #{ex.message} #{trace}" }
|
85
86
|
end
|
86
|
-
if
|
87
|
+
if factory == instance.last
|
87
88
|
log.warn { "Error while searching #{criterion}" }
|
88
|
-
message = case
|
89
|
+
message = case ex
|
89
90
|
when Timeout::Error
|
90
91
|
_("Couldn't reach the provider '%s': timeout " \
|
91
|
-
|
92
|
+
"expired.") % factory.name
|
92
93
|
|
93
94
|
when SocketError
|
94
95
|
format(_("Couldn't reach the provider '%s': socket " \
|
95
|
-
|
96
|
+
"error (%s)."), factory.name, ex.message)
|
96
97
|
|
97
98
|
when NoResultsError
|
98
|
-
_(
|
99
|
-
|
100
|
-
|
99
|
+
_("No results were found. Make sure your " \
|
100
|
+
"search criterion is spelled correctly, and " \
|
101
|
+
"try again.")
|
101
102
|
|
102
103
|
when ProviderSkippedError
|
103
|
-
_(
|
104
|
-
|
105
|
-
|
104
|
+
_("No results were found. Make sure your " \
|
105
|
+
"search criterion is spelled correctly, and " \
|
106
|
+
"try again.")
|
106
107
|
|
107
108
|
when TooManyResultsError
|
108
|
-
_(
|
109
|
+
_("Too many results for that search.")
|
109
110
|
|
110
111
|
when InvalidSearchTypeError
|
111
|
-
_(
|
112
|
+
_("Invalid search type.")
|
112
113
|
|
113
114
|
else
|
114
|
-
|
115
|
+
ex.message
|
115
116
|
end
|
116
|
-
|
117
|
-
raise SearchEmptyError, message
|
117
|
+
log.debug { "raising empty error #{message}" }
|
118
|
+
raise SearchEmptyError, message # rubocop:disable GetText/DecorateFunctionMessage
|
118
119
|
else
|
119
120
|
factory_n += 1
|
120
121
|
retry
|
@@ -152,9 +153,8 @@ module Alexandria
|
|
152
153
|
end
|
153
154
|
|
154
155
|
def new_value=(new_value)
|
155
|
-
|
156
|
-
Alexandria::Preferences.instance.
|
157
|
-
new_value)
|
156
|
+
name = @provider.variable_name(self)
|
157
|
+
Alexandria::Preferences.instance.set_variable(name, new_value)
|
158
158
|
self.value = new_value
|
159
159
|
end
|
160
160
|
|
@@ -187,9 +187,9 @@ module Alexandria
|
|
187
187
|
|
188
188
|
def read
|
189
189
|
each do |var|
|
190
|
-
|
191
|
-
val = Alexandria::Preferences.instance.
|
192
|
-
var.value = val unless val.nil? || ((val ==
|
190
|
+
name = @provider.variable_name(var)
|
191
|
+
val = Alexandria::Preferences.instance.get_variable(name)
|
192
|
+
var.value = val unless val.nil? || ((val == "") && var.mandatory?)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
end
|
@@ -203,35 +203,35 @@ module Alexandria
|
|
203
203
|
@name = name
|
204
204
|
@fullname = (fullname || name)
|
205
205
|
@prefs = Preferences.new(self)
|
206
|
-
@prefs.add(
|
206
|
+
@prefs.add("enabled", _("Enabled"), true, [true, false])
|
207
207
|
end
|
208
208
|
|
209
209
|
def enabled
|
210
|
-
@prefs[
|
210
|
+
@prefs["enabled"]
|
211
211
|
end
|
212
212
|
|
213
213
|
def toggle_enabled
|
214
214
|
old_value = enabled
|
215
|
-
@prefs.variable_named(
|
215
|
+
@prefs.variable_named("enabled").new_value = !old_value
|
216
216
|
end
|
217
217
|
|
218
218
|
def reinitialize(fullname)
|
219
|
-
@name
|
219
|
+
@name = "#{name}_#{fullname.hash}"
|
220
220
|
@fullname = fullname
|
221
221
|
prefs = Alexandria::Preferences.instance
|
222
|
-
ary = prefs.abstract_providers
|
222
|
+
ary = prefs.get_variable :abstract_providers
|
223
223
|
ary ||= []
|
224
224
|
ary << @name
|
225
|
-
prefs.abstract_providers
|
226
|
-
message = variable_name(
|
227
|
-
prefs.
|
225
|
+
prefs.set_variable :abstract_providers, ary
|
226
|
+
message = variable_name("name")
|
227
|
+
prefs.set_variable(message, @fullname)
|
228
228
|
end
|
229
229
|
|
230
230
|
def remove
|
231
231
|
prefs = Alexandria::Preferences.instance
|
232
|
-
if (ary = prefs.abstract_providers)
|
232
|
+
if (ary = prefs.get_variable :abstract_providers)
|
233
233
|
ary.delete(@name)
|
234
|
-
prefs.abstract_providers
|
234
|
+
prefs.set_variable :abstract_providers, ary
|
235
235
|
end
|
236
236
|
if (ary = prefs.providers_priority) && ary.include?(@name)
|
237
237
|
ary.delete(@name)
|
@@ -241,7 +241,7 @@ module Alexandria
|
|
241
241
|
name = variable_name(variable)
|
242
242
|
prefs.remove_preference(name)
|
243
243
|
end
|
244
|
-
name = variable_name(
|
244
|
+
name = variable_name("name")
|
245
245
|
prefs.remove_preference(name)
|
246
246
|
prefs.save!
|
247
247
|
end
|
@@ -255,7 +255,7 @@ module Alexandria
|
|
255
255
|
else
|
256
256
|
raise
|
257
257
|
end
|
258
|
-
@name.downcase +
|
258
|
+
@name.downcase + "_" + s
|
259
259
|
end
|
260
260
|
|
261
261
|
def transport
|
@@ -271,8 +271,8 @@ module Alexandria
|
|
271
271
|
!included_modules.include?(Singleton)
|
272
272
|
end
|
273
273
|
|
274
|
-
def <=>(
|
275
|
-
fullname <=>
|
274
|
+
def <=>(other)
|
275
|
+
fullname <=> other.fullname
|
276
276
|
end
|
277
277
|
|
278
278
|
# FIXME: Clean up this complex abstract/concrete class system
|
@@ -289,24 +289,21 @@ module Alexandria
|
|
289
289
|
unabstract
|
290
290
|
end
|
291
291
|
|
292
|
-
require
|
293
|
-
|
294
|
-
# require 'alexandria/book_providers/renaud'
|
295
|
-
log.info { 'Not loading Renaud (provider not functional)' }
|
292
|
+
require "alexandria/book_providers/douban" # only requires YAML
|
296
293
|
|
297
294
|
# Amazon AWS (Amazon Associates Web Services) provider, needs hpricot
|
298
|
-
require
|
295
|
+
require "alexandria/book_providers/amazon_aws"
|
299
296
|
|
300
297
|
# Website based providers
|
301
|
-
require
|
302
|
-
require
|
303
|
-
require
|
304
|
-
require
|
305
|
-
require
|
306
|
-
require
|
298
|
+
require "alexandria/book_providers/adlibris"
|
299
|
+
require "alexandria/book_providers/barnes_and_noble"
|
300
|
+
require "alexandria/book_providers/proxis"
|
301
|
+
require "alexandria/book_providers/siciliano"
|
302
|
+
require "alexandria/book_providers/thalia_provider"
|
303
|
+
require "alexandria/book_providers/worldcat"
|
307
304
|
|
308
305
|
# Z39.50 based providers
|
309
|
-
require
|
306
|
+
require "alexandria/book_providers/z3950"
|
310
307
|
|
311
308
|
attr_reader :abstract_classes
|
312
309
|
|
@@ -328,10 +325,9 @@ module Alexandria
|
|
328
325
|
next unless md
|
329
326
|
|
330
327
|
klass = self.class.module_eval(constant.to_s)
|
331
|
-
if klass
|
328
|
+
if klass < AbstractProvider &&
|
332
329
|
(klass != GenericProvider) &&
|
333
|
-
(klass != WebsiteBasedProvider)
|
334
|
-
(klass != AbstractProvider)
|
330
|
+
(klass != WebsiteBasedProvider)
|
335
331
|
|
336
332
|
if klass.abstract?
|
337
333
|
@abstract_classes << klass
|
@@ -340,16 +336,16 @@ module Alexandria
|
|
340
336
|
end
|
341
337
|
end
|
342
338
|
end
|
343
|
-
if (ary = @prefs.abstract_providers)
|
339
|
+
if (ary = @prefs.get_variable :abstract_providers)
|
344
340
|
ary.each do |name|
|
345
341
|
md = /^(.+)_/.match(name)
|
346
342
|
next unless md
|
347
343
|
|
348
|
-
klass_name = md[1] +
|
344
|
+
klass_name = md[1] + "Provider"
|
349
345
|
klass = @abstract_classes.find { |x| x.name.include?(klass_name) }
|
350
346
|
next unless klass
|
351
347
|
|
352
|
-
fullname = @prefs.send(name.downcase +
|
348
|
+
fullname = @prefs.send(name.downcase + "_name")
|
353
349
|
next unless fullname
|
354
350
|
|
355
351
|
instance = klass.new
|
@@ -369,37 +365,36 @@ module Alexandria
|
|
369
365
|
compact!
|
370
366
|
end
|
371
367
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
end
|
368
|
+
def self.list
|
369
|
+
instance
|
370
|
+
end
|
371
|
+
|
372
|
+
def self.abstract_classes
|
373
|
+
instance.abstract_classes
|
379
374
|
end
|
380
375
|
|
381
376
|
private
|
382
377
|
|
383
378
|
def rejig_providers_priority
|
384
379
|
priority = (@prefs.providers_priority || [])
|
385
|
-
|
386
|
-
changed = false
|
380
|
+
return if priority.empty?
|
387
381
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
382
|
+
changed = false
|
383
|
+
|
384
|
+
if (ecs_index = priority.index("AmazonECS"))
|
385
|
+
priority[ecs_index] = "Amazon" # replace legacy "AmazonECS" name
|
386
|
+
priority.uniq! # remove any other "Amazon" from the list
|
387
|
+
changed = true
|
388
|
+
end
|
389
|
+
if (worldcat_index = priority.index("Worldcat"))
|
390
|
+
priority[worldcat_index] = "WorldCat"
|
391
|
+
changed = true
|
392
|
+
end
|
393
|
+
if (adlibris_index = priority.index("Adlibris"))
|
394
|
+
priority[adlibris_index] = "AdLibris"
|
395
|
+
changed = true
|
402
396
|
end
|
397
|
+
@prefs.providers_priority = priority if changed
|
403
398
|
end
|
404
399
|
end
|
405
400
|
end
|
@@ -1,24 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# This file is part of Alexandria.
|
4
4
|
#
|
5
|
-
#
|
6
|
-
# Copyright (C) 2014 Matijs van Zuijlen
|
7
|
-
#
|
8
|
-
# Alexandria is free software; you can redistribute it and/or
|
9
|
-
# modify it under the terms of the GNU General Public License as
|
10
|
-
# published by the Free Software Foundation; either version 2 of the
|
11
|
-
# License, or (at your option) any later version.
|
12
|
-
#
|
13
|
-
# Alexandria is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
-
# General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public
|
19
|
-
# License along with Alexandria; see the file COPYING. If not,
|
20
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
21
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
22
6
|
|
23
7
|
# AdLibris Bokhandel AB http://www.adlibris.com/se/
|
24
8
|
# Swedish online book store
|
@@ -27,23 +11,23 @@
|
|
27
11
|
# modified to fit the structure of Alexandria book providers.
|
28
12
|
# (26 Feb 2009)
|
29
13
|
|
30
|
-
require
|
31
|
-
require
|
14
|
+
require "cgi"
|
15
|
+
require "alexandria/book_providers/web"
|
32
16
|
|
33
17
|
module Alexandria
|
34
18
|
class BookProviders
|
35
19
|
class AdLibrisProvider < WebsiteBasedProvider
|
36
|
-
include
|
20
|
+
include Logging
|
37
21
|
|
38
|
-
SITE =
|
22
|
+
SITE = "http://www.adlibris.com/se/"
|
39
23
|
|
40
24
|
BASE_SEARCH_URL = "#{SITE}searchresult.aspx?search=advanced&%s=%s" \
|
41
|
-
|
25
|
+
"&fromproduct=False" # type/term
|
42
26
|
|
43
27
|
PRODUCT_URL = "#{SITE}product.aspx?isbn=%s"
|
44
28
|
|
45
29
|
def initialize
|
46
|
-
super(
|
30
|
+
super("AdLibris", "AdLibris (Sweden)")
|
47
31
|
prefs.read
|
48
32
|
# @ent = HTMLEntities.new
|
49
33
|
end
|
@@ -79,10 +63,10 @@ module Alexandria
|
|
79
63
|
PRODUCT_URL % Library.canonicalise_isbn(search_term)
|
80
64
|
else
|
81
65
|
(search_type_code = {
|
82
|
-
SEARCH_BY_AUTHORS =>
|
83
|
-
SEARCH_BY_TITLE =>
|
84
|
-
SEARCH_BY_KEYWORD =>
|
85
|
-
}[search_type]) ||
|
66
|
+
SEARCH_BY_AUTHORS => "author",
|
67
|
+
SEARCH_BY_TITLE => "title",
|
68
|
+
SEARCH_BY_KEYWORD => "keyword"
|
69
|
+
}[search_type]) || "keyword"
|
86
70
|
search_term_encoded = CGI.escape(search_term)
|
87
71
|
format(BASE_SEARCH_URL, search_type_code, search_term_encoded)
|
88
72
|
end
|
@@ -97,20 +81,17 @@ module Alexandria
|
|
97
81
|
end
|
98
82
|
|
99
83
|
def parse_search_result_data(html)
|
100
|
-
# adlibris site presents data in ISO-8859-1, so change it to UTF-8
|
101
|
-
# html = Iconv.conv("UTF-8", "ISO-8859-1", html)
|
102
|
-
# doc = Hpricot(html)
|
103
84
|
doc = html_to_doc(html)
|
104
85
|
book_search_results = []
|
105
86
|
|
106
87
|
search_hit = doc.search("div'searchResult")[0]
|
107
88
|
return [] unless search_hit
|
108
89
|
|
109
|
-
(search_hit /
|
90
|
+
(search_hit / "ul.ulSearch table").each do |t|
|
110
91
|
result = {}
|
111
|
-
if (title_data = (t %
|
92
|
+
if (title_data = (t % "div.divTitle"))
|
112
93
|
result[:title] = (title_data % :a).inner_text
|
113
|
-
lookup_url = (title_data % :a)[
|
94
|
+
lookup_url = (title_data % :a)["href"]
|
114
95
|
end
|
115
96
|
result[:lookup_url] = "#{SITE}#{lookup_url}"
|
116
97
|
|
@@ -119,45 +100,25 @@ module Alexandria
|
|
119
100
|
book_search_results
|
120
101
|
end
|
121
102
|
|
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äftad == Paperback
|
131
|
-
# end
|
132
|
-
|
133
103
|
def normalize(text)
|
134
|
-
# unless text.nil?
|
135
|
-
# text = @ent.decode(text).strip
|
136
|
-
# end
|
137
104
|
text
|
138
105
|
end
|
139
106
|
|
140
107
|
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
108
|
doc = html_to_doc(html)
|
146
109
|
begin
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
raise NoResultsError, 'title not found on page'
|
152
|
-
end
|
110
|
+
h1 = doc.at("div.productTitleFormat h1")
|
111
|
+
raise NoResultsError, _("title not found on page") unless h1
|
112
|
+
|
113
|
+
title = text_of(h1)
|
153
114
|
|
154
|
-
product = doc.at(
|
155
|
-
ul_info = doc.at(
|
115
|
+
product = doc.at("div.product")
|
116
|
+
ul_info = doc.at("ul.info") # NOTE, two of these
|
156
117
|
|
157
|
-
author_cells = ul_info.search(
|
118
|
+
author_cells = ul_info.search("li.liAuthor") # css-like search
|
158
119
|
authors = []
|
159
120
|
author_cells.each do |li|
|
160
|
-
author_name = text_of(li.search(
|
121
|
+
author_name = text_of(li.search("h2 > a")[0])
|
161
122
|
|
162
123
|
authors << author_name
|
163
124
|
end
|
@@ -168,9 +129,9 @@ module Alexandria
|
|
168
129
|
end
|
169
130
|
|
170
131
|
binding = nil
|
171
|
-
if (format = doc.search(
|
132
|
+
if (format = doc.search("div.productTitleFormat span").first)
|
172
133
|
binding = text_of(format)
|
173
|
-
binding = Regexp.last_match[1] if binding =~ /\(([
|
134
|
+
binding = Regexp.last_match[1] if binding =~ /\(([^)]+)\)/
|
174
135
|
end
|
175
136
|
|
176
137
|
year = nil
|
@@ -186,8 +147,8 @@ module Alexandria
|
|
186
147
|
isbn = isbn_td.inner_text
|
187
148
|
next unless isbn =~ /[0-9x]{10,13}/i
|
188
149
|
|
189
|
-
isbn.gsub(/(\n|\r)/,
|
190
|
-
isbn = Regexp.last_match[1] if isbn =~
|
150
|
+
isbn.gsub(/(\n|\r)/, " ")
|
151
|
+
isbn = Regexp.last_match[1] if isbn =~ /:\s*([0-9x]+)/i
|
191
152
|
isbns << isbn
|
192
153
|
end
|
193
154
|
isbn = isbns.first
|
@@ -195,13 +156,15 @@ module Alexandria
|
|
195
156
|
|
196
157
|
# cover
|
197
158
|
image_url = nil
|
198
|
-
|
199
|
-
|
200
|
-
|
159
|
+
cover_img =
|
160
|
+
doc.search('span.imageWithShadow img[@id$="ProductImageNotLinked"]').first
|
161
|
+
if cover_img
|
162
|
+
image_url = if cover_img["src"].start_with?("http://")
|
163
|
+
cover_img["src"]
|
201
164
|
else
|
202
165
|
"#{SITE}/#{cover_img['src']}" # HACK: use html base
|
203
166
|
end
|
204
|
-
if
|
167
|
+
if /noimage.gif$/.match?(image_url)
|
205
168
|
# no point downloading a "no image" graphic
|
206
169
|
# Alexandria has its own generic book icon...
|
207
170
|
image_url = nil
|
@@ -211,15 +174,15 @@ module Alexandria
|
|
211
174
|
|
212
175
|
book = Book.new(title, authors, isbn, publisher, year, binding)
|
213
176
|
|
214
|
-
|
177
|
+
[book, image_url]
|
215
178
|
rescue StandardError => ex
|
216
179
|
raise ex if ex.instance_of? NoResultsError
|
217
180
|
|
218
181
|
trace = ex.backtrace.join("\n> ")
|
219
|
-
log.warn
|
220
|
-
|
182
|
+
log.warn do
|
183
|
+
"Failed parsing search results for AdLibris " \
|
221
184
|
"#{ex.message} #{trace}"
|
222
|
-
|
185
|
+
end
|
223
186
|
raise NoResultsError
|
224
187
|
end
|
225
188
|
end
|