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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby -*-
|
2
4
|
#
|
3
5
|
# Copyright (C) 2009 Cathal Mc Ginley
|
@@ -26,35 +28,36 @@
|
|
26
28
|
|
27
29
|
# NOTE: this modified version is based on the Alexandria WorldCat provider.
|
28
30
|
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
31
|
+
require "cgi"
|
32
|
+
require "alexandria/net"
|
33
|
+
require "alexandria/book_providers/web"
|
32
34
|
|
33
35
|
module Alexandria
|
34
36
|
class BookProviders
|
35
37
|
class BarnesAndNobleProvider < WebsiteBasedProvider
|
36
|
-
include
|
38
|
+
include Logging
|
37
39
|
|
38
|
-
SITE =
|
40
|
+
SITE = "http://www.barnesandnoble.com"
|
39
41
|
|
40
|
-
BASE_ISBN_SEARCH_URL =
|
42
|
+
BASE_ISBN_SEARCH_URL = "http://www.barnesandnoble.com/s/%s"
|
41
43
|
|
42
|
-
BASE_SEARCH_URL =
|
43
|
-
|
44
|
+
BASE_SEARCH_URL = "http://search.barnesandnoble.com/booksearch" \
|
45
|
+
"/results.asp?%s=%s" # type, term
|
44
46
|
|
45
47
|
def initialize
|
46
|
-
super(
|
48
|
+
super("BarnesAndNoble", "BarnesAndNoble")
|
47
49
|
@agent = nil
|
48
50
|
prefs.read
|
49
51
|
end
|
50
52
|
|
51
53
|
def agent
|
52
|
-
@agent
|
54
|
+
@agent ||= Alexandria::WWWAgent.new
|
53
55
|
@agent
|
54
56
|
end
|
55
57
|
|
56
58
|
def fetch_redirectly(uri_str, limit = 5)
|
57
|
-
raise NoResultsError,
|
59
|
+
raise NoResultsError, _("HTTP redirect too deep") if limit.zero?
|
60
|
+
|
58
61
|
if limit < 10
|
59
62
|
sleep 0.1
|
60
63
|
log.debug { "Redirectly :: #{uri_str}" }
|
@@ -64,12 +67,10 @@ module Alexandria
|
|
64
67
|
response = agent.get(uri_str)
|
65
68
|
log.debug { response.inspect }
|
66
69
|
case response
|
67
|
-
when Net::HTTPSuccess
|
68
|
-
when Net::HTTPRedirection
|
69
|
-
redirect = URI.parse response[
|
70
|
-
if redirect.relative?
|
71
|
-
redirect = URI.parse(uri_str) + redirect
|
72
|
-
end
|
70
|
+
when Net::HTTPSuccess then response
|
71
|
+
when Net::HTTPRedirection
|
72
|
+
redirect = URI.parse response["Location"]
|
73
|
+
redirect = URI.parse(uri_str) + redirect if redirect.relative?
|
73
74
|
fetch_redirectly(redirect.to_s, (limit - 1))
|
74
75
|
else
|
75
76
|
response.error!
|
@@ -78,7 +79,7 @@ module Alexandria
|
|
78
79
|
|
79
80
|
def search(criterion, type)
|
80
81
|
req = create_search_uri(type, criterion)
|
81
|
-
|
82
|
+
log.debug { "Requesting #{req}" }
|
82
83
|
html_data = fetch_redirectly(req)
|
83
84
|
|
84
85
|
if type == SEARCH_BY_ISBN
|
@@ -93,22 +94,22 @@ module Alexandria
|
|
93
94
|
|
94
95
|
def url(book)
|
95
96
|
create_search_uri(SEARCH_BY_ISBN, book.isbn)
|
96
|
-
rescue => ex
|
97
|
+
rescue StandardError => ex
|
97
98
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
98
99
|
nil
|
99
100
|
end
|
100
101
|
|
101
102
|
def create_search_uri(search_type, search_term)
|
102
103
|
(search_type_code = {
|
103
|
-
SEARCH_BY_AUTHORS =>
|
104
|
-
SEARCH_BY_TITLE
|
105
|
-
SEARCH_BY_KEYWORD =>
|
106
|
-
}[search_type]) ||
|
104
|
+
SEARCH_BY_AUTHORS => "ATH",
|
105
|
+
SEARCH_BY_TITLE => "TTL",
|
106
|
+
SEARCH_BY_KEYWORD => "WRD" # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
|
107
|
+
}[search_type]) || ""
|
107
108
|
if search_type == SEARCH_BY_ISBN
|
108
109
|
BASE_ISBN_SEARCH_URL % Library.canonicalise_ean(search_term) # isbn-13
|
109
110
|
else
|
110
111
|
search_term_encoded = CGI.escape(search_term)
|
111
|
-
BASE_SEARCH_URL
|
112
|
+
format(BASE_SEARCH_URL, search_type_code, search_term_encoded)
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -127,19 +128,19 @@ module Alexandria
|
|
127
128
|
result = {}
|
128
129
|
# img = div % 'div.book-image/a/img'
|
129
130
|
# result[:image_url] = img['src'] if img
|
130
|
-
title_header = div %
|
131
|
-
title_links = title_header /
|
131
|
+
title_header = div % "h2"
|
132
|
+
title_links = title_header / "a"
|
132
133
|
result[:title] = title_links.first.inner_text
|
133
|
-
result[:url] = title_links.first[
|
134
|
+
result[:url] = title_links.first["href"]
|
134
135
|
|
135
136
|
book_search_results << result
|
136
137
|
end
|
137
|
-
rescue => ex
|
138
|
+
rescue StandardError => ex
|
138
139
|
trace = ex.backtrace.join("\n> ")
|
139
|
-
log.warn
|
140
|
-
|
140
|
+
log.warn do
|
141
|
+
"Failed parsing search results for Barnes & Noble " \
|
141
142
|
"#{ex.message} #{trace}"
|
142
|
-
|
143
|
+
end
|
143
144
|
end
|
144
145
|
book_search_results
|
145
146
|
end
|
@@ -149,8 +150,8 @@ module Alexandria
|
|
149
150
|
begin
|
150
151
|
book_data = {}
|
151
152
|
|
152
|
-
dl = (doc /
|
153
|
-
dts = dl.children_of_type(
|
153
|
+
dl = (doc / "dl").first
|
154
|
+
dts = dl.children_of_type("dt")
|
154
155
|
dts.each do |dt|
|
155
156
|
value = dt.next_sibling.inner_text
|
156
157
|
case dt.inner_text
|
@@ -165,44 +166,44 @@ module Alexandria
|
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
168
|
-
meta = doc /
|
169
|
+
meta = doc / "meta"
|
169
170
|
meta.each do |it|
|
170
171
|
attrs = it.attributes
|
171
|
-
property = attrs[
|
172
|
+
property = attrs["property"]
|
172
173
|
next unless property
|
174
|
+
|
173
175
|
case property
|
174
|
-
when
|
175
|
-
book_data[:title] = attrs[
|
176
|
-
when
|
177
|
-
book_data[:image_url] = attrs[
|
176
|
+
when "og:title"
|
177
|
+
book_data[:title] = attrs["content"]
|
178
|
+
when "og:image"
|
179
|
+
book_data[:image_url] = attrs["content"]
|
178
180
|
end
|
179
181
|
end
|
180
182
|
|
181
|
-
author_links = doc /
|
183
|
+
author_links = doc / "span.contributors a"
|
182
184
|
authors = author_links.map(&:inner_text)
|
183
185
|
book_data[:authors] = authors
|
184
186
|
|
185
|
-
book_data[:binding] =
|
186
|
-
selected_format = (doc /
|
187
|
-
if selected_format
|
188
|
-
book_data[:binding] = selected_format.inner_text
|
189
|
-
end
|
187
|
+
book_data[:binding] = ""
|
188
|
+
selected_format = (doc / "#availableFormats li.selected a.tabTitle").first
|
189
|
+
book_data[:binding] = selected_format.inner_text if selected_format
|
190
190
|
|
191
191
|
book = Book.new(book_data[:title], book_data[:authors],
|
192
192
|
book_data[:isbn], book_data[:publisher],
|
193
193
|
book_data[:publication_year],
|
194
194
|
book_data[:binding])
|
195
|
-
|
196
|
-
rescue => ex
|
195
|
+
[book, book_data[:image_url]]
|
196
|
+
rescue StandardError => ex
|
197
197
|
raise ex if ex.instance_of? NoResultsError
|
198
|
+
|
198
199
|
trace = ex.backtrace.join("\n> ")
|
199
|
-
log.warn
|
200
|
-
|
200
|
+
log.warn do
|
201
|
+
"Failed parsing search results for BarnesAndNoble " \
|
201
202
|
"#{ex.message} #{trace}"
|
202
|
-
|
203
|
+
end
|
203
204
|
raise NoResultsError
|
204
205
|
end
|
205
206
|
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -1,42 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (C) 2010 Sun Ning
|
5
|
-
#
|
6
|
-
# Alexandria is free software; you can redistribute it and/or
|
7
|
-
# modify it under the terms of the GNU General Public License as
|
8
|
-
# published by the Free Software Foundation; either version 2 of the
|
9
|
-
# License, or (at your option) any later version.
|
10
|
-
#
|
11
|
-
# Alexandria is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
-
# General Public License for more details.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
15
4
|
#
|
16
|
-
#
|
17
|
-
# License along with Alexandria; see the file COPYING. If not,
|
18
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
19
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
20
6
|
|
21
7
|
# http://book.douban.com/
|
22
8
|
# Douban.com book repository, provides many Chinese books.
|
23
9
|
|
24
10
|
# Author: Sun Ning <classicning@gmail.com>, http://sunng.info/
|
25
11
|
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
12
|
+
require "cgi"
|
13
|
+
require "alexandria/net"
|
14
|
+
require "yaml"
|
29
15
|
|
30
16
|
module Alexandria
|
31
17
|
class BookProviders
|
32
18
|
class DoubanProvider < GenericProvider
|
33
|
-
include
|
19
|
+
include Logging
|
34
20
|
|
35
|
-
SITE =
|
36
|
-
BASE_URL =
|
21
|
+
SITE = "http://www.douban.com"
|
22
|
+
BASE_URL = "http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json"
|
37
23
|
|
38
24
|
def initialize
|
39
|
-
super(
|
25
|
+
super("Douban", "Douban (China)")
|
40
26
|
prefs.read
|
41
27
|
end
|
42
28
|
|
@@ -54,9 +40,9 @@ module Alexandria
|
|
54
40
|
raise NoResultsError if results.empty?
|
55
41
|
|
56
42
|
if type == SEARCH_BY_ISBN
|
57
|
-
|
43
|
+
results.first
|
58
44
|
else
|
59
|
-
|
45
|
+
results
|
60
46
|
end
|
61
47
|
end
|
62
48
|
|
@@ -72,10 +58,10 @@ module Alexandria
|
|
72
58
|
def json2yaml(json)
|
73
59
|
# insert spaces after : and , except within strings
|
74
60
|
# i.e. when followed by numeral, quote, { or [
|
75
|
-
yaml = json.gsub(/(
|
61
|
+
yaml = json.gsub(/(:|,)([0-9'"{\[])/) do |_match|
|
76
62
|
"#{Regexp.last_match[1]} #{Regexp.last_match[2]}"
|
77
63
|
end
|
78
|
-
yaml.gsub!(
|
64
|
+
yaml.gsub!(%r{\\/}, "/") # unescape forward slashes
|
79
65
|
yaml
|
80
66
|
end
|
81
67
|
|
@@ -85,43 +71,35 @@ module Alexandria
|
|
85
71
|
book_search_results = []
|
86
72
|
begin
|
87
73
|
# dbresult = JSON.parse(response)
|
88
|
-
dbresult = YAML.
|
74
|
+
dbresult = YAML.safe_load(json2yaml(response))
|
89
75
|
# File.open(",douban.yaml", "wb") {|f| f.write(json2yaml(response)) }
|
90
|
-
if dbresult[
|
91
|
-
|
92
|
-
name = item[
|
76
|
+
if dbresult["opensearch:totalResults"]["$t"].to_i > 0
|
77
|
+
dbresult["entry"].each do |item|
|
78
|
+
name = item["title"]["$t"]
|
93
79
|
isbn = nil
|
94
80
|
publisher = nil
|
95
81
|
pubdate = nil
|
96
82
|
binding = nil
|
97
|
-
|
98
|
-
isbn = av[
|
99
|
-
if av[
|
100
|
-
|
101
|
-
|
102
|
-
if av['@name'] == 'pubdate'
|
103
|
-
pubdate = av['$t']
|
104
|
-
end
|
105
|
-
if av['@name'] == 'binding'
|
106
|
-
binding = av['$t']
|
107
|
-
end
|
83
|
+
item["db:attribute"].each do |av|
|
84
|
+
isbn = av["$t"] if av["@name"] == "isbn13"
|
85
|
+
publisher = av["$t"] if av["@name"] == "publisher"
|
86
|
+
pubdate = av["$t"] if av["@name"] == "pubdate"
|
87
|
+
binding = av["$t"] if av["@name"] == "binding"
|
108
88
|
end
|
109
|
-
authors = if item[
|
110
|
-
item[
|
89
|
+
authors = if item["author"]
|
90
|
+
item["author"].map { |a| a["name"]["$t"] }
|
111
91
|
else
|
112
92
|
[]
|
113
93
|
end
|
114
94
|
image_url = nil
|
115
|
-
|
116
|
-
if av[
|
117
|
-
image_url = av['@href']
|
118
|
-
end
|
95
|
+
item["link"].each do |av|
|
96
|
+
image_url = av["@href"] if av["@rel"] == "image"
|
119
97
|
end
|
120
98
|
book = Book.new(name, authors, isbn, publisher, pubdate, binding)
|
121
99
|
book_search_results << [book, image_url]
|
122
100
|
end
|
123
101
|
end
|
124
|
-
rescue => ex
|
102
|
+
rescue StandardError => ex
|
125
103
|
log.warn(ex.backtrace.join('\n'))
|
126
104
|
end
|
127
105
|
book_search_results
|
@@ -1,32 +1,20 @@
|
|
1
|
-
#
|
2
|
-
|
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.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
13
4
|
#
|
14
|
-
#
|
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.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
18
6
|
|
19
7
|
# New Proxis provider, taken from Palatina MetaDataSource and modified
|
20
8
|
# for Alexandria. (20 Dec 2009)
|
21
9
|
|
22
|
-
require
|
23
|
-
require
|
10
|
+
require "cgi"
|
11
|
+
require "alexandria/book_providers/web"
|
24
12
|
|
25
13
|
module Alexandria
|
26
14
|
class BookProviders
|
27
15
|
class ProxisProvider < WebsiteBasedProvider
|
28
16
|
# include GetText
|
29
|
-
include
|
17
|
+
include Logging
|
30
18
|
# GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
|
31
19
|
|
32
20
|
# Proxis essentially has three book databases, NL, FR and EN.
|
@@ -34,14 +22,14 @@ module Alexandria
|
|
34
22
|
# it adds most to Alexandria (Amazon already has French and
|
35
23
|
# English titles).
|
36
24
|
|
37
|
-
SITE =
|
25
|
+
SITE = "http://www.proxis.nl"
|
38
26
|
BASE_SEARCH_URL = "#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
|
39
|
-
|
27
|
+
"&shop=100001NL&SelRubricLevel1Id=100001NL"
|
40
28
|
ISBN_REDIRECT_BASE_URL = "#{SITE}/NLNL/Search/Index.aspx?search=%s" \
|
41
|
-
|
29
|
+
"&shop=100001NL&SelRubricLevel1Id=100001NL"
|
42
30
|
|
43
31
|
def initialize
|
44
|
-
super(
|
32
|
+
super("Proxis", "Proxis (Belgium)")
|
45
33
|
# prefs.add("lang", _("Language"), "fr",
|
46
34
|
# LANGUAGES.keys)
|
47
35
|
prefs.read
|
@@ -49,11 +37,12 @@ module Alexandria
|
|
49
37
|
|
50
38
|
def search(criterion, type)
|
51
39
|
req = create_search_uri(type, criterion)
|
52
|
-
|
40
|
+
log.debug { req }
|
53
41
|
html_data = transport.get_response(URI.parse(req))
|
54
42
|
|
55
43
|
results = parse_search_result_data(html_data.body)
|
56
44
|
raise NoResultsError if results.empty?
|
45
|
+
|
57
46
|
if type == SEARCH_BY_ISBN
|
58
47
|
get_book_from_search_result(results.first)
|
59
48
|
else
|
@@ -85,32 +74,29 @@ module Alexandria
|
|
85
74
|
def text_of(node)
|
86
75
|
if node.nil?
|
87
76
|
nil
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
node_text.strip.squeeze(' ')
|
97
|
-
end
|
77
|
+
elsif node.text?
|
78
|
+
node.to_html
|
79
|
+
elsif node.elem?
|
80
|
+
if node.children.nil?
|
81
|
+
nil
|
82
|
+
else
|
83
|
+
node_text = node.children.map { |n| text_of(n) }.join
|
84
|
+
node_text.strip.squeeze(" ")
|
98
85
|
end
|
99
|
-
# node.inner_html.strip
|
100
86
|
end
|
101
87
|
end
|
102
88
|
|
103
89
|
def parse_search_result_data(html)
|
104
90
|
doc = html_to_doc(html)
|
105
91
|
book_search_results = []
|
106
|
-
items = doc.search(
|
92
|
+
items = doc.search("table.searchResult tr")
|
107
93
|
items.each do |item|
|
108
94
|
result = {}
|
109
|
-
title_link = item %
|
95
|
+
title_link = item % "h5 a"
|
110
96
|
if title_link
|
111
97
|
result[:title] = text_of(title_link)
|
112
|
-
result[:lookup_url] = title_link[
|
113
|
-
unless result[:lookup_url]
|
98
|
+
result[:lookup_url] = title_link["href"]
|
99
|
+
unless result[:lookup_url].start_with?("http")
|
114
100
|
result[:lookup_url] = "#{SITE}#{result[:lookup_url]}"
|
115
101
|
end
|
116
102
|
end
|
@@ -122,9 +108,9 @@ module Alexandria
|
|
122
108
|
book_search_results
|
123
109
|
end
|
124
110
|
|
125
|
-
def data_for_header(
|
126
|
-
tr =
|
127
|
-
td = tr.at(
|
111
|
+
def data_for_header(header)
|
112
|
+
tr = header.parent
|
113
|
+
td = tr.at("td")
|
128
114
|
text_of(td) if td
|
129
115
|
end
|
130
116
|
|
@@ -133,23 +119,19 @@ module Alexandria
|
|
133
119
|
book_data = {}
|
134
120
|
book_data[:authors] = []
|
135
121
|
# TITLE
|
136
|
-
if (title_header = doc.search(
|
137
|
-
header_spans = title_header.first.search(
|
122
|
+
if (title_header = doc.search("div.detailBlock h3"))
|
123
|
+
header_spans = title_header.first.search("span")
|
138
124
|
title = text_of(header_spans.first)
|
139
|
-
if title =~ /(.+)-$/
|
140
|
-
title = Regexp.last_match[1].strip
|
141
|
-
end
|
125
|
+
title = Regexp.last_match[1].strip if title =~ /(.+)-$/
|
142
126
|
book_data[:title] = title
|
143
127
|
end
|
144
128
|
|
145
|
-
info_headers = doc.search(
|
129
|
+
info_headers = doc.search("table.productInfoTable th")
|
146
130
|
|
147
131
|
isbns = []
|
148
132
|
unless info_headers.empty?
|
149
133
|
info_headers.each do |th|
|
150
|
-
|
151
|
-
isbns << data_for_header(th)
|
152
|
-
end
|
134
|
+
isbns << data_for_header(th) if /(ISBN|EAN)/.match?(th.inner_text)
|
153
135
|
end
|
154
136
|
book_data[:isbn] = Library.canonicalise_ean(isbns.first)
|
155
137
|
end
|
@@ -159,15 +141,16 @@ module Alexandria
|
|
159
141
|
unless info_headers.empty?
|
160
142
|
info_headers.each do |th|
|
161
143
|
header_text = th.inner_text
|
162
|
-
|
144
|
+
case header_text
|
145
|
+
when /Type/
|
163
146
|
book_data[:binding] = data_for_header(th)
|
164
|
-
|
147
|
+
when /Verschijningsdatum/
|
165
148
|
date = data_for_header(th)
|
166
|
-
date =~
|
149
|
+
date =~ %r{/(\d{4})}
|
167
150
|
book_data[:publish_year] = Regexp.last_match[1].to_i
|
168
|
-
|
151
|
+
when /Auteur/
|
169
152
|
book_data[:authors] << data_for_header(th)
|
170
|
-
|
153
|
+
when /Uitgever/
|
171
154
|
book_data[:publisher] = data_for_header(th)
|
172
155
|
end
|
173
156
|
end
|
@@ -175,12 +158,12 @@ module Alexandria
|
|
175
158
|
|
176
159
|
image_url = nil
|
177
160
|
if (cover_img = doc.at("img[@id$='imgProduct']"))
|
178
|
-
image_url = if cover_img[
|
179
|
-
cover_img[
|
161
|
+
image_url = if cover_img["src"].start_with?("http")
|
162
|
+
cover_img["src"]
|
180
163
|
else
|
181
164
|
"#{SITE}/#{cover_img['src']}" # TODO: use html <base>
|
182
165
|
end
|
183
|
-
image_url = nil if
|
166
|
+
image_url = nil if /ProductNoCover/.match?(image_url)
|
184
167
|
end
|
185
168
|
|
186
169
|
book = Book.new(book_data[:title], book_data[:authors],
|