alexandria-book-collection-manager 0.7.2 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ruby.yml +77 -0
- data/.gitignore +5 -1
- data/.hound.yml +2 -0
- data/.rubocop.yml +87 -37
- data/.rubocop_todo.yml +62 -191
- data/.simplecov +5 -2
- data/CHANGELOG.md +63 -0
- data/Gemfile +4 -3
- data/INSTALL.md +26 -14
- data/README.md +52 -42
- data/Rakefile +93 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +50 -43
- data/bin/alexandria +30 -53
- data/doc/FAQ +2 -6
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +27 -37
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +90 -97
- data/lib/alexandria/book_providers/adlibris.rb +41 -76
- data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
- data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
- data/lib/alexandria/book_providers/douban.rb +26 -42
- data/lib/alexandria/book_providers/proxis.rb +44 -55
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +64 -65
- data/lib/alexandria/book_providers/thalia.rb +42 -41
- data/lib/alexandria/book_providers/web.rb +15 -33
- data/lib/alexandria/book_providers/worldcat.rb +70 -97
- data/lib/alexandria/book_providers/z3950.rb +160 -173
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +8 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +15 -13
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +193 -300
- data/lib/alexandria/import_library.rb +108 -141
- data/lib/alexandria/import_library_csv.rb +43 -46
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +11 -13
- data/lib/alexandria/models/book.rb +13 -20
- data/lib/alexandria/models/library.rb +81 -353
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +73 -87
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +133 -170
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
- data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
- data/lib/alexandria/ui/builder_base.rb +7 -27
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +189 -183
- data/lib/alexandria/ui/completion_models.rb +10 -23
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +7 -7
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +142 -0
- data/lib/alexandria/ui/icons.rb +47 -63
- data/lib/alexandria/ui/iconview.rb +12 -10
- data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +21 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +16 -14
- data/lib/alexandria/ui/listview.rb +73 -87
- data/lib/alexandria/ui/main_app.rb +24 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +11 -13
- data/lib/alexandria/ui/ui_manager.rb +236 -251
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +22 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1017 -974
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +75 -171
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +128 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +44 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +30 -25
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +7 -34
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
- data/spec/end_to_end/basic_run_spec.rb +52 -0
- data/spec/spec_helper.rb +65 -33
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +16 -3
- data/util/rake/fileinstall.rb +39 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +178 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
- data/lib/alexandria/book_providers/renaud.rb +0 -149
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -96
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
- data/tasks/dogtail.rake +0 -6
@@ -1,40 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright (C) 2010 Cathal Mc Ginley
|
5
|
-
# Copyright (C) 2014,2015 Matijs van Zuijlen
|
3
|
+
# This file is part of Alexandria.
|
6
4
|
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
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.
|
21
|
-
require 'gettext'
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
require "gettext"
|
8
|
+
require "tmpdir"
|
22
9
|
|
23
10
|
module Alexandria
|
24
11
|
class ImportFilter
|
25
12
|
attr_reader :name, :patterns, :message
|
26
13
|
|
14
|
+
include Logging
|
27
15
|
include GetText
|
28
16
|
extend GetText
|
29
|
-
bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
17
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
30
18
|
|
31
19
|
def self.all
|
32
20
|
[
|
33
|
-
new(_(
|
34
|
-
new(_(
|
35
|
-
[
|
36
|
-
new(_(
|
37
|
-
new(_(
|
21
|
+
new(_("Autodetect"), ["*"], :import_autodetect),
|
22
|
+
new(_("Archived Tellico XML (*.bc, *.tc)"),
|
23
|
+
["*.tc", "*.bc"], :import_as_tellico_xml_archive),
|
24
|
+
new(_("ISBN List (*.txt)"), ["*.txt"], :import_as_isbn_list),
|
25
|
+
new(_("GoodReads CSV"), ["*.csv"], :import_as_csv_file)
|
38
26
|
]
|
39
27
|
end
|
40
28
|
|
@@ -47,7 +35,7 @@ module Alexandria
|
|
47
35
|
end
|
48
36
|
|
49
37
|
def invoke(library_name, filename)
|
50
|
-
|
38
|
+
log.debug { "Selected: #{@message} -- #{library_name} -- #{filename}" }
|
51
39
|
Library.send(@message, library_name, filename,
|
52
40
|
@on_iterate_cb, @on_error_cb)
|
53
41
|
end
|
@@ -63,119 +51,100 @@ module Alexandria
|
|
63
51
|
|
64
52
|
class Library
|
65
53
|
def self.import_autodetect(*args)
|
66
|
-
|
54
|
+
log.debug { args.inspect }
|
67
55
|
filename = args[1]
|
68
|
-
|
69
|
-
|
70
|
-
if filename[-4..-1] ==
|
56
|
+
log.debug { "Filename is #{filename} and ext is #{filename[-4..-1]}" }
|
57
|
+
log.debug { "Beginning import: #{args[0]}, #{args[1]}" }
|
58
|
+
if filename[-4..-1] == ".txt"
|
71
59
|
import_as_isbn_list(*args)
|
72
|
-
elsif [
|
73
|
-
|
74
|
-
|
75
|
-
rescue => e
|
76
|
-
puts e.message
|
77
|
-
puts e.backtrace.join("\n>> ")
|
78
|
-
end
|
79
|
-
elsif ['.csv'].include? filename[-4..-1]
|
60
|
+
elsif [".tc", ".bc"].include? filename[-3..-1]
|
61
|
+
import_as_tellico_xml_archive(*args)
|
62
|
+
elsif [".csv"].include? filename[-4..-1]
|
80
63
|
import_as_csv_file(*args)
|
81
64
|
else
|
82
|
-
|
83
|
-
raise 'Not supported type'
|
65
|
+
raise _("Unsupported type")
|
84
66
|
end
|
85
67
|
end
|
86
68
|
|
87
69
|
def self.import_as_tellico_xml_archive(name, filename,
|
88
70
|
on_iterate_cb, _on_error_cb)
|
89
|
-
|
71
|
+
log.debug { "Starting import_as_tellico_xml_archive... " }
|
90
72
|
return nil unless system("unzip -qqt \"#{filename}\"")
|
91
|
-
|
73
|
+
|
74
|
+
tmpdir = File.join(Dir.tmpdir, "tellico_export")
|
92
75
|
FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
|
93
76
|
Dir.mkdir(tmpdir)
|
94
77
|
Dir.chdir(tmpdir) do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
raise unless xml.root.elements.size == 1
|
102
|
-
collection = xml.root.elements[1]
|
103
|
-
raise unless collection.name == 'collection'
|
104
|
-
type = collection.attribute('type').value.to_i
|
105
|
-
raise unless (type == 2) || (type == 5)
|
106
|
-
|
107
|
-
content = []
|
108
|
-
entries = collection.elements.to_a('entry')
|
109
|
-
(total = entries.size).times do |n|
|
110
|
-
entry = entries[n]
|
111
|
-
elements = entry.elements
|
112
|
-
# Feed an array in here, tomorrow.
|
113
|
-
keys = ['isbn', 'publisher', 'pub_year', 'binding']
|
114
|
-
|
115
|
-
book_elements = [neaten(elements['title'].text)]
|
116
|
-
book_elements += if !elements['authors'].nil?
|
117
|
-
[elements['authors'].elements.to_a.map \
|
118
|
-
{ |x| neaten(x.text) }]
|
119
|
-
else
|
120
|
-
[[]]
|
121
|
-
end
|
122
|
-
book_elements += keys.map { |key|
|
123
|
-
neaten(elements[key].text) if elements[key]
|
124
|
-
}
|
125
|
-
# isbn
|
126
|
-
if book_elements[2].nil? || book_elements[2].strip.empty?
|
127
|
-
book_elements[2] = nil
|
128
|
-
else
|
129
|
-
begin
|
130
|
-
book_elements[2] = book_elements[2].strip
|
131
|
-
book_elements[2] = Library.canonicalise_ean(book_elements[2])
|
132
|
-
rescue => ex
|
133
|
-
puts book_elements[2]
|
134
|
-
puts ex.message
|
135
|
-
puts ex.backtrace.join("\n> ")
|
136
|
-
raise ex
|
137
|
-
end
|
138
|
-
end
|
139
|
-
book_elements[4] = book_elements[4].to_i unless book_elements[4].nil? # publishing_year
|
140
|
-
puts book_elements.inspect
|
141
|
-
cover = (neaten(elements['cover'].text) if elements['cover'])
|
142
|
-
puts cover
|
143
|
-
book = Book.new(*book_elements)
|
144
|
-
if elements['rating'] && Book::VALID_RATINGS.member?(elements['rating'].text.to_i)
|
145
|
-
book.rating = elements['rating'].text.to_i
|
146
|
-
end
|
147
|
-
book.notes = neaten(elements['comments'].text) if elements['comments']
|
148
|
-
content << [book, cover]
|
149
|
-
on_iterate_cb&.call(n + 1, total)
|
150
|
-
end
|
78
|
+
system("unzip -qq \"#{filename}\"")
|
79
|
+
file = File.exist?("bookcase.xml") ? "bookcase.xml" : "tellico.xml"
|
80
|
+
xml = REXML::Document.new(File.open(file))
|
81
|
+
raise unless ["bookcase", "tellico"].include? xml.root.name
|
82
|
+
# FIXME: handle multiple collections
|
83
|
+
raise unless xml.root.elements.size == 1
|
151
84
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
85
|
+
collection = xml.root.elements[1]
|
86
|
+
raise unless collection.name == "collection"
|
87
|
+
|
88
|
+
type = collection.attribute("type").value.to_i
|
89
|
+
raise unless (type == 2) || (type == 5)
|
90
|
+
|
91
|
+
content = []
|
92
|
+
entries = collection.elements.to_a("entry")
|
93
|
+
(total = entries.size).times do |n|
|
94
|
+
entry = entries[n]
|
95
|
+
elements = entry.elements
|
96
|
+
# Feed an array in here, tomorrow.
|
97
|
+
keys = ["isbn", "publisher", "pub_year", "binding"]
|
98
|
+
|
99
|
+
book_elements = [neaten(elements["title"].text)]
|
100
|
+
book_elements += if !elements["authors"].nil?
|
101
|
+
[elements["authors"].elements.to_a.map \
|
102
|
+
{ |x| neaten(x.text) }]
|
103
|
+
else
|
104
|
+
[[]]
|
105
|
+
end
|
106
|
+
book_elements += keys.map do |key|
|
107
|
+
neaten(elements[key].text) if elements[key]
|
161
108
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
109
|
+
book_elements[2] = Library.canonicalise_ean(book_elements[2])
|
110
|
+
# publishing_year
|
111
|
+
book_elements[4] = book_elements[4].to_i unless book_elements[4].nil?
|
112
|
+
log.debug { book_elements.inspect }
|
113
|
+
cover = (neaten(elements["cover"].text) if elements["cover"])
|
114
|
+
log.debug { cover }
|
115
|
+
book = Book.new(*book_elements)
|
116
|
+
if elements["rating"]
|
117
|
+
rating = elements["rating"].text.to_i
|
118
|
+
book.rating = rating if Book::VALID_RATINGS.member? rating
|
119
|
+
end
|
120
|
+
book.notes = neaten(elements["comments"].text) if elements["comments"]
|
121
|
+
content << [book, cover]
|
122
|
+
on_iterate_cb&.call(n + 1, total)
|
123
|
+
end
|
124
|
+
|
125
|
+
# TODO: Pass in library store as an argument
|
126
|
+
library = LibraryCollection.instance.library_store.load_library name
|
127
|
+
content.each do |book, cover|
|
128
|
+
library.save_cover(book, File.join(Dir.pwd, "images", cover)) unless cover.nil?
|
129
|
+
library << book
|
130
|
+
library.save(book)
|
166
131
|
end
|
132
|
+
return [library, []]
|
133
|
+
rescue StandardError => ex
|
134
|
+
log.info { ex.message }
|
135
|
+
return nil
|
167
136
|
end
|
168
137
|
end
|
169
138
|
|
170
139
|
def self.import_as_csv_file(name, filename, on_iterate_cb, _on_error_cb)
|
171
|
-
require
|
140
|
+
require "alexandria/import_library_csv"
|
172
141
|
books_and_covers = []
|
173
142
|
line_count = IO.readlines(filename).reduce(0) { |count, _line| count + 1 }
|
174
143
|
|
175
144
|
import_count = 0
|
176
145
|
max_import = line_count - 1
|
177
146
|
|
178
|
-
reader = CSV.open(filename,
|
147
|
+
reader = CSV.open(filename, "r")
|
179
148
|
# Goodreads & LibraryThing now use csv header lines
|
180
149
|
header = reader.shift
|
181
150
|
importer = identify_csv_type(header)
|
@@ -187,7 +156,7 @@ module Alexandria
|
|
187
156
|
if book.isbn
|
188
157
|
# if we can search by ISBN, try to grab the cover
|
189
158
|
begin
|
190
|
-
dl_book, dl_cover =
|
159
|
+
dl_book, dl_cover = BookProviders.isbn_search(book.isbn)
|
191
160
|
if dl_book.authors.size > book.authors.size
|
192
161
|
# LibraryThing only supports a single author, so
|
193
162
|
# attempt to include more author information if it's
|
@@ -196,9 +165,8 @@ module Alexandria
|
|
196
165
|
end
|
197
166
|
book.edition = dl_book.edition unless book.edition
|
198
167
|
cover = dl_cover
|
199
|
-
rescue
|
200
|
-
|
201
|
-
# note failure
|
168
|
+
rescue StandardError
|
169
|
+
log.debug { "Failed to get cover for #{book.title} #{book.isbn}" }
|
202
170
|
end
|
203
171
|
end
|
204
172
|
|
@@ -213,12 +181,12 @@ module Alexandria
|
|
213
181
|
# probably Goodreads' wonky ISBN fields ,,="043432432X",
|
214
182
|
# this is a hack to fix up such files
|
215
183
|
data = File.read(filename)
|
216
|
-
data.gsub!(
|
217
|
-
csv_fixed = Tempfile.new(
|
184
|
+
data.gsub!(/,="/, ',"')
|
185
|
+
csv_fixed = Tempfile.new("alexandria_import_csv_fixed_")
|
218
186
|
csv_fixed.write(data)
|
219
187
|
csv_fixed.close
|
220
188
|
|
221
|
-
reader = CSV.open(csv_fixed.path,
|
189
|
+
reader = CSV.open(csv_fixed.path, "r")
|
222
190
|
header = reader.shift
|
223
191
|
importer = identify_csv_type(header)
|
224
192
|
|
@@ -226,12 +194,13 @@ module Alexandria
|
|
226
194
|
end
|
227
195
|
end
|
228
196
|
|
229
|
-
library
|
197
|
+
# TODO: Pass in library store as an argument
|
198
|
+
library = LibraryCollection.instance.library_store.load_library name
|
230
199
|
|
231
200
|
books_and_covers.each do |book, cover_uri|
|
232
|
-
|
201
|
+
log.debug { "Saving #{book.isbn} cover" }
|
233
202
|
library.save_cover(book, cover_uri) unless cover_uri.nil?
|
234
|
-
|
203
|
+
log.debug { "Saving #{book.isbn}" }
|
235
204
|
library << book
|
236
205
|
library.save(book)
|
237
206
|
end
|
@@ -240,20 +209,15 @@ module Alexandria
|
|
240
209
|
|
241
210
|
def self.import_as_isbn_list(name, filename, on_iterate_cb,
|
242
211
|
on_error_cb)
|
243
|
-
|
212
|
+
log.debug { "Starting import_as_isbn_list... " }
|
244
213
|
isbn_list = IO.readlines(filename).map do |line|
|
245
|
-
|
246
|
-
|
247
|
-
begin
|
248
|
-
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
249
|
-
rescue => e
|
250
|
-
puts e.message
|
251
|
-
[line.chomp, nil]
|
252
|
-
end
|
214
|
+
log.debug { "Trying line #{line}" }
|
215
|
+
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
253
216
|
end
|
254
|
-
|
217
|
+
log.debug { "Isbn list: #{isbn_list.inspect}" }
|
255
218
|
isbn_list.compact!
|
256
219
|
return nil if isbn_list.empty?
|
220
|
+
|
257
221
|
max_iterations = isbn_list.length * 2
|
258
222
|
current_iteration = 1
|
259
223
|
books = []
|
@@ -262,27 +226,30 @@ module Alexandria
|
|
262
226
|
isbn_list.each do |isbn|
|
263
227
|
begin
|
264
228
|
if isbn[1]
|
265
|
-
books <<
|
229
|
+
books << BookProviders.isbn_search(isbn[1])
|
266
230
|
else
|
267
231
|
bad_isbns << isbn[0]
|
268
232
|
end
|
269
|
-
rescue =>
|
270
|
-
|
233
|
+
rescue BookProviders::SearchEmptyError => ex
|
234
|
+
log.debug { ex.message }
|
271
235
|
failed_lookup_isbns << isbn[1]
|
272
|
-
|
236
|
+
log.debug { "NOTE : ignoring on_error_cb #{on_error_cb}" }
|
273
237
|
# return nil unless
|
274
238
|
# (on_error_cb and on_error_cb.call(e.message))
|
275
239
|
end
|
276
240
|
|
277
241
|
on_iterate_cb&.call(current_iteration += 1, max_iterations)
|
278
242
|
end
|
279
|
-
|
280
|
-
|
281
|
-
|
243
|
+
log.debug { "Bad Isbn list: #{bad_isbns.inspect}" } if bad_isbns
|
244
|
+
|
245
|
+
# TODO: Pass in library store as an argument
|
246
|
+
library = LibraryCollection.instance.library_store.load_library name
|
247
|
+
|
248
|
+
log.debug { "Going with these #{books.length} books: #{books.inspect}" }
|
282
249
|
books.each do |book, cover_uri|
|
283
|
-
|
250
|
+
log.debug { "Saving #{book.isbn} cover..." }
|
284
251
|
library.save_cover(book, cover_uri) unless cover_uri.nil?
|
285
|
-
|
252
|
+
log.debug { "Saving #{book.isbn}..." }
|
286
253
|
library << book
|
287
254
|
library.save(book)
|
288
255
|
on_iterate_cb&.call(current_iteration += 1, max_iterations)
|
@@ -20,10 +20,10 @@
|
|
20
20
|
# New CSV import code taken from Palatina and modified for
|
21
21
|
# Alexandria. (29 Apr 2010)
|
22
22
|
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
23
|
+
require "csv"
|
24
|
+
require "date"
|
25
|
+
require "htmlentities"
|
26
|
+
require "tempfile"
|
27
27
|
|
28
28
|
module Alexandria
|
29
29
|
class CSVImport
|
@@ -47,21 +47,21 @@ module Alexandria
|
|
47
47
|
class GoodreadsCSVImport < CSVImport
|
48
48
|
def initialize(header)
|
49
49
|
super(header)
|
50
|
-
@title = index_of(
|
51
|
-
@author = index_of(
|
52
|
-
@additional_authors = index_of(
|
53
|
-
@isbn = index_of(
|
54
|
-
@publisher = index_of(
|
55
|
-
@publishing_year = index_of(
|
56
|
-
@edition = index_of(
|
50
|
+
@title = index_of("Title")
|
51
|
+
@author = index_of("Author")
|
52
|
+
@additional_authors = index_of("Additional Authors")
|
53
|
+
@isbn = index_of("ISBN")
|
54
|
+
@publisher = index_of("Publisher")
|
55
|
+
@publishing_year = index_of("Year Published")
|
56
|
+
@edition = index_of("Binding")
|
57
57
|
|
58
58
|
# optional extras
|
59
|
-
@notes = index_of(
|
60
|
-
@rating = index_of(
|
61
|
-
@read_count = index_of(
|
62
|
-
@date_read = index_of(
|
63
|
-
@bookshelves = index_of(
|
64
|
-
@mainshelf = index_of(
|
59
|
+
@notes = index_of("Private Notes")
|
60
|
+
@rating = index_of("My Rating")
|
61
|
+
@read_count = index_of("Read Count")
|
62
|
+
@date_read = index_of("Date Read")
|
63
|
+
@bookshelves = index_of("Bookshelves") # save names as tags
|
64
|
+
@mainshelf = index_of("Exclusive Shelf")
|
65
65
|
end
|
66
66
|
|
67
67
|
def row_to_book(row)
|
@@ -69,11 +69,10 @@ module Alexandria
|
|
69
69
|
authors = []
|
70
70
|
authors << normalize(row[@author])
|
71
71
|
additional = row[@additional_authors]
|
72
|
-
additional.split(
|
72
|
+
additional.split(",").each do |add|
|
73
73
|
authors << normalize(add)
|
74
74
|
end
|
75
|
-
isbn = row[@isbn]
|
76
|
-
isbn = Library.canonicalise_ean(isbn) if isbn
|
75
|
+
isbn = Library.canonicalise_ean(row[@isbn])
|
77
76
|
publisher = normalize(row[@publisher])
|
78
77
|
year = row[@publishing_year].to_i
|
79
78
|
edition = normalize(row[@edition])
|
@@ -90,32 +89,30 @@ module Alexandria
|
|
90
89
|
book.redd = true if count > 0
|
91
90
|
end
|
92
91
|
if row[@date_read]
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
book.redd = true
|
97
|
-
rescue
|
98
|
-
end
|
92
|
+
date = Date.strptime(str, "%d/%m/%y") # e.g. "14/01/10" => 2010-01-14
|
93
|
+
book.redd_when = date
|
94
|
+
book.redd = true
|
99
95
|
end
|
100
96
|
if row[@mainshelf]
|
101
|
-
|
97
|
+
case row[@mainshelf]
|
98
|
+
when "read"
|
102
99
|
book.redd = true
|
103
|
-
|
100
|
+
when "to-read"
|
104
101
|
book.redd = false
|
105
|
-
book.tags = [
|
106
|
-
|
102
|
+
book.tags = ["to read"]
|
103
|
+
when "currently-reading"
|
107
104
|
book.redd = false
|
108
|
-
book.tags = [
|
105
|
+
book.tags = ["currently reading"]
|
109
106
|
end
|
110
107
|
end
|
111
108
|
if row[@bookshelves]
|
112
109
|
shelves = normalize(row[@bookshelves]).split
|
113
110
|
shelves.each do |shelf|
|
114
|
-
tag = shelf.tr(
|
111
|
+
tag = shelf.tr("-", " ")
|
115
112
|
book.tags << tag unless book.tags.include? tag
|
116
113
|
end
|
117
114
|
end
|
118
|
-
|
115
|
+
log.debug { "Goodreads loading #{book.title}" }
|
119
116
|
book
|
120
117
|
end
|
121
118
|
end
|
@@ -149,10 +146,10 @@ module Alexandria
|
|
149
146
|
# sometimes "Publisher (YEAR), Edition: NUM, Binding, NUM pages"
|
150
147
|
publisher_info = normalize(row[@publisher_info])
|
151
148
|
publisher = publisher_info
|
152
|
-
publisher = Regexp.last_match[1] if publisher_info =~ /([
|
149
|
+
publisher = Regexp.last_match[1] if publisher_info =~ /([^(]+)\(/
|
153
150
|
edition = publisher_info # binding
|
154
|
-
edition_info = publisher_info.split(
|
155
|
-
edition = publisher_info.split(
|
151
|
+
edition_info = publisher_info.split(",")
|
152
|
+
edition = publisher_info.split(",")[-2] if edition_info.size >= 3
|
156
153
|
|
157
154
|
year = row[@publishing_year].to_i
|
158
155
|
|
@@ -166,13 +163,13 @@ module Alexandria
|
|
166
163
|
|
167
164
|
book.rating = row[@rating].to_i if row[@rating]
|
168
165
|
if row[@tags]
|
169
|
-
tags = normalize(row[@tags]).split(
|
166
|
+
tags = normalize(row[@tags]).split(",")
|
170
167
|
tags.each do |tag|
|
171
168
|
book.tags << tag unless book.tags.include? tag
|
172
169
|
end
|
173
170
|
end
|
174
171
|
|
175
|
-
|
172
|
+
log.debug { "LibraryThing loading #{book.title}" }
|
176
173
|
book
|
177
174
|
end
|
178
175
|
end
|
@@ -186,20 +183,20 @@ module Alexandria
|
|
186
183
|
is_librarything = false
|
187
184
|
is_goodreads = false
|
188
185
|
header.each do |head|
|
189
|
-
|
186
|
+
case head
|
187
|
+
when "'PUBLICATION INFO'"
|
190
188
|
is_librarything = true
|
191
189
|
break
|
192
|
-
|
190
|
+
when "Year Published"
|
193
191
|
is_goodreads = true
|
194
192
|
break
|
195
193
|
end
|
196
194
|
end
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
raise 'Not Recognized' unless is_librarything || is_goodreads
|
195
|
+
|
196
|
+
return LibraryThingCSVImport.new(header) if is_librarything
|
197
|
+
return GoodreadsCSVImport.new(header) if is_goodreads
|
198
|
+
|
199
|
+
raise _("Not Recognized") unless is_librarything || is_goodreads
|
203
200
|
end
|
204
201
|
end
|
205
202
|
end
|