alexandria-book-collection-manager 0.7.2 → 0.7.7
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 +5 -1
- data/.hound.yml +2 -0
- data/.rubocop.yml +87 -37
- data/.rubocop_todo.yml +62 -191
- data/.simplecov +5 -2
- data/CHANGELOG.md +63 -0
- data/Gemfile +4 -3
- data/INSTALL.md +26 -14
- data/README.md +52 -42
- data/Rakefile +93 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +50 -43
- data/bin/alexandria +30 -53
- data/doc/FAQ +2 -6
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +27 -37
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +90 -97
- data/lib/alexandria/book_providers/adlibris.rb +41 -76
- data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
- data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
- data/lib/alexandria/book_providers/douban.rb +26 -42
- data/lib/alexandria/book_providers/proxis.rb +44 -55
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +64 -65
- data/lib/alexandria/book_providers/thalia.rb +42 -41
- data/lib/alexandria/book_providers/web.rb +15 -33
- data/lib/alexandria/book_providers/worldcat.rb +70 -97
- data/lib/alexandria/book_providers/z3950.rb +160 -173
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +8 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +15 -13
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +193 -300
- data/lib/alexandria/import_library.rb +108 -141
- data/lib/alexandria/import_library_csv.rb +43 -46
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +11 -13
- data/lib/alexandria/models/book.rb +13 -20
- data/lib/alexandria/models/library.rb +81 -353
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +73 -87
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +133 -170
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- 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} +39 -52
- data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
- data/lib/alexandria/ui/builder_base.rb +7 -27
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +189 -183
- data/lib/alexandria/ui/completion_models.rb +10 -23
- 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/export_dialog.rb +142 -0
- data/lib/alexandria/ui/icons.rb +47 -63
- 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 +21 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +16 -14
- data/lib/alexandria/ui/listview.rb +73 -87
- 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 +28 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- 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/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
- 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 +236 -251
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +22 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1017 -974
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- 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 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +75 -171
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +128 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- 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 +30 -25
- 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 +17 -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 +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- 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 +43 -20
- data/spec/end_to_end/basic_run_spec.rb +52 -0
- data/spec/spec_helper.rb +65 -33
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +16 -3
- data/util/rake/fileinstall.rb +39 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +178 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
- data/lib/alexandria/book_providers/renaud.rb +0 -149
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -96
- 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 =>
|
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,26 +289,21 @@ module Alexandria
|
|
289
289
|
unabstract
|
290
290
|
end
|
291
291
|
|
292
|
-
require
|
293
|
-
require 'alexandria/book_providers/douban' # only requires YAML
|
294
|
-
|
295
|
-
# require 'alexandria/book_providers/renaud'
|
296
|
-
log.info { 'Not loading Renaud (provider not functional)' }
|
292
|
+
require "alexandria/book_providers/douban" # only requires YAML
|
297
293
|
|
298
294
|
# Amazon AWS (Amazon Associates Web Services) provider, needs hpricot
|
299
|
-
require
|
295
|
+
require "alexandria/book_providers/amazon_aws"
|
300
296
|
|
301
297
|
# Website based providers
|
302
|
-
require
|
303
|
-
require
|
304
|
-
require
|
305
|
-
require
|
306
|
-
require
|
307
|
-
require
|
308
|
-
require 'alexandria/book_providers/worldcat'
|
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"
|
303
|
+
require "alexandria/book_providers/worldcat"
|
309
304
|
|
310
305
|
# Z39.50 based providers
|
311
|
-
require
|
306
|
+
require "alexandria/book_providers/z3950"
|
312
307
|
|
313
308
|
attr_reader :abstract_classes
|
314
309
|
|
@@ -328,11 +323,11 @@ module Alexandria
|
|
328
323
|
self.class.constants.each do |constant|
|
329
324
|
md = /(.+)Provider$/.match(constant)
|
330
325
|
next unless md
|
326
|
+
|
331
327
|
klass = self.class.module_eval(constant.to_s)
|
332
|
-
if klass
|
328
|
+
if klass < AbstractProvider &&
|
333
329
|
(klass != GenericProvider) &&
|
334
|
-
(klass != WebsiteBasedProvider)
|
335
|
-
(klass != AbstractProvider)
|
330
|
+
(klass != WebsiteBasedProvider)
|
336
331
|
|
337
332
|
if klass.abstract?
|
338
333
|
@abstract_classes << klass
|
@@ -341,15 +336,18 @@ module Alexandria
|
|
341
336
|
end
|
342
337
|
end
|
343
338
|
end
|
344
|
-
if (ary = @prefs.abstract_providers)
|
339
|
+
if (ary = @prefs.get_variable :abstract_providers)
|
345
340
|
ary.each do |name|
|
346
341
|
md = /^(.+)_/.match(name)
|
347
342
|
next unless md
|
348
|
-
|
343
|
+
|
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
|
+
|
348
|
+
fullname = @prefs.send(name.downcase + "_name")
|
352
349
|
next unless fullname
|
350
|
+
|
353
351
|
instance = klass.new
|
354
352
|
instance.name = name
|
355
353
|
instance.fullname = fullname
|
@@ -367,41 +365,36 @@ module Alexandria
|
|
367
365
|
compact!
|
368
366
|
end
|
369
367
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
end
|
368
|
+
def self.list
|
369
|
+
instance
|
370
|
+
end
|
371
|
+
|
372
|
+
def self.abstract_classes
|
373
|
+
instance.abstract_classes
|
377
374
|
end
|
378
375
|
|
379
376
|
private
|
380
377
|
|
381
378
|
def rejig_providers_priority
|
382
379
|
priority = (@prefs.providers_priority || [])
|
383
|
-
|
384
|
-
changed = false
|
380
|
+
return if priority.empty?
|
385
381
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
priority[adlibris_index] = 'AdLibris'
|
401
|
-
changed = true
|
402
|
-
end
|
403
|
-
@prefs.providers_priority = priority if changed
|
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
|
404
396
|
end
|
397
|
+
@prefs.providers_priority = priority if changed
|
405
398
|
end
|
406
399
|
end
|
407
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
|
@@ -67,7 +51,7 @@ module Alexandria
|
|
67
51
|
## url
|
68
52
|
def url(book)
|
69
53
|
create_search_uri(SEARCH_BY_ISBN, book.isbn)
|
70
|
-
rescue => ex
|
54
|
+
rescue StandardError => ex
|
71
55
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
72
56
|
nil
|
73
57
|
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
|
-
title = text_of(h1)
|
150
|
-
else
|
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
|
153
112
|
|
154
|
-
|
155
|
-
ul_info = doc.at('ul.info') # NOTE, two of these
|
113
|
+
title = text_of(h1)
|
156
114
|
|
157
|
-
|
115
|
+
product = doc.at("div.product")
|
116
|
+
ul_info = doc.at("ul.info") # NOTE, two of these
|
117
|
+
|
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
|
@@ -185,8 +146,9 @@ module Alexandria
|
|
185
146
|
isbn_tds.each do |isbn_td|
|
186
147
|
isbn = isbn_td.inner_text
|
187
148
|
next unless isbn =~ /[0-9x]{10,13}/i
|
188
|
-
|
189
|
-
isbn
|
149
|
+
|
150
|
+
isbn.gsub(/(\n|\r)/, " ")
|
151
|
+
isbn = Regexp.last_match[1] if isbn =~ /:\s*([0-9x]+)/i
|
190
152
|
isbns << isbn
|
191
153
|
end
|
192
154
|
isbn = isbns.first
|
@@ -194,13 +156,15 @@ module Alexandria
|
|
194
156
|
|
195
157
|
# cover
|
196
158
|
image_url = nil
|
197
|
-
|
198
|
-
|
199
|
-
|
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"]
|
200
164
|
else
|
201
165
|
"#{SITE}/#{cover_img['src']}" # HACK: use html base
|
202
166
|
end
|
203
|
-
if
|
167
|
+
if /noimage.gif$/.match?(image_url)
|
204
168
|
# no point downloading a "no image" graphic
|
205
169
|
# Alexandria has its own generic book icon...
|
206
170
|
image_url = nil
|
@@ -210,14 +174,15 @@ module Alexandria
|
|
210
174
|
|
211
175
|
book = Book.new(title, authors, isbn, publisher, year, binding)
|
212
176
|
|
213
|
-
|
214
|
-
rescue => ex
|
177
|
+
[book, image_url]
|
178
|
+
rescue StandardError => ex
|
215
179
|
raise ex if ex.instance_of? NoResultsError
|
180
|
+
|
216
181
|
trace = ex.backtrace.join("\n> ")
|
217
|
-
log.warn
|
218
|
-
|
182
|
+
log.warn do
|
183
|
+
"Failed parsing search results for AdLibris " \
|
219
184
|
"#{ex.message} #{trace}"
|
220
|
-
|
185
|
+
end
|
221
186
|
raise NoResultsError
|
222
187
|
end
|
223
188
|
end
|