alexandria-book-collection-manager 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +34 -30
- data/.rubocop_todo.yml +139 -54
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Rakefile +10 -11
- data/alexandria-book-collection-manager.gemspec +3 -2
- data/bin/alexandria +1 -1
- data/lib/alexandria.rb +3 -6
- data/lib/alexandria/about.rb +9 -9
- data/lib/alexandria/book_providers.rb +12 -12
- data/lib/alexandria/book_providers/adlibris.rb +14 -18
- data/lib/alexandria/book_providers/amazon_aws.rb +17 -31
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +5 -6
- data/lib/alexandria/book_providers/barnes_and_noble.rb +51 -76
- data/lib/alexandria/book_providers/bol_it.rb +12 -12
- data/lib/alexandria/book_providers/deastore.rb +27 -31
- data/lib/alexandria/book_providers/douban.rb +9 -13
- data/lib/alexandria/book_providers/ibs_it.rb +10 -10
- data/lib/alexandria/book_providers/mcu.rb +12 -18
- data/lib/alexandria/book_providers/proxis.rb +14 -22
- data/lib/alexandria/book_providers/pseudomarc.rb +8 -18
- data/lib/alexandria/book_providers/renaud.rb +16 -16
- data/lib/alexandria/book_providers/siciliano.rb +25 -38
- data/lib/alexandria/book_providers/thalia.rb +13 -16
- data/lib/alexandria/book_providers/webster_it.rb +14 -18
- data/lib/alexandria/book_providers/worldcat.rb +21 -25
- data/lib/alexandria/book_providers/z3950.rb +19 -23
- data/lib/alexandria/config.rb +2 -2
- data/lib/alexandria/execution_queue.rb +3 -1
- data/lib/alexandria/export_library.rb +19 -22
- data/lib/alexandria/import_library.rb +14 -18
- data/lib/alexandria/import_library_csv.rb +12 -30
- data/lib/alexandria/models/book.rb +7 -9
- data/lib/alexandria/models/library.rb +44 -44
- data/lib/alexandria/net.rb +1 -1
- data/lib/alexandria/preferences.rb +12 -57
- data/lib/alexandria/scanners.rb +10 -6
- data/lib/alexandria/scanners/cuecat.rb +2 -2
- data/lib/alexandria/smart_library.rb +12 -12
- data/lib/alexandria/ui.rb +5 -2
- data/lib/alexandria/ui/callbacks.rb +106 -65
- data/lib/alexandria/ui/completion_models.rb +55 -51
- data/lib/alexandria/ui/dialogs/about_dialog.rb +1 -1
- data/lib/alexandria/ui/dialogs/acquire_dialog.rb +25 -51
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +13 -11
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +2 -2
- data/lib/alexandria/ui/dialogs/barcode_animation.rb +39 -23
- data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +16 -21
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +23 -24
- data/lib/alexandria/ui/dialogs/export_dialog.rb +46 -45
- data/lib/alexandria/ui/dialogs/import_dialog.rb +26 -35
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +11 -11
- data/lib/alexandria/ui/dialogs/new_book_dialog.rb +47 -59
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +14 -13
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +12 -11
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +37 -43
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +9 -8
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +47 -53
- data/lib/alexandria/ui/dndable.rb +5 -4
- data/lib/alexandria/ui/icons.rb +19 -19
- data/lib/alexandria/ui/iconview.rb +7 -12
- data/lib/alexandria/ui/iconview_tooltips.rb +22 -109
- data/lib/alexandria/ui/init.rb +7 -15
- data/lib/alexandria/ui/libraries_combo.rb +54 -48
- data/lib/alexandria/ui/listview.rb +30 -85
- data/lib/alexandria/ui/multi_drag_treeview.rb +110 -107
- data/lib/alexandria/ui/sidepane.rb +23 -25
- data/lib/alexandria/ui/sound.rb +18 -27
- data/lib/alexandria/ui/ui_manager.rb +126 -204
- data/lib/alexandria/undo_manager.rb +2 -2
- data/lib/alexandria/version.rb +4 -4
- data/spec/alexandria/book_providers_spec.rb +7 -4
- data/spec/alexandria/library_spec.rb +13 -16
- data/spec/alexandria/scanners/cuecat_spec.rb +1 -2
- data/spec/alexandria/ui/dialogs_spec.rb +5 -1
- data/spec/alexandria/ui/main_app_spec.rb +3 -3
- data/{lib/alexandria/utils.rb → spec/alexandria/ui/sound_spec.rb} +6 -11
- data/spec/alexandria/ui/ui_utilities_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -2
- data/util/rake/fileinstall.rb +17 -33
- data/util/rake/gettextgenerate.rb +2 -4
- data/util/rake/omfgenerate.rb +1 -3
- metadata +23 -11
- data/lib/alexandria/ui/gtk_thread_help.rb +0 -89
@@ -27,7 +27,7 @@ module Alexandria
|
|
27
27
|
year: ['210', 'd'],
|
28
28
|
binding: ['225', 'a'],
|
29
29
|
notes: ['520', 'a']
|
30
|
-
}
|
30
|
+
}.freeze
|
31
31
|
|
32
32
|
USMARC_MAPPINGS = {
|
33
33
|
title: ['245', 'a', 'b'],
|
@@ -37,7 +37,7 @@ module Alexandria
|
|
37
37
|
year: ['260', 'c'],
|
38
38
|
binding: ['020', 'a'], # listed with isbn here
|
39
39
|
notes: ['520', 'a']
|
40
|
-
}
|
40
|
+
}.freeze
|
41
41
|
|
42
42
|
def self.get_fields(data, type, stripping, m = USMARC_MAPPINGS)
|
43
43
|
field = ''
|
@@ -48,15 +48,11 @@ module Alexandria
|
|
48
48
|
part_data = Regexp.last_match[1]
|
49
49
|
part_data = part_data.strip
|
50
50
|
end
|
51
|
-
if field != ''
|
52
|
-
field += ': '
|
53
|
-
end
|
51
|
+
field += ': ' if field != ''
|
54
52
|
field += part_data
|
55
53
|
end
|
56
54
|
end
|
57
|
-
if field == ''
|
58
|
-
field = nil
|
59
|
-
end
|
55
|
+
field = nil if field == ''
|
60
56
|
field
|
61
57
|
end
|
62
58
|
|
@@ -67,9 +63,7 @@ module Alexandria
|
|
67
63
|
title_data = details[m[:title][0]]
|
68
64
|
if title_data
|
69
65
|
title_data_all = get_fields(title_data, :title, /(.*)[\/:]$/, m)
|
70
|
-
if title_data_all
|
71
|
-
title = title_data_all
|
72
|
-
end
|
66
|
+
title = title_data_all if title_data_all
|
73
67
|
end
|
74
68
|
|
75
69
|
authors = []
|
@@ -123,13 +117,11 @@ module Alexandria
|
|
123
117
|
if notes_data
|
124
118
|
notes_data.each do |note|
|
125
119
|
txt = note[m[:notes][1]]
|
126
|
-
if txt
|
127
|
-
notes += txt
|
128
|
-
end
|
120
|
+
notes += txt if txt
|
129
121
|
end
|
130
122
|
end
|
131
123
|
|
132
|
-
if title.nil?
|
124
|
+
if title.nil? && isbn.nil?
|
133
125
|
# probably didn't undertand the MARC dialect
|
134
126
|
return nil
|
135
127
|
end
|
@@ -171,9 +163,7 @@ module Alexandria
|
|
171
163
|
end
|
172
164
|
|
173
165
|
unless this_line_data.empty?
|
174
|
-
unless details.key?(code)
|
175
|
-
details[code] = []
|
176
|
-
end
|
166
|
+
details[code] = [] unless details.key?(code)
|
177
167
|
details[code] << this_line_data
|
178
168
|
end
|
179
169
|
|
@@ -25,15 +25,15 @@ module Alexandria
|
|
25
25
|
class RENAUDProvider < GenericProvider
|
26
26
|
include GetText
|
27
27
|
# GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
|
28
|
-
BASE_URI = 'http://www.renaud-bray.com/'
|
29
|
-
ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'
|
28
|
+
BASE_URI = 'http://www.renaud-bray.com/'.freeze
|
29
|
+
ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'.freeze
|
30
30
|
|
31
31
|
def initialize
|
32
32
|
super('RENAUD', 'Renaud-Bray (Canada)')
|
33
33
|
end
|
34
34
|
|
35
35
|
def search(criterion, type)
|
36
|
-
criterion = criterion.
|
36
|
+
criterion = criterion.encode('ISO-8859-1')
|
37
37
|
req = BASE_URI + 'francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri='
|
38
38
|
# req = BASE_URI + "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri="
|
39
39
|
req += case type
|
@@ -58,14 +58,14 @@ module Alexandria
|
|
58
58
|
return to_books(data).pop
|
59
59
|
else
|
60
60
|
results = []
|
61
|
-
to_books(data).each {|book|
|
61
|
+
to_books(data).each { |book|
|
62
62
|
results << book
|
63
63
|
}
|
64
|
-
while /Suivant
|
64
|
+
while /Suivant/ =~ data
|
65
65
|
md = /Enteterouge\">([\d]*)<\/b>/.match(data)
|
66
66
|
num = md[1].to_i + 1
|
67
67
|
data = transport.get(URI.parse(req + '&PageActuelle=' + num.to_s))
|
68
|
-
to_books(data).each {|book|
|
68
|
+
to_books(data).each { |book|
|
69
69
|
results << book
|
70
70
|
}
|
71
71
|
end
|
@@ -85,16 +85,16 @@ module Alexandria
|
|
85
85
|
|
86
86
|
def to_books(data)
|
87
87
|
data = CGI.unescapeHTML(data)
|
88
|
-
data = data.
|
89
|
-
raise NoResultsError if /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong
|
88
|
+
data = data.encode('UTF-8')
|
89
|
+
raise NoResultsError if data =~ /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong>/
|
90
90
|
|
91
91
|
titles = []
|
92
|
-
data.scan(/"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/).each {|md|
|
92
|
+
data.scan(/"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/).each { |md|
|
93
93
|
titles << md[1].strip
|
94
94
|
}
|
95
95
|
raise if titles.empty?
|
96
96
|
authors = []
|
97
|
-
data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each {|md|
|
97
|
+
data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each { |md|
|
98
98
|
authors2 = []
|
99
99
|
for author in md[0].split(' ')
|
100
100
|
authors2 << author.strip
|
@@ -103,30 +103,30 @@ module Alexandria
|
|
103
103
|
}
|
104
104
|
raise if authors.empty?
|
105
105
|
isbns = []
|
106
|
-
data.scan(/ISBN : ?<\/td><td>(\d+)/).each {|md|
|
106
|
+
data.scan(/ISBN : ?<\/td><td>(\d+)/).each { |md|
|
107
107
|
isbns << md[0].strip
|
108
108
|
}
|
109
109
|
raise if isbns.empty?
|
110
110
|
editions = []
|
111
111
|
publish_years = []
|
112
|
-
data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each {|md|
|
112
|
+
data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each { |md|
|
113
113
|
editions << md[0].strip
|
114
114
|
publish_years << md[0].strip.split(/-/)[0].to_i
|
115
115
|
}
|
116
|
-
raise if editions.empty?
|
116
|
+
raise if editions.empty? || publish_years.empty?
|
117
117
|
publishers = []
|
118
|
-
data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each {|md|
|
118
|
+
data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each { |md|
|
119
119
|
publishers << md[0].strip
|
120
120
|
}
|
121
121
|
raise if publishers.empty?
|
122
122
|
book_covers = []
|
123
|
-
data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))|\/francais\/suggestion\/images\/livre\/livre.gif)/).each {|md|
|
123
|
+
data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))|\/francais\/suggestion\/images\/livre\/livre.gif)/).each { |md|
|
124
124
|
book_covers << BASE_URI + md[0].strip
|
125
125
|
}
|
126
126
|
raise if book_covers.empty?
|
127
127
|
|
128
128
|
books = []
|
129
|
-
titles.each_with_index {|title, i|
|
129
|
+
titles.each_with_index { |title, i|
|
130
130
|
books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
|
131
131
|
book_covers[i]]
|
132
132
|
# print books
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (C) 2004 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
|
3
3
|
# Copyright (C) 2009 Cathal Mc Ginley
|
4
|
-
# Copyright (C) 2011, 2014 Matijs van Zuijlen
|
4
|
+
# Copyright (C) 2011, 2014, 2016 Matijs van Zuijlen
|
5
5
|
#
|
6
6
|
# Alexandria is free software; you can redistribute it and/or
|
7
7
|
# modify it under the terms of the GNU General Public License as
|
@@ -32,7 +32,7 @@ module Alexandria
|
|
32
32
|
class SicilianoProvider < WebsiteBasedProvider
|
33
33
|
include Logging
|
34
34
|
|
35
|
-
SITE = 'http://www.siciliano.com.br'
|
35
|
+
SITE = 'http://www.siciliano.com.br'.freeze
|
36
36
|
|
37
37
|
# The string interpolations in this URL are the search term and search
|
38
38
|
# type, respectively.
|
@@ -40,7 +40,7 @@ module Alexandria
|
|
40
40
|
'&FIL_ID=102' \
|
41
41
|
'&PALAVRASN1=%s' \
|
42
42
|
'&FILTRON1=%s' \
|
43
|
-
'&ESTRUTN1=0301&ORDEMN2=E'
|
43
|
+
'&ESTRUTN1=0301&ORDEMN2=E'.freeze
|
44
44
|
|
45
45
|
def initialize
|
46
46
|
super('Siciliano', 'Livraria Siciliano (Brasil)')
|
@@ -55,12 +55,7 @@ module Alexandria
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def search(criterion, type)
|
58
|
-
|
59
|
-
criterion = criterion.convert('ISO-8859-1', 'UTF-8') # still needed??
|
60
|
-
rescue GLib::ConvertError
|
61
|
-
log.info { "Cannot search for non-ISO-8859-1 terms at Siciliano : #{criterion}" }
|
62
|
-
raise NoResultsError
|
63
|
-
end
|
58
|
+
criterion = criterion.encode('ISO-8859-1') # still needed??
|
64
59
|
trying_again = false
|
65
60
|
begin
|
66
61
|
req = create_search_uri(type, criterion, trying_again)
|
@@ -76,7 +71,7 @@ module Alexandria
|
|
76
71
|
end
|
77
72
|
|
78
73
|
rescue NoResultsError => err
|
79
|
-
if (type == SEARCH_BY_ISBN)
|
74
|
+
if (type == SEARCH_BY_ISBN) && (trying_again == false)
|
80
75
|
trying_again = true
|
81
76
|
retry
|
82
77
|
else
|
@@ -94,23 +89,21 @@ module Alexandria
|
|
94
89
|
private
|
95
90
|
|
96
91
|
def create_search_uri(search_type, search_term, trying_again = false)
|
97
|
-
search_type_code = { SEARCH_BY_ISBN => 'G',
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
search_term_encoded = CGI.escape(search_term)
|
113
|
-
end
|
92
|
+
(search_type_code = { SEARCH_BY_ISBN => 'G',
|
93
|
+
SEARCH_BY_TITLE => 'A',
|
94
|
+
SEARCH_BY_AUTHORS => 'B',
|
95
|
+
SEARCH_BY_KEYWORD => 'X' }[search_type]) || 'X'
|
96
|
+
search_term_encoded = if search_type == SEARCH_BY_ISBN
|
97
|
+
if trying_again
|
98
|
+
# on second attempt, try ISBN-10...
|
99
|
+
Library.canonicalise_isbn(search_term) # isbn-10
|
100
|
+
else
|
101
|
+
# search by ISBN-13 first
|
102
|
+
Library.canonicalise_ean(search_term) # isbn-13
|
103
|
+
end
|
104
|
+
else
|
105
|
+
CGI.escape(search_term)
|
106
|
+
end
|
114
107
|
|
115
108
|
BASE_SEARCH_URL % [search_term_encoded, search_type_code]
|
116
109
|
end
|
@@ -150,10 +143,8 @@ module Alexandria
|
|
150
143
|
result[:title] = link.inner_text.strip
|
151
144
|
link_to_description = link['href']
|
152
145
|
slash = ''
|
153
|
-
unless link_to_description =~ /^\//
|
154
|
-
|
155
|
-
end
|
156
|
-
result[:url] = "#{SITE}#{slash}#{link_to_description}"
|
146
|
+
slash = '/' unless link_to_description =~ /^\//
|
147
|
+
result[:url] = "#{SITE}#{slash}#{link_to_description}"
|
157
148
|
|
158
149
|
book_search_results << result
|
159
150
|
rescue => ex
|
@@ -187,9 +178,7 @@ module Alexandria
|
|
187
178
|
isbn = details['ISBN']
|
188
179
|
## ean = details["CdBarras"]
|
189
180
|
translator = details['Tradutor']
|
190
|
-
if translator
|
191
|
-
authors << translator
|
192
|
-
end
|
181
|
+
authors << translator if translator
|
193
182
|
binding = details['Acabamento']
|
194
183
|
publisher = search_result[:publisher]
|
195
184
|
# publish year
|
@@ -214,7 +203,7 @@ module Alexandria
|
|
214
203
|
end
|
215
204
|
end
|
216
205
|
book = Book.new(title, authors, isbn, publisher, publish_year, binding)
|
217
|
-
result =
|
206
|
+
result = [book, image_urls.first]
|
218
207
|
return result
|
219
208
|
rescue => ex
|
220
209
|
trace = ex.backtrace.join("\n> ")
|
@@ -255,9 +244,7 @@ module Alexandria
|
|
255
244
|
arr.each do |str|
|
256
245
|
key, val = str.split(':')
|
257
246
|
# a real hack for not handling encoding properly :^)
|
258
|
-
if val
|
259
|
-
map[key.gsub(/[^a-zA-Z]/, '')] = val.strip
|
260
|
-
end
|
247
|
+
map[key.gsub(/[^a-zA-Z]/, '')] = val.strip if val
|
261
248
|
end
|
262
249
|
map
|
263
250
|
end
|
@@ -31,8 +31,8 @@ module Alexandria
|
|
31
31
|
class ThaliaProvider < WebsiteBasedProvider
|
32
32
|
include Alexandria::Logging
|
33
33
|
|
34
|
-
SITE = 'http://www.thalia.de'
|
35
|
-
BASE_SEARCH_URL = "#{SITE}/shop/bde_bu_hg_startseite/suche/?%s=%s" # type,term
|
34
|
+
SITE = 'http://www.thalia.de'.freeze
|
35
|
+
BASE_SEARCH_URL = "#{SITE}/shop/bde_bu_hg_startseite/suche/?%s=%s".freeze # type,term
|
36
36
|
|
37
37
|
def initialize
|
38
38
|
super('Thalia', 'Thalia (Germany)')
|
@@ -58,20 +58,19 @@ module Alexandria
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def create_search_uri(search_type, search_term)
|
61
|
-
search_type_code = {
|
61
|
+
(search_type_code = {
|
62
62
|
SEARCH_BY_ISBN => 'sq',
|
63
63
|
SEARCH_BY_AUTHORS => 'sa', # Autor
|
64
64
|
SEARCH_BY_TITLE => 'st', # Titel
|
65
65
|
SEARCH_BY_KEYWORD => 'ssw' # Schlagwort
|
66
|
-
}[search_type]
|
66
|
+
}[search_type]) || ''
|
67
67
|
search_type_code = CGI.escape(search_type_code)
|
68
|
-
search_term_encoded =
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
68
|
+
search_term_encoded = if search_type == SEARCH_BY_ISBN
|
69
|
+
# search_term_encoded = search_term.as_isbn_13
|
70
|
+
Library.canonicalise_isbn(search_term) # check this!
|
71
|
+
else
|
72
|
+
CGI.escape(search_term)
|
73
|
+
end
|
75
74
|
BASE_SEARCH_URL % [search_type_code, search_term_encoded]
|
76
75
|
end
|
77
76
|
|
@@ -94,9 +93,7 @@ module Alexandria
|
|
94
93
|
if (item_node = label_node.parent)
|
95
94
|
data = ''
|
96
95
|
item_node.children.each do |n|
|
97
|
-
if n.text?
|
98
|
-
data += n.to_html
|
99
|
-
end
|
96
|
+
data += n.to_html if n.text?
|
100
97
|
end
|
101
98
|
data.strip
|
102
99
|
else
|
@@ -106,7 +103,7 @@ module Alexandria
|
|
106
103
|
|
107
104
|
def get_book_from_search_result(result)
|
108
105
|
log.debug { "Fetching book from #{result[:lookup_url]}" }
|
109
|
-
html_data =
|
106
|
+
html_data = transport.get_response(URI.parse(result[:lookup_url]))
|
110
107
|
parse_result_data(html_data.body, 'noisbn', true)
|
111
108
|
end
|
112
109
|
|
@@ -130,7 +127,7 @@ module Alexandria
|
|
130
127
|
chosen = results.first # fallback!
|
131
128
|
results.each do |rslt|
|
132
129
|
if rslt[:lookup_url] =~ /\/ISBN(\d+[\d-]*)\//
|
133
|
-
if Regexp.last_match[1].
|
130
|
+
if Regexp.last_match[1].delete('-') == isbn10
|
134
131
|
chosen = rslt
|
135
132
|
break
|
136
133
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (C) 2007 Marco Costantini
|
2
|
-
# Copyright (C) 2014 Matijs van Zuijlen
|
2
|
+
# Copyright (C) 2014, 2016 Matijs van Zuijlen
|
3
3
|
# based on ibs_it.rb by Claudio Belotti
|
4
4
|
#
|
5
5
|
# Alexandria is free software; you can redistribute it and/or
|
@@ -25,10 +25,10 @@ require 'open-uri'
|
|
25
25
|
module Alexandria
|
26
26
|
class BookProviders
|
27
27
|
class Webster_itProvider < GenericProvider
|
28
|
-
BASE_URI = 'http://www.libreriauniversitaria.it' # also "http://www.webster.it"
|
28
|
+
BASE_URI = 'http://www.libreriauniversitaria.it'.freeze # also "http://www.webster.it"
|
29
29
|
CACHE_DIR = File.join(Alexandria::Library::DIR, '.webster_it_cache')
|
30
30
|
REFERER = BASE_URI
|
31
|
-
LOCALE = 'BIT' # used only for search by title/author/keyword. possible are: "BIT", "BUS", "BUK", "BDE", "MIT"
|
31
|
+
LOCALE = 'BIT'.freeze # used only for search by title/author/keyword. possible are: "BIT", "BUS", "BUK", "BDE", "MIT"
|
32
32
|
def initialize
|
33
33
|
super('Webster_it', 'Webster (Italy)')
|
34
34
|
FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR)
|
@@ -37,7 +37,7 @@ module Alexandria
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def search(criterion, type)
|
40
|
-
criterion = criterion.
|
40
|
+
criterion = criterion.encode('ISO-8859-15')
|
41
41
|
req = BASE_URI + '/'
|
42
42
|
req += case type
|
43
43
|
when SEARCH_BY_ISBN
|
@@ -82,8 +82,8 @@ module Alexandria
|
|
82
82
|
private
|
83
83
|
|
84
84
|
def to_book(data)
|
85
|
-
raise NoResultsError if /<font color="\#ffffff"><b>Prodotto non esistente<\/b><\/font
|
86
|
-
data = data.
|
85
|
+
raise NoResultsError if data =~ /<font color="\#ffffff"><b>Prodotto non esistente<\/b><\/font>/
|
86
|
+
data = data.encode('UTF-8')
|
87
87
|
|
88
88
|
md = /<li><span class="product_label">Titolo:<\/span><span class="product_text"> ([^<]+)/.match(data)
|
89
89
|
raise unless md
|
@@ -107,26 +107,22 @@ module Alexandria
|
|
107
107
|
|
108
108
|
# raise unless
|
109
109
|
md = /<li><span class="product_label">Editore:<\/span> <span class="product_text"><a href="[^>]+>([^<]+)/.match(data)
|
110
|
-
publisher = CGI.unescape(md[1].strip)
|
110
|
+
(publisher = CGI.unescape(md[1].strip)) || md
|
111
111
|
|
112
|
-
if (md = /<li><span class="product_label">Pagine:<\/span> <span class="product_text">([^<]+)/.match(data))
|
113
|
-
|
114
|
-
|
115
|
-
edition = nil
|
116
|
-
end
|
112
|
+
edition = if (md = /<li><span class="product_label">Pagine:<\/span> <span class="product_text">([^<]+)/.match(data))
|
113
|
+
CGI.unescape(md[1].strip) + ' p.'
|
114
|
+
end
|
117
115
|
|
118
116
|
publish_year = nil
|
119
117
|
if (md = /<li><span class="product_label">Data di Pubblicazione:<\/span> <span class="product_text">([^<]+)/.match(data))
|
120
118
|
publish_year = CGI.unescape(md[1].strip)[-4..-1].to_i
|
121
|
-
publish_year = nil if publish_year
|
119
|
+
publish_year = nil if publish_year.zero?
|
122
120
|
end
|
123
121
|
|
124
|
-
if data =~ /javascript:popImage/
|
122
|
+
if data =~ /javascript:popImage/ && (md = /<img border="0" alt="[^"]+" src="([^"]+)/.match(data))
|
125
123
|
cover_url = BASE_URI + md[1].strip
|
126
124
|
# use "p" instead of "g" for smaller image
|
127
|
-
if cover_url[-5] == 103
|
128
|
-
cover_url[-5] = 112
|
129
|
-
end
|
125
|
+
cover_url[-5] = 112 if cover_url[-5] == 103
|
130
126
|
|
131
127
|
cover_filename = isbn + '.tmp'
|
132
128
|
Dir.chdir(CACHE_DIR) do
|
@@ -158,7 +154,7 @@ module Alexandria
|
|
158
154
|
end
|
159
155
|
|
160
156
|
def clean_cache
|
161
|
-
# FIXME begin ... rescue ... end?
|
157
|
+
# FIXME: begin ... rescue ... end?
|
162
158
|
Dir.chdir(CACHE_DIR) do
|
163
159
|
Dir.glob('*.tmp') do |file|
|
164
160
|
puts 'removing ' + file if $DEBUG
|
@@ -37,8 +37,8 @@ module Alexandria
|
|
37
37
|
class WorldCatProvider < WebsiteBasedProvider
|
38
38
|
include Alexandria::Logging
|
39
39
|
|
40
|
-
SITE = 'http://www.worldcat.org'
|
41
|
-
BASE_SEARCH_URL = "#{SITE}/search?q=%s%s&qt=advanced" # type, term
|
40
|
+
SITE = 'http://www.worldcat.org'.freeze
|
41
|
+
BASE_SEARCH_URL = "#{SITE}/search?q=%s%s&qt=advanced".freeze # type, term
|
42
42
|
|
43
43
|
def initialize
|
44
44
|
super('WorldCat', 'WorldCat')
|
@@ -76,24 +76,22 @@ module Alexandria
|
|
76
76
|
private
|
77
77
|
|
78
78
|
def create_search_uri(search_type, search_term)
|
79
|
-
search_type_code = { SEARCH_BY_ISBN => 'isbn:',
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}[search_type] or ''
|
79
|
+
(search_type_code = { SEARCH_BY_ISBN => 'isbn:',
|
80
|
+
SEARCH_BY_AUTHORS => 'au:',
|
81
|
+
SEARCH_BY_TITLE => 'ti:',
|
82
|
+
SEARCH_BY_KEYWORD => '' }[search_type]) || ''
|
84
83
|
search_type_code = CGI.escape(search_type_code)
|
85
|
-
search_term_encoded =
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
84
|
+
search_term_encoded = if search_type == SEARCH_BY_ISBN
|
85
|
+
Library.canonicalise_ean(search_term) # isbn-13
|
86
|
+
else
|
87
|
+
CGI.escape(search_term)
|
88
|
+
end
|
91
89
|
BASE_SEARCH_URL % [search_type_code, search_term_encoded]
|
92
90
|
end
|
93
91
|
|
94
92
|
def get_book_from_search_result(result)
|
95
93
|
log.debug { "Fetching book from #{result[:url]}" }
|
96
|
-
html_data =
|
94
|
+
html_data = transport.get_response(URI.parse(result[:url]))
|
97
95
|
parse_result_data(html_data.body)
|
98
96
|
end
|
99
97
|
|
@@ -105,13 +103,11 @@ module Alexandria
|
|
105
103
|
# puts result_cells.length
|
106
104
|
result_cells.each do |td|
|
107
105
|
type_icon = (td % 'div.type/img.icn')
|
108
|
-
next unless type_icon
|
106
|
+
next unless type_icon && type_icon['src'] =~ /icon-bks/
|
109
107
|
name_div = td % 'div.name'
|
110
108
|
title = name_div.inner_text
|
111
109
|
anchor = name_div % :a
|
112
|
-
if anchor
|
113
|
-
url = anchor['href']
|
114
|
-
end
|
110
|
+
url = anchor['href'] if anchor
|
115
111
|
lookup_url = "#{SITE}#{url}"
|
116
112
|
result = {}
|
117
113
|
result[:title] = title
|
@@ -205,13 +201,13 @@ module Alexandria
|
|
205
201
|
if publisher_row
|
206
202
|
publication_info = (publisher_row / 'td').last.inner_text
|
207
203
|
|
208
|
-
if publication_info.index(';')
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
204
|
+
publication_info =~ if publication_info.index(';')
|
205
|
+
/;[\s]*([^\d]+)[\s]*[\d]*/
|
206
|
+
elsif publication_info.index(':')
|
207
|
+
/:[\s]*([^;:,]+)/
|
208
|
+
else
|
209
|
+
/([^;,]+)/
|
210
|
+
end
|
215
211
|
|
216
212
|
publisher = Regexp.last_match[1]
|
217
213
|
publication_info =~ /([12][0-9]{3})/
|