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
@@ -1,69 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
|
5
|
-
# Copyright (C) 2014, 2016 Matijs van Zuijlen
|
3
|
+
# This file is part of Alexandria.
|
6
4
|
#
|
7
|
-
#
|
8
|
-
# modify it under the terms of the GNU General Public License as
|
9
|
-
# published by the Free Software Foundation; either version 2 of the
|
10
|
-
# License, or (at your option) any later version.
|
11
|
-
#
|
12
|
-
# Alexandria is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
-
# General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public
|
18
|
-
# License along with Alexandria; see the file COPYING. If not,
|
19
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
20
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
21
6
|
|
22
7
|
## $Z3950_DEBUG = $DEBUG
|
23
8
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
9
|
+
require "zoom"
|
10
|
+
require "alexandria/book_providers/pseudomarc"
|
11
|
+
require "marc"
|
27
12
|
|
28
13
|
module Alexandria
|
29
14
|
class BookProviders
|
30
15
|
class Z3950Provider < AbstractProvider
|
31
16
|
include Logging
|
32
17
|
include GetText
|
33
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
18
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
34
19
|
|
35
|
-
def initialize(name =
|
20
|
+
def initialize(name = "Z3950", fullname = "Z39.50")
|
36
21
|
super
|
37
|
-
prefs.add(
|
38
|
-
prefs.add(
|
39
|
-
prefs.add(
|
40
|
-
prefs.add(
|
41
|
-
|
42
|
-
prefs.add(
|
43
|
-
prefs.add(
|
22
|
+
prefs.add("hostname", _("Hostname"), "")
|
23
|
+
prefs.add("port", _("Port"), 7090)
|
24
|
+
prefs.add("database", _("Database"), "")
|
25
|
+
prefs.add("record_syntax", _("Record syntax"), "USMARC",
|
26
|
+
["USMARC", "UNIMARC", "SUTRS"])
|
27
|
+
prefs.add("username", _("Username"), "", nil, false)
|
28
|
+
prefs.add("password", _("Password"), "", nil, false)
|
29
|
+
prefs.add("charset", _("Charset encoding"), "ISO-8859-1")
|
44
30
|
|
45
31
|
# HACK : piggybacking support
|
46
|
-
prefs.add(
|
32
|
+
prefs.add("piggyback", "Piggyback", true, [true, false])
|
47
33
|
prefs.read
|
48
34
|
end
|
49
35
|
|
50
36
|
def search(criterion, type)
|
51
37
|
prefs.read
|
52
|
-
criterion = criterion.encode(prefs[
|
53
|
-
|
54
|
-
# We only decode MARC at the moment.
|
55
|
-
# SUTRS needs to be decoded separately, because each Z39.50 server has a
|
56
|
-
# different one.
|
57
|
-
raise NoResultsError unless marc?
|
38
|
+
criterion = criterion.encode(prefs["charset"])
|
58
39
|
|
59
40
|
isbn = type == SEARCH_BY_ISBN ? criterion : nil
|
60
|
-
criterion =
|
61
|
-
conn_count = type
|
41
|
+
criterion = canonicalise_criterion(criterion, type)
|
42
|
+
conn_count = request_count(type)
|
62
43
|
resultset = search_records(criterion, type, conn_count)
|
63
44
|
log.debug { "total #{resultset.length}" }
|
64
|
-
raise NoResultsError if resultset.length == 0
|
65
45
|
|
66
|
-
results =
|
46
|
+
results = books_from_resultset(resultset, isbn)
|
47
|
+
raise NoResultsError if results.empty?
|
48
|
+
|
67
49
|
type == SEARCH_BY_ISBN ? results.first : results
|
68
50
|
end
|
69
51
|
|
@@ -71,9 +53,35 @@ module Alexandria
|
|
71
53
|
nil
|
72
54
|
end
|
73
55
|
|
56
|
+
def books_from_resultset(resultset, isbn)
|
57
|
+
case prefs["record_syntax"]
|
58
|
+
when /MARC$/
|
59
|
+
books_from_marc(resultset, isbn)
|
60
|
+
when "SUTRS"
|
61
|
+
books_from_sutrs(resultset)
|
62
|
+
else
|
63
|
+
raise NoResultsError
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
74
67
|
private
|
75
68
|
|
76
|
-
def
|
69
|
+
def request_count(type)
|
70
|
+
type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
71
|
+
end
|
72
|
+
|
73
|
+
def canonicalise_criterion(criterion, type)
|
74
|
+
criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
|
75
|
+
criterion
|
76
|
+
end
|
77
|
+
|
78
|
+
def books_from_sutrs(_resultset)
|
79
|
+
# SUTRS needs to be decoded separately, because each Z39.50 server has a
|
80
|
+
# different one.
|
81
|
+
raise NoResultsError
|
82
|
+
end
|
83
|
+
|
84
|
+
def marc_to_book(marc_txt, isbn)
|
77
85
|
begin
|
78
86
|
marc = MARC::Record.new_from_marc(marc_txt, forgiving: true)
|
79
87
|
rescue StandardError => ex
|
@@ -81,15 +89,15 @@ module Alexandria
|
|
81
89
|
log.error { ex.backtrace.join("> \n") }
|
82
90
|
begin
|
83
91
|
marc = MARC::Record.new(marc_txt)
|
84
|
-
rescue StandardError =>
|
85
|
-
log.error {
|
86
|
-
log.error {
|
87
|
-
raise
|
92
|
+
rescue StandardError => ex
|
93
|
+
log.error { ex.message }
|
94
|
+
log.error { ex.backtrace.join("> \n") }
|
95
|
+
raise ex
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
91
|
-
log.debug
|
92
|
-
msg =
|
99
|
+
log.debug do
|
100
|
+
msg = "Parsing MARC"
|
93
101
|
msg += "\n title: #{marc.title}"
|
94
102
|
msg += "\n authors: #{marc.authors.join(', ')}"
|
95
103
|
msg += "\n isbn: #{marc.isbn}, #{isbn}"
|
@@ -97,41 +105,42 @@ module Alexandria
|
|
97
105
|
msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
|
98
106
|
msg += "\n edition: #{marc.edition}"
|
99
107
|
msg
|
100
|
-
|
108
|
+
end
|
101
109
|
|
102
110
|
return if marc.title.nil? # or marc.authors.empty?
|
103
111
|
|
104
|
-
|
112
|
+
isbn ||= marc.isbn
|
105
113
|
isbn = Library.canonicalise_ean(isbn)
|
106
114
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
book
|
115
|
+
Book.new(marc.title, marc.authors,
|
116
|
+
isbn,
|
117
|
+
(marc.publisher || ""),
|
118
|
+
marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
|
119
|
+
(marc.edition || ""))
|
113
120
|
end
|
114
121
|
|
115
|
-
def books_from_marc(resultset,
|
122
|
+
def books_from_marc(resultset, isbn)
|
116
123
|
results = []
|
117
124
|
resultset[0..9].each do |record|
|
118
|
-
marc_txt = record.render(prefs[
|
125
|
+
marc_txt = record.render(prefs["charset"], "UTF-8")
|
119
126
|
log.debug { marc_txt }
|
120
127
|
if $DEBUG
|
121
|
-
File.open(
|
128
|
+
File.open(",marc.txt", "wb") do |f| # DEBUG
|
122
129
|
f.write(marc_txt)
|
123
130
|
end
|
124
131
|
end
|
125
132
|
book = nil
|
126
133
|
begin
|
127
134
|
mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
|
128
|
-
|
135
|
+
if prefs["hostname"] == "z3950.bnf.fr"
|
136
|
+
mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS
|
137
|
+
end
|
129
138
|
# try pseudo-marc parser first (it seems to have more luck)
|
130
139
|
book = Alexandria::PseudoMarcParser.marc_text_to_book(marc_txt,
|
131
140
|
mappings)
|
132
141
|
if book.nil?
|
133
142
|
# failing that, try the genuine MARC parser
|
134
|
-
book = marc_to_book(marc_txt)
|
143
|
+
book = marc_to_book(marc_txt, isbn)
|
135
144
|
end
|
136
145
|
rescue StandardError => ex
|
137
146
|
log.warn { ex }
|
@@ -144,26 +153,23 @@ module Alexandria
|
|
144
153
|
end
|
145
154
|
|
146
155
|
def marc?
|
147
|
-
|
156
|
+
prefs["record_syntax"].end_with?("MARC")
|
148
157
|
end
|
149
158
|
|
150
159
|
def search_records(criterion, type, conn_count)
|
151
160
|
options = {}
|
152
|
-
unless prefs[
|
153
|
-
options[
|
154
|
-
options[
|
161
|
+
unless prefs["username"].empty? || prefs["password"].empty?
|
162
|
+
options["user"] = prefs["username"]
|
163
|
+
options["password"] = prefs["password"]
|
155
164
|
end
|
156
|
-
hostname = prefs[
|
157
|
-
port = prefs[
|
165
|
+
hostname = prefs["hostname"]
|
166
|
+
port = prefs["port"].to_i
|
158
167
|
log.debug { "hostname #{hostname} port #{port} options #{options}" }
|
159
168
|
conn = ZOOM::Connection.new(options).connect(hostname, port)
|
160
|
-
conn.database_name = prefs[
|
169
|
+
conn.database_name = prefs["database"]
|
161
170
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
conn.preferred_record_syntax = prefs['record_syntax']
|
166
|
-
conn.element_set_name = 'F'
|
171
|
+
conn.preferred_record_syntax = prefs["record_syntax"]
|
172
|
+
conn.element_set_name = "F"
|
167
173
|
conn.count = conn_count
|
168
174
|
attr = case type
|
169
175
|
when SEARCH_BY_ISBN then [7]
|
@@ -171,33 +177,27 @@ module Alexandria
|
|
171
177
|
when SEARCH_BY_AUTHORS then [1, 1003]
|
172
178
|
when SEARCH_BY_KEYWORD then [1016]
|
173
179
|
end
|
174
|
-
pqf =
|
180
|
+
pqf = ""
|
175
181
|
attr.each { |att| pqf += "@attr 1=#{att} " }
|
176
182
|
pqf += '"' + criterion.upcase + '"'
|
177
183
|
log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
|
178
184
|
|
179
185
|
begin
|
180
|
-
if prefs.variable_named(
|
181
|
-
|
182
|
-
|
183
|
-
conn.piggyback = false
|
184
|
-
end
|
186
|
+
if prefs.variable_named("piggyback") && !prefs["piggyback"]
|
187
|
+
log.debug { "setting conn.piggyback to false" }
|
188
|
+
conn.piggyback = false
|
185
189
|
end
|
186
190
|
conn.search(pqf)
|
187
191
|
rescue StandardError => ex
|
188
|
-
if /1005
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
# hopefully these precautions will prevent infinite loops here
|
195
|
-
else
|
196
|
-
raise ex
|
197
|
-
end
|
198
|
-
else
|
199
|
-
raise ex
|
192
|
+
if /1005/.match?(ex.message) &&
|
193
|
+
prefs.variable_named("piggyback") && prefs["piggyback"]
|
194
|
+
log.error { "Z39.50 search failed:: #{ex.message}" }
|
195
|
+
log.info { "Turning off piggybacking for this provider" }
|
196
|
+
prefs.variable_named("piggyback").new_value = false
|
197
|
+
retry
|
200
198
|
end
|
199
|
+
|
200
|
+
raise ex
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
@@ -207,21 +207,22 @@ module Alexandria
|
|
207
207
|
unabstract
|
208
208
|
|
209
209
|
include GetText
|
210
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
210
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
211
211
|
|
212
212
|
def initialize
|
213
|
-
super(
|
214
|
-
prefs.variable_named(
|
215
|
-
prefs.variable_named(
|
216
|
-
prefs.variable_named(
|
217
|
-
prefs.variable_named(
|
218
|
-
prefs.variable_named(
|
213
|
+
super("LOC", _("Library of Congress (Usa)"))
|
214
|
+
prefs.variable_named("hostname").default_value = "z3950.loc.gov"
|
215
|
+
prefs.variable_named("port").default_value = 7090
|
216
|
+
prefs.variable_named("database").default_value = "Voyager"
|
217
|
+
prefs.variable_named("record_syntax").default_value = "USMARC"
|
218
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
219
219
|
prefs.read
|
220
220
|
end
|
221
221
|
|
222
222
|
def url(book)
|
223
|
-
|
224
|
-
|
223
|
+
isbn = Library.canonicalise_isbn(book.isbn)
|
224
|
+
"http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?" \
|
225
|
+
"DB=local&CNT=25+records+per+page&CMD=isbn+#{isbn}"
|
225
226
|
rescue StandardError => ex
|
226
227
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
227
228
|
nil
|
@@ -242,34 +243,20 @@ module Alexandria
|
|
242
243
|
unabstract
|
243
244
|
|
244
245
|
include GetText
|
245
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
246
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
246
247
|
|
247
248
|
def initialize
|
248
|
-
super(
|
249
|
-
prefs.variable_named(
|
250
|
-
prefs.variable_named(
|
251
|
-
prefs.variable_named(
|
252
|
-
prefs.variable_named(
|
253
|
-
prefs.variable_named(
|
254
|
-
prefs.read
|
255
|
-
end
|
256
|
-
|
257
|
-
def search(criterion, type)
|
258
|
-
return super unless prefs['record_syntax'] == 'SUTRS'
|
259
|
-
|
249
|
+
super("BL", _("British Library"))
|
250
|
+
prefs.variable_named("hostname").default_value = "z3950cat.bl.uk"
|
251
|
+
prefs.variable_named("port").default_value = 9909
|
252
|
+
prefs.variable_named("database").default_value = "BLAC"
|
253
|
+
prefs.variable_named("record_syntax").default_value = "SUTRS"
|
254
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
260
255
|
prefs.read
|
261
|
-
criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
|
262
|
-
conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
263
|
-
resultset = search_records(criterion, type, conn_count)
|
264
|
-
log.debug { "total #{resultset.length}" }
|
265
|
-
raise NoResultsError if resultset.length == 0
|
266
|
-
|
267
|
-
results = books_from_sutrs(resultset)
|
268
|
-
type == SEARCH_BY_ISBN ? results.first : results
|
269
256
|
end
|
270
257
|
|
271
258
|
def url(book)
|
272
|
-
|
259
|
+
"http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn)
|
273
260
|
rescue StandardError => ex
|
274
261
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
275
262
|
nil
|
@@ -280,7 +267,7 @@ module Alexandria
|
|
280
267
|
def books_from_sutrs(resultset)
|
281
268
|
results = []
|
282
269
|
resultset[0..9].each do |record|
|
283
|
-
text = record.render(prefs[
|
270
|
+
text = record.render(prefs["charset"], "UTF-8")
|
284
271
|
# File.open(',bl.marc', 'wb') {|f| f.write(text) }
|
285
272
|
log.debug { text }
|
286
273
|
|
@@ -289,27 +276,27 @@ module Alexandria
|
|
289
276
|
|
290
277
|
text.split(/\n/).each do |line|
|
291
278
|
if (md = /^Title:\s+(.*)$/.match(line))
|
292
|
-
title = md[1].sub(/\.$/,
|
279
|
+
title = md[1].sub(/\.$/, "").squeeze(" ")
|
293
280
|
elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
|
294
281
|
authors << md[1]
|
295
282
|
elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
|
296
283
|
authors << md[1]
|
297
284
|
elsif (md = /^ISBN:\s+([\dXx]+)/.match(line))
|
298
285
|
isbn = Library.canonicalise_ean(md[1])
|
299
|
-
elsif (md = /^Imprint
|
286
|
+
elsif (md = /^Imprint:.+:\s*(.+),/.match(line))
|
300
287
|
publisher = md[1]
|
301
288
|
end
|
302
289
|
end
|
303
290
|
|
304
|
-
log.debug
|
305
|
-
msg =
|
291
|
+
log.debug do
|
292
|
+
msg = "Parsing SUTRS"
|
306
293
|
msg += "\n title: #{title}"
|
307
294
|
msg += "\n authors: #{authors.join(' and ')}"
|
308
295
|
msg += "\n isbn: #{isbn}"
|
309
296
|
msg += "\n publisher: #{publisher}"
|
310
297
|
msg += "\n edition: #{edition}"
|
311
298
|
msg
|
312
|
-
|
299
|
+
end
|
313
300
|
|
314
301
|
if title # and !authors.empty?
|
315
302
|
book = Book.new(title, authors, isbn, (publisher || nil),
|
@@ -327,41 +314,29 @@ module Alexandria
|
|
327
314
|
unabstract
|
328
315
|
|
329
316
|
include GetText
|
330
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
317
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
331
318
|
|
332
319
|
def initialize
|
333
|
-
super(
|
334
|
-
prefs.variable_named(
|
335
|
-
prefs.variable_named(
|
336
|
-
prefs.variable_named(
|
320
|
+
super("SBN", "Servizio Bibliotecario Nazionale (Italy)")
|
321
|
+
prefs.variable_named("hostname").default_value = "opac.sbn.it"
|
322
|
+
prefs.variable_named("port").default_value = 3950
|
323
|
+
prefs.variable_named("database").default_value = "nopac"
|
337
324
|
# supported 'USMARC', 'UNIMARC' , 'SUTRS'
|
338
|
-
prefs.variable_named(
|
339
|
-
prefs.variable_named(
|
325
|
+
prefs.variable_named("record_syntax").default_value = "USMARC"
|
326
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
340
327
|
prefs.read
|
341
328
|
end
|
342
329
|
|
343
|
-
def search(criterion, type)
|
344
|
-
prefs.read
|
345
|
-
|
346
|
-
isbn = type == SEARCH_BY_ISBN ? criterion : nil
|
347
|
-
criterion = canonicalise_isbn_with_dashes(criterion)
|
348
|
-
resultset = search_records(criterion, type, 0)
|
349
|
-
log.debug { "total #{resultset.length}" }
|
350
|
-
raise NoResultsError if resultset.length == 0
|
351
|
-
|
352
|
-
results = books_from_marc(resultset, isbn)
|
353
|
-
type == SEARCH_BY_ISBN ? results.first : results
|
354
|
-
end
|
355
|
-
|
356
330
|
def url(book)
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
331
|
+
"http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=" \
|
332
|
+
"%253CB%253E%253Cfont%2520color%253D%2523000064%253E" \
|
333
|
+
"Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520" \
|
334
|
+
"contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E" +
|
361
335
|
canonicalise_isbn_with_dashes(book.isbn) +
|
362
|
-
|
336
|
+
"%253C%2FFONT%253E%2522&session=&zurl=opac" \
|
337
|
+
"&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22" +
|
363
338
|
canonicalise_isbn_with_dashes(book.isbn) +
|
364
|
-
|
339
|
+
"%22%29&language=it&maxentries=10&target=0&position=1"
|
365
340
|
rescue StandardError => ex
|
366
341
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
367
342
|
nil
|
@@ -369,32 +344,40 @@ module Alexandria
|
|
369
344
|
|
370
345
|
private
|
371
346
|
|
347
|
+
def canonicalise_criterion(criterion, _type)
|
348
|
+
canonicalise_isbn_with_dashes(criterion)
|
349
|
+
end
|
350
|
+
|
351
|
+
def request_count(_type)
|
352
|
+
0
|
353
|
+
end
|
354
|
+
|
372
355
|
def canonicalise_isbn_with_dashes(isbn)
|
373
356
|
# The reference for the position of the dashes is
|
374
357
|
# http://www.isbn-international.org/converter/ranges.htm
|
375
358
|
|
376
359
|
isbn = Alexandria::Library.canonicalise_isbn(isbn)
|
377
360
|
|
378
|
-
if isbn[0..1] ==
|
361
|
+
if isbn[0..1] == "88"
|
379
362
|
# Italian speaking area
|
380
|
-
if isbn >
|
381
|
-
|
382
|
-
elsif isbn >
|
383
|
-
|
384
|
-
elsif isbn >
|
385
|
-
|
386
|
-
elsif isbn >
|
387
|
-
|
388
|
-
elsif isbn >
|
389
|
-
|
390
|
-
elsif isbn >
|
391
|
-
|
363
|
+
if isbn > "8895000" && (isbn <= "8899999996")
|
364
|
+
isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
|
365
|
+
elsif isbn > "88900000"
|
366
|
+
isbn[0..1] + "-" + isbn[2..7] + "-" + isbn[8..8] + "-" + isbn[9..9]
|
367
|
+
elsif isbn > "8885000"
|
368
|
+
isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
|
369
|
+
elsif isbn > "886000"
|
370
|
+
isbn[0..1] + "-" + isbn[2..5] + "-" + isbn[6..8] + "-" + isbn[9..9]
|
371
|
+
elsif isbn > "88200"
|
372
|
+
isbn[0..1] + "-" + isbn[2..4] + "-" + isbn[5..8] + "-" + isbn[9..9]
|
373
|
+
elsif isbn > "8800"
|
374
|
+
isbn[0..1] + "-" + isbn[2..3] + "-" + isbn[4..8] + "-" + isbn[9..9]
|
392
375
|
else
|
393
|
-
raise
|
376
|
+
raise _("Invalid ISBN")
|
394
377
|
end
|
395
378
|
|
396
379
|
else
|
397
|
-
|
380
|
+
isbn
|
398
381
|
end
|
399
382
|
end
|
400
383
|
#
|
@@ -408,7 +391,8 @@ module Alexandria
|
|
408
391
|
#
|
409
392
|
# Dashes:
|
410
393
|
# this database requires that Italian books are searched with dashes :(
|
411
|
-
# However, they have also books with dashes in wrong positions, for
|
394
|
+
# However, they have also books with dashes in wrong positions, for
|
395
|
+
# instance 88-061-4934-2
|
412
396
|
#
|
413
397
|
# References:
|
414
398
|
# http://opac.internetculturale.it/cgi-bin/main.cgi?type=field
|