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
@@ -4,24 +4,25 @@
|
|
4
4
|
#
|
5
5
|
# See the file README.md for authorship and licensing information.
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "gettext"
|
8
|
+
require "tmpdir"
|
9
9
|
|
10
10
|
module Alexandria
|
11
11
|
class ImportFilter
|
12
12
|
attr_reader :name, :patterns, :message
|
13
13
|
|
14
|
+
include Logging
|
14
15
|
include GetText
|
15
16
|
extend GetText
|
16
|
-
bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
17
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
17
18
|
|
18
19
|
def self.all
|
19
20
|
[
|
20
|
-
new(_(
|
21
|
-
new(_(
|
22
|
-
[
|
23
|
-
new(_(
|
24
|
-
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)
|
25
26
|
]
|
26
27
|
end
|
27
28
|
|
@@ -34,7 +35,7 @@ module Alexandria
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def invoke(library_name, filename)
|
37
|
-
|
38
|
+
log.debug { "Selected: #{@message} -- #{library_name} -- #{filename}" }
|
38
39
|
Library.send(@message, library_name, filename,
|
39
40
|
@on_iterate_cb, @on_error_cb)
|
40
41
|
end
|
@@ -50,122 +51,100 @@ module Alexandria
|
|
50
51
|
|
51
52
|
class Library
|
52
53
|
def self.import_autodetect(*args)
|
53
|
-
|
54
|
+
log.debug { args.inspect }
|
54
55
|
filename = args[1]
|
55
|
-
|
56
|
-
|
57
|
-
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"
|
58
59
|
import_as_isbn_list(*args)
|
59
|
-
elsif [
|
60
|
-
|
61
|
-
|
62
|
-
rescue StandardError => e
|
63
|
-
puts e.message
|
64
|
-
puts e.backtrace.join("\n>> ")
|
65
|
-
end
|
66
|
-
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]
|
67
63
|
import_as_csv_file(*args)
|
68
64
|
else
|
69
|
-
|
70
|
-
raise 'Not supported type'
|
65
|
+
raise _("Unsupported type")
|
71
66
|
end
|
72
67
|
end
|
73
68
|
|
74
69
|
def self.import_as_tellico_xml_archive(name, filename,
|
75
70
|
on_iterate_cb, _on_error_cb)
|
76
|
-
|
71
|
+
log.debug { "Starting import_as_tellico_xml_archive... " }
|
77
72
|
return nil unless system("unzip -qqt \"#{filename}\"")
|
78
73
|
|
79
|
-
tmpdir = File.join(Dir.tmpdir,
|
74
|
+
tmpdir = File.join(Dir.tmpdir, "tellico_export")
|
80
75
|
FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
|
81
76
|
Dir.mkdir(tmpdir)
|
82
77
|
Dir.chdir(tmpdir) do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
raise unless xml.root.elements.size == 1
|
90
|
-
|
91
|
-
collection = xml.root.elements[1]
|
92
|
-
raise unless collection.name == 'collection'
|
93
|
-
|
94
|
-
type = collection.attribute('type').value.to_i
|
95
|
-
raise unless (type == 2) || (type == 5)
|
96
|
-
|
97
|
-
content = []
|
98
|
-
entries = collection.elements.to_a('entry')
|
99
|
-
(total = entries.size).times do |n|
|
100
|
-
entry = entries[n]
|
101
|
-
elements = entry.elements
|
102
|
-
# Feed an array in here, tomorrow.
|
103
|
-
keys = ['isbn', 'publisher', 'pub_year', 'binding']
|
104
|
-
|
105
|
-
book_elements = [neaten(elements['title'].text)]
|
106
|
-
book_elements += if !elements['authors'].nil?
|
107
|
-
[elements['authors'].elements.to_a.map \
|
108
|
-
{ |x| neaten(x.text) }]
|
109
|
-
else
|
110
|
-
[[]]
|
111
|
-
end
|
112
|
-
book_elements += keys.map { |key|
|
113
|
-
neaten(elements[key].text) if elements[key]
|
114
|
-
}
|
115
|
-
# isbn
|
116
|
-
if book_elements[2].nil? || book_elements[2].strip.empty?
|
117
|
-
book_elements[2] = nil
|
118
|
-
else
|
119
|
-
begin
|
120
|
-
book_elements[2] = book_elements[2].strip
|
121
|
-
book_elements[2] = Library.canonicalise_ean(book_elements[2])
|
122
|
-
rescue StandardError => ex
|
123
|
-
puts book_elements[2]
|
124
|
-
puts ex.message
|
125
|
-
puts ex.backtrace.join("\n> ")
|
126
|
-
raise ex
|
127
|
-
end
|
128
|
-
end
|
129
|
-
book_elements[4] = book_elements[4].to_i unless book_elements[4].nil? # publishing_year
|
130
|
-
puts book_elements.inspect
|
131
|
-
cover = (neaten(elements['cover'].text) if elements['cover'])
|
132
|
-
puts cover
|
133
|
-
book = Book.new(*book_elements)
|
134
|
-
if elements['rating'] && Book::VALID_RATINGS.member?(elements['rating'].text.to_i)
|
135
|
-
book.rating = elements['rating'].text.to_i
|
136
|
-
end
|
137
|
-
book.notes = neaten(elements['comments'].text) if elements['comments']
|
138
|
-
content << [book, cover]
|
139
|
-
on_iterate_cb&.call(n + 1, total)
|
140
|
-
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
|
141
84
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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]
|
108
|
+
end
|
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
|
151
119
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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)
|
156
131
|
end
|
132
|
+
return [library, []]
|
133
|
+
rescue StandardError => ex
|
134
|
+
log.info { ex.message }
|
135
|
+
return nil
|
157
136
|
end
|
158
137
|
end
|
159
138
|
|
160
139
|
def self.import_as_csv_file(name, filename, on_iterate_cb, _on_error_cb)
|
161
|
-
require
|
140
|
+
require "alexandria/import_library_csv"
|
162
141
|
books_and_covers = []
|
163
142
|
line_count = IO.readlines(filename).reduce(0) { |count, _line| count + 1 }
|
164
143
|
|
165
144
|
import_count = 0
|
166
145
|
max_import = line_count - 1
|
167
146
|
|
168
|
-
reader = CSV.open(filename,
|
147
|
+
reader = CSV.open(filename, "r")
|
169
148
|
# Goodreads & LibraryThing now use csv header lines
|
170
149
|
header = reader.shift
|
171
150
|
importer = identify_csv_type(header)
|
@@ -177,7 +156,7 @@ module Alexandria
|
|
177
156
|
if book.isbn
|
178
157
|
# if we can search by ISBN, try to grab the cover
|
179
158
|
begin
|
180
|
-
dl_book, dl_cover =
|
159
|
+
dl_book, dl_cover = BookProviders.isbn_search(book.isbn)
|
181
160
|
if dl_book.authors.size > book.authors.size
|
182
161
|
# LibraryThing only supports a single author, so
|
183
162
|
# attempt to include more author information if it's
|
@@ -187,8 +166,7 @@ module Alexandria
|
|
187
166
|
book.edition = dl_book.edition unless book.edition
|
188
167
|
cover = dl_cover
|
189
168
|
rescue StandardError
|
190
|
-
|
191
|
-
# note failure
|
169
|
+
log.debug { "Failed to get cover for #{book.title} #{book.isbn}" }
|
192
170
|
end
|
193
171
|
end
|
194
172
|
|
@@ -203,12 +181,12 @@ module Alexandria
|
|
203
181
|
# probably Goodreads' wonky ISBN fields ,,="043432432X",
|
204
182
|
# this is a hack to fix up such files
|
205
183
|
data = File.read(filename)
|
206
|
-
data.gsub!(
|
207
|
-
csv_fixed = Tempfile.new(
|
184
|
+
data.gsub!(/,="/, ',"')
|
185
|
+
csv_fixed = Tempfile.new("alexandria_import_csv_fixed_")
|
208
186
|
csv_fixed.write(data)
|
209
187
|
csv_fixed.close
|
210
188
|
|
211
|
-
reader = CSV.open(csv_fixed.path,
|
189
|
+
reader = CSV.open(csv_fixed.path, "r")
|
212
190
|
header = reader.shift
|
213
191
|
importer = identify_csv_type(header)
|
214
192
|
|
@@ -216,12 +194,13 @@ module Alexandria
|
|
216
194
|
end
|
217
195
|
end
|
218
196
|
|
219
|
-
library
|
197
|
+
# TODO: Pass in library store as an argument
|
198
|
+
library = LibraryCollection.instance.library_store.load_library name
|
220
199
|
|
221
200
|
books_and_covers.each do |book, cover_uri|
|
222
|
-
|
201
|
+
log.debug { "Saving #{book.isbn} cover" }
|
223
202
|
library.save_cover(book, cover_uri) unless cover_uri.nil?
|
224
|
-
|
203
|
+
log.debug { "Saving #{book.isbn}" }
|
225
204
|
library << book
|
226
205
|
library.save(book)
|
227
206
|
end
|
@@ -230,18 +209,12 @@ module Alexandria
|
|
230
209
|
|
231
210
|
def self.import_as_isbn_list(name, filename, on_iterate_cb,
|
232
211
|
on_error_cb)
|
233
|
-
|
212
|
+
log.debug { "Starting import_as_isbn_list... " }
|
234
213
|
isbn_list = IO.readlines(filename).map do |line|
|
235
|
-
|
236
|
-
|
237
|
-
begin
|
238
|
-
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
239
|
-
rescue StandardError => e
|
240
|
-
puts e.message
|
241
|
-
[line.chomp, nil]
|
242
|
-
end
|
214
|
+
log.debug { "Trying line #{line}" }
|
215
|
+
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
243
216
|
end
|
244
|
-
|
217
|
+
log.debug { "Isbn list: #{isbn_list.inspect}" }
|
245
218
|
isbn_list.compact!
|
246
219
|
return nil if isbn_list.empty?
|
247
220
|
|
@@ -253,27 +226,30 @@ module Alexandria
|
|
253
226
|
isbn_list.each do |isbn|
|
254
227
|
begin
|
255
228
|
if isbn[1]
|
256
|
-
books <<
|
229
|
+
books << BookProviders.isbn_search(isbn[1])
|
257
230
|
else
|
258
231
|
bad_isbns << isbn[0]
|
259
232
|
end
|
260
|
-
rescue
|
261
|
-
|
233
|
+
rescue BookProviders::SearchEmptyError => ex
|
234
|
+
log.debug { ex.message }
|
262
235
|
failed_lookup_isbns << isbn[1]
|
263
|
-
|
236
|
+
log.debug { "NOTE : ignoring on_error_cb #{on_error_cb}" }
|
264
237
|
# return nil unless
|
265
238
|
# (on_error_cb and on_error_cb.call(e.message))
|
266
239
|
end
|
267
240
|
|
268
241
|
on_iterate_cb&.call(current_iteration += 1, max_iterations)
|
269
242
|
end
|
270
|
-
|
271
|
-
|
272
|
-
|
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}" }
|
273
249
|
books.each do |book, cover_uri|
|
274
|
-
|
250
|
+
log.debug { "Saving #{book.isbn} cover..." }
|
275
251
|
library.save_cover(book, cover_uri) unless cover_uri.nil?
|
276
|
-
|
252
|
+
log.debug { "Saving #{book.isbn}..." }
|
277
253
|
library << book
|
278
254
|
library.save(book)
|
279
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,29 +89,30 @@ module Alexandria
|
|
90
89
|
book.redd = true if count > 0
|
91
90
|
end
|
92
91
|
if row[@date_read]
|
93
|
-
date = Date.strptime(str,
|
92
|
+
date = Date.strptime(str, "%d/%m/%y") # e.g. "14/01/10" => 2010-01-14
|
94
93
|
book.redd_when = date
|
95
94
|
book.redd = true
|
96
95
|
end
|
97
96
|
if row[@mainshelf]
|
98
|
-
|
97
|
+
case row[@mainshelf]
|
98
|
+
when "read"
|
99
99
|
book.redd = true
|
100
|
-
|
100
|
+
when "to-read"
|
101
101
|
book.redd = false
|
102
|
-
book.tags = [
|
103
|
-
|
102
|
+
book.tags = ["to read"]
|
103
|
+
when "currently-reading"
|
104
104
|
book.redd = false
|
105
|
-
book.tags = [
|
105
|
+
book.tags = ["currently reading"]
|
106
106
|
end
|
107
107
|
end
|
108
108
|
if row[@bookshelves]
|
109
109
|
shelves = normalize(row[@bookshelves]).split
|
110
110
|
shelves.each do |shelf|
|
111
|
-
tag = shelf.tr(
|
111
|
+
tag = shelf.tr("-", " ")
|
112
112
|
book.tags << tag unless book.tags.include? tag
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
log.debug { "Goodreads loading #{book.title}" }
|
116
116
|
book
|
117
117
|
end
|
118
118
|
end
|
@@ -146,10 +146,10 @@ module Alexandria
|
|
146
146
|
# sometimes "Publisher (YEAR), Edition: NUM, Binding, NUM pages"
|
147
147
|
publisher_info = normalize(row[@publisher_info])
|
148
148
|
publisher = publisher_info
|
149
|
-
publisher = Regexp.last_match[1] if publisher_info =~ /([
|
149
|
+
publisher = Regexp.last_match[1] if publisher_info =~ /([^(]+)\(/
|
150
150
|
edition = publisher_info # binding
|
151
|
-
edition_info = publisher_info.split(
|
152
|
-
edition = publisher_info.split(
|
151
|
+
edition_info = publisher_info.split(",")
|
152
|
+
edition = publisher_info.split(",")[-2] if edition_info.size >= 3
|
153
153
|
|
154
154
|
year = row[@publishing_year].to_i
|
155
155
|
|
@@ -163,13 +163,13 @@ module Alexandria
|
|
163
163
|
|
164
164
|
book.rating = row[@rating].to_i if row[@rating]
|
165
165
|
if row[@tags]
|
166
|
-
tags = normalize(row[@tags]).split(
|
166
|
+
tags = normalize(row[@tags]).split(",")
|
167
167
|
tags.each do |tag|
|
168
168
|
book.tags << tag unless book.tags.include? tag
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
log.debug { "LibraryThing loading #{book.title}" }
|
173
173
|
book
|
174
174
|
end
|
175
175
|
end
|
@@ -183,20 +183,20 @@ module Alexandria
|
|
183
183
|
is_librarything = false
|
184
184
|
is_goodreads = false
|
185
185
|
header.each do |head|
|
186
|
-
|
186
|
+
case head
|
187
|
+
when "'PUBLICATION INFO'"
|
187
188
|
is_librarything = true
|
188
189
|
break
|
189
|
-
|
190
|
+
when "Year Published"
|
190
191
|
is_goodreads = true
|
191
192
|
break
|
192
193
|
end
|
193
194
|
end
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
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
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|