alexandria-book-collection-manager 0.7.1 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +9 -0
- data/.gitignore +5 -2
- data/.hound.yml +2 -0
- data/.rubocop.yml +113 -45
- data/.rubocop_todo.yml +82 -170
- data/.simplecov +5 -1
- data/.travis.yml +45 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +60 -0
- data/ChangeLog.0 +33 -35
- data/Gemfile +6 -5
- data/INSTALL.md +164 -0
- data/README.md +52 -42
- data/Rakefile +95 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +52 -45
- data/bin/alexandria +31 -53
- data/doc/AUTHORS +61 -0
- data/doc/BUGS +31 -0
- data/doc/FAQ +365 -0
- data/doc/HACKING +19 -0
- data/doc/NEWS +341 -0
- data/doc/alexandria.1 +120 -0
- data/doc/cuecat_support.rdoc +67 -0
- data/doc/dependency_decisions.yml +80 -0
- data/lib/alexandria.rb +29 -37
- data/lib/alexandria/about.rb +52 -51
- data/lib/alexandria/book_providers.rb +94 -101
- data/lib/alexandria/book_providers/adlibris.rb +45 -85
- data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
- data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
- data/lib/alexandria/book_providers/douban.rb +29 -51
- data/lib/alexandria/book_providers/proxis.rb +42 -59
- data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
- data/lib/alexandria/book_providers/siciliano.rb +68 -70
- data/lib/alexandria/book_providers/thalia.rb +46 -45
- data/lib/alexandria/book_providers/web.rb +17 -33
- data/lib/alexandria/book_providers/worldcat.rb +74 -102
- data/lib/alexandria/book_providers/z3950.rb +170 -174
- data/lib/alexandria/config.rb +5 -3
- data/lib/alexandria/console.rb +10 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +17 -15
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +188 -302
- data/lib/alexandria/import_library.rb +114 -155
- data/lib/alexandria/import_library_csv.rb +46 -96
- 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 +15 -19
- data/lib/alexandria/models/book.rb +15 -20
- data/lib/alexandria/models/library.rb +81 -363
- data/lib/alexandria/net.rb +7 -6
- data/lib/alexandria/preferences.rb +73 -91
- data/lib/alexandria/scanners.rb +4 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
- data/lib/alexandria/scanners/keyboard.rb +10 -8
- data/lib/alexandria/smart_library.rb +135 -171
- data/lib/alexandria/ui.rb +17 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
- 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} +18 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
- data/lib/alexandria/ui/builder_base.rb +9 -27
- data/lib/alexandria/ui/callbacks.rb +188 -186
- data/lib/alexandria/ui/columns.rb +2 -0
- data/lib/alexandria/ui/completion_models.rb +12 -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 +10 -8
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +139 -0
- data/lib/alexandria/ui/icons.rb +49 -65
- data/lib/alexandria/ui/iconview.rb +15 -13
- data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +23 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +18 -14
- data/lib/alexandria/ui/listview.rb +77 -88
- data/lib/alexandria/ui/main_app.rb +26 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
- 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} +62 -72
- 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/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +13 -13
- data/lib/alexandria/ui/ui_manager.rb +262 -283
- data/lib/alexandria/undo_manager.rb +3 -0
- data/lib/alexandria/version.rb +6 -19
- data/lib/alexandria/web_themes.rb +24 -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 +1020 -969
- 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 +77 -210
- data/spec/alexandria/book_spec.rb +16 -12
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +130 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +46 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +32 -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 +15 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +9 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +8 -33
- 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 +32 -0
- data/spec/alexandria/ui/sound_spec.rb +4 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
- data/spec/end_to_end/basic_run_spec.rb +57 -0
- data/spec/spec_helper.rb +66 -33
- data/tasks/setup.rb +5 -3
- data/tasks/spec.rake +18 -3
- data/util/rake/fileinstall.rb +38 -40
- data/util/rake/gettextgenerate.rb +15 -70
- data/util/rake/omfgenerate.rb +10 -10
- metadata +176 -60
- data/INSTALL.rdoc +0 -148
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/bol_it.rb +0 -160
- data/lib/alexandria/book_providers/deastore.rb +0 -273
- data/lib/alexandria/book_providers/ibs_it.rb +0 -147
- data/lib/alexandria/book_providers/mcu.rb +0 -169
- data/lib/alexandria/book_providers/renaud.rb +0 -140
- data/lib/alexandria/book_providers/webster_it.rb +0 -167
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
- 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 -85
- 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 -578
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
- data/spec/alexandria/ui/dialogs_spec.rb +0 -94
- data/spec/alexandria/ui/sidepane_spec.rb +0 -27
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
- data/spec/alexandria/utilities_spec.rb +0 -50
- data/tasks/dogtail.rake +0 -4
@@ -1,147 +0,0 @@
|
|
1
|
-
# Copyright (C) 2005-2006 Claudio Belotti
|
2
|
-
# Copyright (C) 2014, 2016 Matijs van Zuijlen
|
3
|
-
#
|
4
|
-
# Alexandria is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU General Public License as
|
6
|
-
# published by the Free Software Foundation; either version 2 of the
|
7
|
-
# License, or (at your option) any later version.
|
8
|
-
#
|
9
|
-
# Alexandria is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
-
# General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public
|
15
|
-
# License along with Alexandria; see the file COPYING. If not,
|
16
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
17
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
-
|
19
|
-
require 'fileutils'
|
20
|
-
require 'net/http'
|
21
|
-
require 'open-uri'
|
22
|
-
# require 'cgi'
|
23
|
-
|
24
|
-
module Alexandria
|
25
|
-
class BookProviders
|
26
|
-
class IBS_itProvider < GenericProvider
|
27
|
-
BASE_URI = 'http://www.internetbookshop.it'.freeze
|
28
|
-
CACHE_DIR = File.join(Alexandria::Library::DIR, '.ibs_it_cache')
|
29
|
-
REFERER = BASE_URI
|
30
|
-
def initialize
|
31
|
-
super('IBS_it', 'Internet Bookshop (Italy)')
|
32
|
-
FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR)
|
33
|
-
# no preferences for the moment
|
34
|
-
at_exit { clean_cache }
|
35
|
-
end
|
36
|
-
|
37
|
-
def search(criterion, type)
|
38
|
-
criterion = criterion.encode('ISO-8859-1')
|
39
|
-
req = BASE_URI + '/ser/'
|
40
|
-
req += case type
|
41
|
-
when SEARCH_BY_ISBN
|
42
|
-
'serdsp.asp?isbn='
|
43
|
-
|
44
|
-
when SEARCH_BY_TITLE
|
45
|
-
'serpge.asp?Type=keyword&T='
|
46
|
-
|
47
|
-
when SEARCH_BY_AUTHORS
|
48
|
-
'serpge.asp?Type=keyword&A='
|
49
|
-
|
50
|
-
when SEARCH_BY_KEYWORD
|
51
|
-
'serpge.asp?Type=keyword&S='
|
52
|
-
|
53
|
-
else
|
54
|
-
raise InvalidSearchTypeError
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
req += CGI.escape(criterion)
|
59
|
-
p req if $DEBUG
|
60
|
-
data = transport.get(URI.parse(req))
|
61
|
-
if type == SEARCH_BY_ISBN
|
62
|
-
to_book(data) # rescue raise NoResultsError
|
63
|
-
else
|
64
|
-
begin
|
65
|
-
results = []
|
66
|
-
each_book_page(data) do |code, _title|
|
67
|
-
results << to_book(transport.get(URI.parse('http://www.internetbookshop.it/ser/serdsp.asp?cc=' + code)))
|
68
|
-
end
|
69
|
-
return results
|
70
|
-
rescue
|
71
|
-
raise NoResultsError
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def url(book)
|
77
|
-
'http://www.internetbookshop.it/ser/serdsp.asp?isbn=' + book.isbn
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def to_book(data)
|
83
|
-
raise NoResultsError if data =~ /<b>Il libro che hai cercato non è presente nel nostro catalogo<\/b><br>/
|
84
|
-
data = data.encode('UTF-8')
|
85
|
-
|
86
|
-
md = />Titolo<\/td><td valign="top" class="lbarrasup">([^<]+)/.match(data)
|
87
|
-
raise 'No title' unless md
|
88
|
-
title = CGI.unescape(md[1].strip)
|
89
|
-
|
90
|
-
authors = []
|
91
|
-
if (md = /<b>Autore<\/b><\/td>.+<b>([^<]+)/.match(data))
|
92
|
-
md[0].strip.gsub(/<.*?>|Autore/m, ' ').split('; ').each { |a| authors << CGI.unescape(a.strip) }
|
93
|
-
end
|
94
|
-
|
95
|
-
md = /<input type=\"hidden\" name=\"isbn\" value=\"([^"]+)\">/i.match(data)
|
96
|
-
raise 'No ISBN' unless md
|
97
|
-
isbn = md[1].strip
|
98
|
-
|
99
|
-
# raise "No publisher" unless
|
100
|
-
md = /<b>Editore<\/b><\/td>.+<b>([^<]+)/.match(data)
|
101
|
-
(publisher = CGI.unescape(md[1].strip)) || md
|
102
|
-
|
103
|
-
# raise "No edition" unless
|
104
|
-
md = /Dati<\/b><\/td><td valign="top">([^<]+)/.match(data)
|
105
|
-
(edition = CGI.unescape(md[1].strip)) || md
|
106
|
-
|
107
|
-
publish_year = nil
|
108
|
-
if (md = /Anno<\/b><\/td><td valign="top">([^<]+)/.match(data))
|
109
|
-
publish_year = CGI.unescape(md[1].strip).to_i
|
110
|
-
publish_year = nil if publish_year.zero?
|
111
|
-
end
|
112
|
-
|
113
|
-
md = /src="http:\/\/giotto.ibs.it\/cop\/copt13.asp\?f=(\d+)">/.match(data)
|
114
|
-
cover_url = 'http://giotto.ibs.it/cop/copt13.asp?f=' + md[1] # use copa13.asp, copt13.asp, copj13.asp, for small, medium, big image
|
115
|
-
cover_filename = isbn + '.tmp'
|
116
|
-
Dir.chdir(CACHE_DIR) do
|
117
|
-
File.open(cover_filename, 'w') do |file|
|
118
|
-
file.write open(cover_url, 'Referer' => REFERER).read
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
medium_cover = CACHE_DIR + '/' + cover_filename
|
123
|
-
if File.size(medium_cover) > 0 && (File.size(medium_cover) != 1822) # 1822 is the size of the fake image "copertina non disponibile"
|
124
|
-
puts medium_cover + ' has non-0 size' if $DEBUG
|
125
|
-
return [Book.new(title, authors, isbn, publisher, publish_year, edition), medium_cover]
|
126
|
-
end
|
127
|
-
puts medium_cover + ' has 0 size, removing ...' if $DEBUG
|
128
|
-
File.delete(medium_cover)
|
129
|
-
[Book.new(title, authors, isbn, publisher, publish_year, edition)]
|
130
|
-
end
|
131
|
-
|
132
|
-
def each_book_page(data)
|
133
|
-
raise if data.scan(/<a href="http:\/\/www.internetbookshop.it\/ser\/serdsp.asp\?shop=1&cc=([\w\d]+)"><b>([^<]+)/) { |a| yield a }.empty?
|
134
|
-
end
|
135
|
-
|
136
|
-
def clean_cache
|
137
|
-
# FIXME: begin ... rescue ... end?
|
138
|
-
Dir.chdir(CACHE_DIR) do
|
139
|
-
Dir.glob('*.tmp') do |file|
|
140
|
-
puts 'removing ' + file if $DEBUG
|
141
|
-
File.delete(file)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,169 +0,0 @@
|
|
1
|
-
# Copyright (C) 2004 Javier Fernandez-Sanguino
|
2
|
-
# Copyright (C) 2007 Javier Fernandez-Sanguino and Marco Costantini
|
3
|
-
# Copyright (C) 2011, 2016 Matijs van Zuijlen
|
4
|
-
#
|
5
|
-
# Alexandria is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU General Public License as
|
7
|
-
# published by the Free Software Foundation; either version 2 of the
|
8
|
-
# License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# Alexandria is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU General Public
|
16
|
-
# License along with Alexandria; see the file COPYING. If not,
|
17
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
18
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
19
|
-
|
20
|
-
require 'cgi'
|
21
|
-
require 'net/http'
|
22
|
-
|
23
|
-
# http://www.mcu.es/libro/CE/AgenciaISBN/BBDDLibros/Sobre.html
|
24
|
-
# http://www.mcu.es/comun/bases/isbn/ISBN.html
|
25
|
-
|
26
|
-
module Alexandria
|
27
|
-
class BookProviders
|
28
|
-
class MCUProvider < GenericProvider
|
29
|
-
include Logging
|
30
|
-
include GetText
|
31
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
32
|
-
|
33
|
-
LANGUAGES = {
|
34
|
-
'es' => '1'
|
35
|
-
}.freeze
|
36
|
-
|
37
|
-
# BASE_URI = "http://www.mcu.es/cgi-bin/BRSCGI3701?"
|
38
|
-
BASE_URI = 'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?'.freeze
|
39
|
-
def initialize
|
40
|
-
super('MCU', _('Spanish Culture Ministry'))
|
41
|
-
# No preferences
|
42
|
-
prefs.read
|
43
|
-
end
|
44
|
-
|
45
|
-
def search(criterion, type)
|
46
|
-
prefs.read
|
47
|
-
criterion = criterion.encode('ISO-8859-1') # still needed??
|
48
|
-
print "Doing search with MCU #{criterion}, type: #{type}\n" if $DEBUG # for DEBUGing
|
49
|
-
req = BASE_URI + 'CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1-1000&SEPARADOR=&'
|
50
|
-
req += case type
|
51
|
-
when SEARCH_BY_ISBN
|
52
|
-
"WGEN-C=&WISB-C=#{CGI.escape(criterion)}&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
|
53
|
-
|
54
|
-
when SEARCH_BY_TITLE
|
55
|
-
"WGEN-C=&WISB-C=&WAUT-C=&WTIT-C=#{CGI.escape(criterion)}&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
|
56
|
-
|
57
|
-
when SEARCH_BY_AUTHORS
|
58
|
-
"WGEN-C=&WISB-C=&WAUT-C=#{CGI.escape(criterion)}&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
|
59
|
-
|
60
|
-
when SEARCH_BY_KEYWORD
|
61
|
-
"WGEN-C=#{CGI.escape(criterion)}&WISB-C=&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
|
62
|
-
|
63
|
-
else
|
64
|
-
raise InvalidSearchTypeError
|
65
|
-
end
|
66
|
-
products = {}
|
67
|
-
print "Request page is #{req}\n" if $DEBUG # for DEBUGing
|
68
|
-
transport.get(URI.parse(req)).each do |line|
|
69
|
-
print "Reading line: #{line}" if $DEBUG # for DEBUGing
|
70
|
-
if (line =~ /CMD=VERDOC.*&DOCN=([^&]*)&NDOC=([^&]*)/) && (!products[Regexp.last_match[1]]) && (book = parseBook(Regexp.last_match[1], Regexp.last_match[2]))
|
71
|
-
products[Regexp.last_match[1]] = book
|
72
|
-
puts Regexp.last_match[1] if $DEBUG # for DEBUGing
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
raise NoResultsError if products.values.empty?
|
77
|
-
type == SEARCH_BY_ISBN ? products.values.first : products.values
|
78
|
-
end
|
79
|
-
|
80
|
-
def url(book)
|
81
|
-
isbn = Library.canonicalise_isbn(book.isbn)
|
82
|
-
"http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1&SEPARADOR=&WGEN-C=&WISB-C=#{isbn}&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
|
83
|
-
rescue => ex
|
84
|
-
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def parseBook(docn, ndoc)
|
91
|
-
detailspage = 'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERDOC&CONF=AEISPA.cnf&BASE=ISBN&DOCN=' + docn + '&NDOC=' + ndoc
|
92
|
-
print "Looking at detailspage: #{detailspage}\n" if $DEBUG # for DEBUGing
|
93
|
-
product = {}
|
94
|
-
product['authors'] = []
|
95
|
-
robotstate = 0
|
96
|
-
transport.get(URI.parse(detailspage)).each do |line|
|
97
|
-
# This is a very crude robot interpreter
|
98
|
-
# Note that the server provides more information
|
99
|
-
# we don't store:
|
100
|
-
# - Language - Description
|
101
|
-
# - Binding - Price
|
102
|
-
# - Colection - Theme
|
103
|
-
# - CDU - Last update
|
104
|
-
|
105
|
-
# There seems to be an issue with accented chars..
|
106
|
-
line = line.encode('UTF-8')
|
107
|
-
print "Reading line (robotstate #{robotstate}): #{line}" if $DEBUG # for DEBUGing
|
108
|
-
if line =~ /^<\/td>$/ || line =~ /^<\/tr>$/
|
109
|
-
robotstate = 0
|
110
|
-
elsif (robotstate == 1) && line =~ /^([^<]+)</
|
111
|
-
author = Regexp.last_match[1].gsub(' ', ' ').sub(/ +$/, '')
|
112
|
-
if author.length > 3
|
113
|
-
# Only add authors of appropiate length
|
114
|
-
product['authors'] << author
|
115
|
-
print "Authors are #{product['authors']}\n" if $DEBUG # for DEBUGing
|
116
|
-
robotstate = 0
|
117
|
-
end
|
118
|
-
elsif (robotstate == 2) && line =~ /^(.*)$/ # The title es the next line to title declaration and has not tags on web src code
|
119
|
-
product['name'] = Regexp.last_match[1].strip
|
120
|
-
print "Name is #{product['name']}\n" if $DEBUG # for DEBUGing
|
121
|
-
robotstate = 0
|
122
|
-
elsif (robotstate == 3) && line =~ /^([0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]).*/
|
123
|
-
product['isbn'] = Regexp.last_match[1]
|
124
|
-
print "ISBN is #{product['isbn']}\n" if $DEBUG # for DEBUGing
|
125
|
-
robotstate = 0
|
126
|
-
elsif (robotstate == 4) && line =~ /^([^<]+)</
|
127
|
-
product['manufacturer'] = Regexp.last_match[1].strip
|
128
|
-
print "Manufacturer is #{product['manufacturer']}\n" if $DEBUG # for DEBUGing
|
129
|
-
robotstate = 0
|
130
|
-
# elsif robotstate == 5 and line =~ /^([^<]+)</
|
131
|
-
elsif (robotstate == 5) && line =~ /<span>([^<]+)</
|
132
|
-
product['media'] = Regexp.last_match[1].strip
|
133
|
-
print "Media is #{product['media']}\n" if $DEBUG # for DEBUGing
|
134
|
-
robotstate = 0
|
135
|
-
elsif line =~ /^.*>Autor:\s*</
|
136
|
-
robotstate = 1
|
137
|
-
elsif line =~ /^.*>T(.|í)tulo:\s*</
|
138
|
-
robotstate = 2
|
139
|
-
elsif line =~ /^.*>ISBN \(13\):\s*</
|
140
|
-
robotstate = 3
|
141
|
-
elsif line =~ /^.*>Publicaci(.|ó)n:\s*</
|
142
|
-
robotstate = 4
|
143
|
-
elsif line =~ /^.*>Encuadernaci(.|ó)n:\s*</
|
144
|
-
robotstate = 5
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# TODO: This provider does not include picture for books
|
149
|
-
# %w{name isbn media manufacturer}.each do |field|
|
150
|
-
# print "Checking #{field} for nil\n" if $DEBUG # for DEBUGing
|
151
|
-
# product[field]="" if product[field].nil?
|
152
|
-
# end
|
153
|
-
|
154
|
-
print "Creating new book\n" if $DEBUG # for DEBUGing
|
155
|
-
book = Book.new(product['name'],
|
156
|
-
product['authors'],
|
157
|
-
product['isbn'].delete('-'),
|
158
|
-
product['manufacturer'],
|
159
|
-
nil, # TODO: furnish publish year
|
160
|
-
product['media'])
|
161
|
-
if book.title.nil?
|
162
|
-
log.warn { "No title was returned for #{book.isbn}" }
|
163
|
-
book.title = ''
|
164
|
-
end
|
165
|
-
[book]
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# Copyright (C) 2005-2006-2006 Mathieu Leduc-Hamel
|
2
|
-
#
|
3
|
-
# Alexandria is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU General Public License as
|
5
|
-
# published by the Free Software Foundation; either version 2 of the
|
6
|
-
# License, or (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Alexandria is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
-
# General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU General Public
|
14
|
-
# License along with Alexandria; see the file COPYING. If not,
|
15
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
16
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
17
|
-
|
18
|
-
# http://en.wikipedia.org/wiki/Renaud-Bray
|
19
|
-
|
20
|
-
require 'net/http'
|
21
|
-
require 'cgi'
|
22
|
-
|
23
|
-
module Alexandria
|
24
|
-
class BookProviders
|
25
|
-
class RENAUDProvider < GenericProvider
|
26
|
-
include GetText
|
27
|
-
# GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
|
28
|
-
BASE_URI = 'http://www.renaud-bray.com/'.freeze
|
29
|
-
ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'.freeze
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
super('RENAUD', 'Renaud-Bray (Canada)')
|
33
|
-
end
|
34
|
-
|
35
|
-
def search(criterion, type)
|
36
|
-
criterion = criterion.encode('ISO-8859-1')
|
37
|
-
req = BASE_URI + 'francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri='
|
38
|
-
# req = BASE_URI + "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri="
|
39
|
-
req += case type
|
40
|
-
when SEARCH_BY_ISBN
|
41
|
-
'ISBN'
|
42
|
-
when SEARCH_BY_TITLE
|
43
|
-
'Titre'
|
44
|
-
when SEARCH_BY_AUTHORS
|
45
|
-
'Auteur'
|
46
|
-
when SEARCH_BY_KEYWORD
|
47
|
-
''
|
48
|
-
else
|
49
|
-
raise InvalidSearchTypeError
|
50
|
-
end
|
51
|
-
req += '&Phrase='
|
52
|
-
|
53
|
-
req += CGI.escape(criterion)
|
54
|
-
p req if $DEBUG
|
55
|
-
data = transport.get(URI.parse(req))
|
56
|
-
begin
|
57
|
-
if type == SEARCH_BY_ISBN
|
58
|
-
return to_books(data).pop
|
59
|
-
else
|
60
|
-
results = []
|
61
|
-
to_books(data).each { |book|
|
62
|
-
results << book
|
63
|
-
}
|
64
|
-
while /Suivant/ =~ data
|
65
|
-
md = /Enteterouge\">([\d]*)<\/b>/.match(data)
|
66
|
-
num = md[1].to_i + 1
|
67
|
-
data = transport.get(URI.parse(req + '&PageActuelle=' + num.to_s))
|
68
|
-
to_books(data).each { |book|
|
69
|
-
results << book
|
70
|
-
}
|
71
|
-
end
|
72
|
-
return results
|
73
|
-
end
|
74
|
-
rescue
|
75
|
-
raise NoResultsError
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def url(book)
|
80
|
-
# "http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=" + book.isbn
|
81
|
-
'http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=' + book.isbn
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def to_books(data)
|
87
|
-
data = CGI.unescapeHTML(data)
|
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
|
-
|
91
|
-
titles = []
|
92
|
-
data.scan(/"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/).each { |md|
|
93
|
-
titles << md[1].strip
|
94
|
-
}
|
95
|
-
raise if titles.empty?
|
96
|
-
authors = []
|
97
|
-
data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each { |md|
|
98
|
-
authors2 = []
|
99
|
-
for author in md[0].split(' ')
|
100
|
-
authors2 << author.strip
|
101
|
-
end
|
102
|
-
authors << authors2
|
103
|
-
}
|
104
|
-
raise if authors.empty?
|
105
|
-
isbns = []
|
106
|
-
data.scan(/ISBN : ?<\/td><td>(\d+)/).each { |md|
|
107
|
-
isbns << md[0].strip
|
108
|
-
}
|
109
|
-
raise if isbns.empty?
|
110
|
-
editions = []
|
111
|
-
publish_years = []
|
112
|
-
data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each { |md|
|
113
|
-
editions << md[0].strip
|
114
|
-
publish_years << md[0].strip.split(/-/)[0].to_i
|
115
|
-
}
|
116
|
-
raise if editions.empty? || publish_years.empty?
|
117
|
-
publishers = []
|
118
|
-
data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each { |md|
|
119
|
-
publishers << md[0].strip
|
120
|
-
}
|
121
|
-
raise if publishers.empty?
|
122
|
-
book_covers = []
|
123
|
-
data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))|\/francais\/suggestion\/images\/livre\/livre.gif)/).each { |md|
|
124
|
-
book_covers << BASE_URI + md[0].strip
|
125
|
-
}
|
126
|
-
raise if book_covers.empty?
|
127
|
-
|
128
|
-
books = []
|
129
|
-
titles.each_with_index { |title, i|
|
130
|
-
books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
|
131
|
-
book_covers[i]]
|
132
|
-
# print books
|
133
|
-
}
|
134
|
-
raise if books.empty?
|
135
|
-
|
136
|
-
books
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|