alexandria-book-collection-manager 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -25
- data/.rubocop_todo.yml +87 -67
- data/CHANGELOG.md +12 -1
- data/Gemfile +4 -3
- data/README.md +16 -6
- data/Rakefile +71 -72
- data/alexandria-book-collection-manager.gemspec +44 -44
- data/bin/alexandria +12 -12
- data/lib/alexandria.rb +22 -22
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +50 -50
- data/lib/alexandria/book_providers/adlibris.rb +28 -44
- data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
- data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
- data/lib/alexandria/book_providers/douban.rb +21 -37
- data/lib/alexandria/book_providers/proxis.rb +24 -24
- data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
- data/lib/alexandria/book_providers/renaud.rb +44 -57
- data/lib/alexandria/book_providers/siciliano.rb +39 -39
- data/lib/alexandria/book_providers/thalia.rb +33 -33
- data/lib/alexandria/book_providers/web.rb +5 -5
- data/lib/alexandria/book_providers/worldcat.rb +44 -69
- data/lib/alexandria/book_providers/z3950.rb +94 -109
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +3 -3
- data/lib/alexandria/export_format.rb +8 -8
- data/lib/alexandria/export_library.rb +112 -113
- data/lib/alexandria/import_library.rb +45 -45
- data/lib/alexandria/import_library_csv.rb +30 -30
- data/lib/alexandria/library_collection.rb +4 -4
- data/lib/alexandria/library_sort_order.rb +1 -1
- data/lib/alexandria/library_store.rb +14 -14
- data/lib/alexandria/logging.rb +5 -5
- data/lib/alexandria/models/book.rb +1 -1
- data/lib/alexandria/models/library.rb +36 -36
- data/lib/alexandria/net.rb +5 -5
- data/lib/alexandria/preferences.rb +32 -32
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
- data/lib/alexandria/scanners/keyboard.rb +5 -5
- data/lib/alexandria/smart_library.rb +53 -53
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
- data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
- data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
- data/lib/alexandria/ui/builder_base.rb +1 -1
- data/lib/alexandria/ui/callbacks.rb +95 -91
- data/lib/alexandria/ui/completion_models.rb +7 -21
- 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} +22 -42
- data/lib/alexandria/ui/icons.rb +6 -6
- data/lib/alexandria/ui/iconview.rb +7 -7
- data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
- data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
- data/lib/alexandria/ui/init.rb +16 -29
- data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
- data/lib/alexandria/ui/libraries_combo.rb +7 -7
- data/lib/alexandria/ui/listview.rb +40 -40
- data/lib/alexandria/ui/main_app.rb +22 -24
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
- data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
- data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
- data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
- data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
- data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
- data/lib/alexandria/ui/sound.rb +8 -8
- data/lib/alexandria/ui/ui_manager.rb +136 -135
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +8 -8
- data/po/cs.po +97 -97
- data/po/cy.po +97 -97
- data/po/de.po +97 -97
- data/po/el.po +97 -97
- data/po/es.po +97 -97
- data/po/fr.po +97 -97
- data/po/ga.po +97 -97
- data/po/gl.po +97 -97
- data/po/it.po +97 -97
- data/po/ja.po +97 -97
- data/po/mk.po +97 -97
- data/po/nb.po +97 -97
- data/po/nl.po +97 -97
- data/po/pl.po +97 -97
- data/po/pt.po +97 -97
- data/po/pt_BR.po +97 -97
- data/po/ru.po +97 -97
- data/po/sk.po +97 -97
- data/po/sv.po +97 -97
- data/po/uk.po +97 -97
- data/po/zh_TW.po +97 -97
- data/schemas/alexandria.schemas +24 -2
- data/spec/alexandria/book_providers_spec.rb +65 -82
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +9 -9
- data/spec/alexandria/export_library_spec.rb +31 -31
- data/spec/alexandria/library_spec.rb +86 -86
- data/spec/alexandria/library_store_spec.rb +8 -8
- data/spec/alexandria/preferences_spec.rb +18 -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 +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/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +6 -6
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -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 +14 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -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 +18 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
- data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
- data/spec/alexandria/utilities_spec.rb +6 -6
- data/spec/end_to_end/basic_run_spec.rb +24 -36
- data/spec/spec_helper.rb +9 -9
- data/tasks/dogtail.rake +1 -1
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +11 -11
- data/util/rake/fileinstall.rb +25 -25
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +59 -33
- 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
@@ -4,8 +4,8 @@
|
|
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
|
@@ -13,15 +13,15 @@ module Alexandria
|
|
13
13
|
|
14
14
|
include GetText
|
15
15
|
extend GetText
|
16
|
-
bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
16
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
17
17
|
|
18
18
|
def self.all
|
19
19
|
[
|
20
|
-
new(_(
|
21
|
-
new(_(
|
22
|
-
[
|
23
|
-
new(_(
|
24
|
-
new(_(
|
20
|
+
new(_("Autodetect"), ["*"], :import_autodetect),
|
21
|
+
new(_("Archived Tellico XML (*.bc, *.tc)"),
|
22
|
+
["*.tc", "*.bc"], :import_as_tellico_xml_archive),
|
23
|
+
new(_("ISBN List (*.txt)"), ["*.txt"], :import_as_isbn_list),
|
24
|
+
new(_("GoodReads CSV"), ["*.csv"], :import_as_csv_file)
|
25
25
|
]
|
26
26
|
end
|
27
27
|
|
@@ -54,64 +54,64 @@ module Alexandria
|
|
54
54
|
filename = args[1]
|
55
55
|
puts "Filename is #{filename} and ext is #{filename[-4..-1]}"
|
56
56
|
puts "Beginning import: #{args[0]}, #{args[1]}"
|
57
|
-
if filename[-4..-1] ==
|
57
|
+
if filename[-4..-1] == ".txt"
|
58
58
|
import_as_isbn_list(*args)
|
59
|
-
elsif [
|
59
|
+
elsif [".tc", ".bc"].include? filename[-3..-1]
|
60
60
|
begin
|
61
61
|
import_as_tellico_xml_archive(*args)
|
62
|
-
rescue StandardError =>
|
63
|
-
puts
|
64
|
-
puts
|
62
|
+
rescue StandardError => ex
|
63
|
+
puts ex.message
|
64
|
+
puts ex.backtrace.join("\n>> ")
|
65
65
|
end
|
66
|
-
elsif [
|
66
|
+
elsif [".csv"].include? filename[-4..-1]
|
67
67
|
import_as_csv_file(*args)
|
68
68
|
else
|
69
|
-
puts
|
70
|
-
raise
|
69
|
+
puts "Bailing on this import!"
|
70
|
+
raise "Not supported type"
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def self.import_as_tellico_xml_archive(name, filename,
|
75
75
|
on_iterate_cb, _on_error_cb)
|
76
|
-
puts
|
76
|
+
puts "Starting import_as_tellico_xml_archive... "
|
77
77
|
return nil unless system("unzip -qqt \"#{filename}\"")
|
78
78
|
|
79
|
-
tmpdir = File.join(Dir.tmpdir,
|
79
|
+
tmpdir = File.join(Dir.tmpdir, "tellico_export")
|
80
80
|
FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
|
81
81
|
Dir.mkdir(tmpdir)
|
82
82
|
Dir.chdir(tmpdir) do
|
83
83
|
begin
|
84
84
|
system("unzip -qq \"#{filename}\"")
|
85
|
-
file = File.exist?(
|
85
|
+
file = File.exist?("bookcase.xml") ? "bookcase.xml" : "tellico.xml"
|
86
86
|
xml = REXML::Document.new(File.open(file))
|
87
|
-
raise unless [
|
87
|
+
raise unless ["bookcase", "tellico"].include? xml.root.name
|
88
88
|
# FIXME: handle multiple collections
|
89
89
|
raise unless xml.root.elements.size == 1
|
90
90
|
|
91
91
|
collection = xml.root.elements[1]
|
92
|
-
raise unless collection.name ==
|
92
|
+
raise unless collection.name == "collection"
|
93
93
|
|
94
|
-
type = collection.attribute(
|
94
|
+
type = collection.attribute("type").value.to_i
|
95
95
|
raise unless (type == 2) || (type == 5)
|
96
96
|
|
97
97
|
content = []
|
98
|
-
entries = collection.elements.to_a(
|
98
|
+
entries = collection.elements.to_a("entry")
|
99
99
|
(total = entries.size).times do |n|
|
100
100
|
entry = entries[n]
|
101
101
|
elements = entry.elements
|
102
102
|
# Feed an array in here, tomorrow.
|
103
|
-
keys = [
|
103
|
+
keys = ["isbn", "publisher", "pub_year", "binding"]
|
104
104
|
|
105
|
-
book_elements = [neaten(elements[
|
106
|
-
book_elements += if !elements[
|
107
|
-
[elements[
|
105
|
+
book_elements = [neaten(elements["title"].text)]
|
106
|
+
book_elements += if !elements["authors"].nil?
|
107
|
+
[elements["authors"].elements.to_a.map \
|
108
108
|
{ |x| neaten(x.text) }]
|
109
109
|
else
|
110
110
|
[[]]
|
111
111
|
end
|
112
|
-
book_elements += keys.map
|
112
|
+
book_elements += keys.map do |key|
|
113
113
|
neaten(elements[key].text) if elements[key]
|
114
|
-
|
114
|
+
end
|
115
115
|
# isbn
|
116
116
|
if book_elements[2].nil? || book_elements[2].strip.empty?
|
117
117
|
book_elements[2] = nil
|
@@ -128,13 +128,13 @@ module Alexandria
|
|
128
128
|
end
|
129
129
|
book_elements[4] = book_elements[4].to_i unless book_elements[4].nil? # publishing_year
|
130
130
|
puts book_elements.inspect
|
131
|
-
cover = (neaten(elements[
|
131
|
+
cover = (neaten(elements["cover"].text) if elements["cover"])
|
132
132
|
puts cover
|
133
133
|
book = Book.new(*book_elements)
|
134
|
-
if elements[
|
135
|
-
book.rating = elements[
|
134
|
+
if elements["rating"] && Book::VALID_RATINGS.member?(elements["rating"].text.to_i)
|
135
|
+
book.rating = elements["rating"].text.to_i
|
136
136
|
end
|
137
|
-
book.notes = neaten(elements[
|
137
|
+
book.notes = neaten(elements["comments"].text) if elements["comments"]
|
138
138
|
content << [book, cover]
|
139
139
|
on_iterate_cb&.call(n + 1, total)
|
140
140
|
end
|
@@ -143,29 +143,29 @@ module Alexandria
|
|
143
143
|
content.each do |book, cover|
|
144
144
|
unless cover.nil?
|
145
145
|
library.save_cover(book,
|
146
|
-
File.join(Dir.pwd,
|
146
|
+
File.join(Dir.pwd, "images",
|
147
147
|
cover))
|
148
148
|
end
|
149
149
|
library << book
|
150
150
|
library.save(book)
|
151
151
|
end
|
152
152
|
return [library, []]
|
153
|
-
rescue StandardError =>
|
154
|
-
puts
|
153
|
+
rescue StandardError => ex
|
154
|
+
puts ex.message
|
155
155
|
return nil
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
160
|
def self.import_as_csv_file(name, filename, on_iterate_cb, _on_error_cb)
|
161
|
-
require
|
161
|
+
require "alexandria/import_library_csv"
|
162
162
|
books_and_covers = []
|
163
163
|
line_count = IO.readlines(filename).reduce(0) { |count, _line| count + 1 }
|
164
164
|
|
165
165
|
import_count = 0
|
166
166
|
max_import = line_count - 1
|
167
167
|
|
168
|
-
reader = CSV.open(filename,
|
168
|
+
reader = CSV.open(filename, "r")
|
169
169
|
# Goodreads & LibraryThing now use csv header lines
|
170
170
|
header = reader.shift
|
171
171
|
importer = identify_csv_type(header)
|
@@ -204,11 +204,11 @@ module Alexandria
|
|
204
204
|
# this is a hack to fix up such files
|
205
205
|
data = File.read(filename)
|
206
206
|
data.gsub!(/\,\=\"/, ',"')
|
207
|
-
csv_fixed = Tempfile.new(
|
207
|
+
csv_fixed = Tempfile.new("alexandria_import_csv_fixed_")
|
208
208
|
csv_fixed.write(data)
|
209
209
|
csv_fixed.close
|
210
210
|
|
211
|
-
reader = CSV.open(csv_fixed.path,
|
211
|
+
reader = CSV.open(csv_fixed.path, "r")
|
212
212
|
header = reader.shift
|
213
213
|
importer = identify_csv_type(header)
|
214
214
|
|
@@ -230,14 +230,14 @@ module Alexandria
|
|
230
230
|
|
231
231
|
def self.import_as_isbn_list(name, filename, on_iterate_cb,
|
232
232
|
on_error_cb)
|
233
|
-
puts
|
233
|
+
puts "Starting import_as_isbn_list... "
|
234
234
|
isbn_list = IO.readlines(filename).map do |line|
|
235
235
|
puts "Trying line #{line}" if $DEBUG
|
236
236
|
# Let's preserve the failing isbns so we can report them later.
|
237
237
|
begin
|
238
238
|
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
239
|
-
rescue StandardError =>
|
240
|
-
puts
|
239
|
+
rescue StandardError => ex
|
240
|
+
puts ex.message
|
241
241
|
[line.chomp, nil]
|
242
242
|
end
|
243
243
|
end
|
@@ -257,8 +257,8 @@ module Alexandria
|
|
257
257
|
else
|
258
258
|
bad_isbns << isbn[0]
|
259
259
|
end
|
260
|
-
rescue StandardError =>
|
261
|
-
puts
|
260
|
+
rescue StandardError => ex
|
261
|
+
puts ex.message
|
262
262
|
failed_lookup_isbns << isbn[1]
|
263
263
|
puts "NOTE : ignoring on_error_cb #{on_error_cb}"
|
264
264
|
# return nil unless
|
@@ -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,7 +69,7 @@ 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
75
|
isbn = row[@isbn] # TODO: canonicalize_ean...
|
@@ -90,25 +90,25 @@ module Alexandria
|
|
90
90
|
book.redd = true if count > 0
|
91
91
|
end
|
92
92
|
if row[@date_read]
|
93
|
-
date = Date.strptime(str,
|
93
|
+
date = Date.strptime(str, "%d/%m/%y") # e.g. "14/01/10" => 2010-01-14
|
94
94
|
book.redd_when = date
|
95
95
|
book.redd = true
|
96
96
|
end
|
97
97
|
if row[@mainshelf]
|
98
|
-
if row[@mainshelf] ==
|
98
|
+
if row[@mainshelf] == "read"
|
99
99
|
book.redd = true
|
100
|
-
elsif row[@mainshelf] ==
|
100
|
+
elsif row[@mainshelf] == "to-read"
|
101
101
|
book.redd = false
|
102
|
-
book.tags = [
|
103
|
-
elsif row[@mainshelf] ==
|
102
|
+
book.tags = ["to read"]
|
103
|
+
elsif row[@mainshelf] == "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
|
@@ -148,8 +148,8 @@ module Alexandria
|
|
148
148
|
publisher = publisher_info
|
149
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,7 +163,7 @@ 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
|
@@ -186,7 +186,7 @@ module Alexandria
|
|
186
186
|
if head == "'PUBLICATION INFO'"
|
187
187
|
is_librarything = true
|
188
188
|
break
|
189
|
-
elsif head ==
|
189
|
+
elsif head == "Year Published"
|
190
190
|
is_goodreads = true
|
191
191
|
break
|
192
192
|
end
|
@@ -196,7 +196,7 @@ module Alexandria
|
|
196
196
|
elsif is_goodreads
|
197
197
|
return GoodreadsCSVImport.new(header)
|
198
198
|
end
|
199
|
-
raise
|
199
|
+
raise "Not Recognized" unless is_librarything || is_goodreads
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -4,8 +4,8 @@
|
|
4
4
|
#
|
5
5
|
# See the file README.md for authorship and licensing information.
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "observer"
|
8
|
+
require "singleton"
|
9
9
|
|
10
10
|
module Alexandria
|
11
11
|
class LibraryCollection
|
@@ -22,11 +22,11 @@ module Alexandria
|
|
22
22
|
|
23
23
|
ruined = []
|
24
24
|
deleted = []
|
25
|
-
all_regular_libraries.each
|
25
|
+
all_regular_libraries.each do |library|
|
26
26
|
ruined += library.ruined_books
|
27
27
|
# make deleted books from each library accessible so we don't crash on smart libraries
|
28
28
|
deleted += library.deleted_books
|
29
|
-
|
29
|
+
end
|
30
30
|
@ruined_books = ruined
|
31
31
|
@deleted_books = deleted
|
32
32
|
end
|
@@ -9,10 +9,10 @@ module Alexandria
|
|
9
9
|
include Logging
|
10
10
|
|
11
11
|
FIX_BIGNUM_REGEX =
|
12
|
-
|
12
|
+
%r{loaned_since:\s*(\!ruby/object\:Bignum\s*)?(\d+)\n}.freeze
|
13
13
|
|
14
14
|
include GetText
|
15
|
-
bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
15
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
16
16
|
|
17
17
|
def initialize(dir)
|
18
18
|
@dir = dir
|
@@ -23,7 +23,7 @@ module Alexandria
|
|
23
23
|
begin
|
24
24
|
Dir.entries(library_dir).each do |file|
|
25
25
|
# Skip hidden files.
|
26
|
-
next if file
|
26
|
+
next if /^\./.match?(file)
|
27
27
|
# Skip non-directory files.
|
28
28
|
next unless File.stat(File.join(library_dir, file)).directory?
|
29
29
|
|
@@ -34,7 +34,7 @@ module Alexandria
|
|
34
34
|
end
|
35
35
|
# Create the default library if there is no library yet.
|
36
36
|
|
37
|
-
a << load_library(_(
|
37
|
+
a << load_library(_("My Library")) if a.empty?
|
38
38
|
|
39
39
|
a
|
40
40
|
end
|
@@ -45,7 +45,7 @@ module Alexandria
|
|
45
45
|
library = Library.new(name, self)
|
46
46
|
FileUtils.mkdir_p(library.path) unless File.exist?(library.path)
|
47
47
|
Dir.chdir(library.path) do
|
48
|
-
Dir[
|
48
|
+
Dir["*" + Library::EXT[:book]].each do |filename|
|
49
49
|
test[1] = filename if (test[0]).zero?
|
50
50
|
|
51
51
|
unless File.size? test[1]
|
@@ -111,21 +111,21 @@ module Alexandria
|
|
111
111
|
# '_medium.jpg' have been deprecated for a single medium
|
112
112
|
# cover file named '.cover'.
|
113
113
|
|
114
|
-
Dir[
|
114
|
+
Dir["*" + "_medium.jpg"].each do |medium_cover|
|
115
115
|
FileUtils.mv(medium_cover,
|
116
116
|
medium_cover.sub(/_medium\.jpg$/,
|
117
117
|
Library::EXT[:cover]))
|
118
118
|
end
|
119
119
|
|
120
|
-
Dir[
|
121
|
-
next if cover[0] ==
|
120
|
+
Dir["*" + Library::EXT[:cover]].each do |cover|
|
121
|
+
next if cover[0] == "g"
|
122
122
|
|
123
123
|
md = /(.+)\.cover/.match(cover)
|
124
124
|
ean = Library.canonicalise_ean(md[1]) || md[1]
|
125
125
|
FileUtils.mv(cover, ean + Library::EXT[:cover]) unless cover == ean + Library::EXT[:cover]
|
126
126
|
end
|
127
127
|
|
128
|
-
FileUtils.rm_f(Dir[
|
128
|
+
FileUtils.rm_f(Dir["*_small.jpg"])
|
129
129
|
end
|
130
130
|
library.ruined_books = ruined_books
|
131
131
|
|
@@ -137,7 +137,7 @@ module Alexandria
|
|
137
137
|
begin
|
138
138
|
# Deserialize smart libraries.
|
139
139
|
Dir.chdir(smart_library_dir) do
|
140
|
-
Dir[
|
140
|
+
Dir["*" + SmartLibrary::EXT].each do |filename|
|
141
141
|
# Skip non-regular files.
|
142
142
|
next unless File.stat(filename).file?
|
143
143
|
|
@@ -164,7 +164,7 @@ module Alexandria
|
|
164
164
|
end
|
165
165
|
|
166
166
|
def smart_library_dir
|
167
|
-
File.join(@dir,
|
167
|
+
File.join(@dir, ".smart_libraries")
|
168
168
|
end
|
169
169
|
|
170
170
|
private
|
@@ -177,9 +177,9 @@ module Alexandria
|
|
177
177
|
|
178
178
|
# The string is removed on load, but can't make it stick, maybe has to do with cache
|
179
179
|
|
180
|
-
if
|
180
|
+
if /!str:Amazon::Search::Response/.match?(text)
|
181
181
|
log.debug { "Removing Ruby/Amazon strings from #{name}" }
|
182
|
-
text.gsub!(
|
182
|
+
text.gsub!("!str:Amazon::Search::Response", "")
|
183
183
|
end
|
184
184
|
|
185
185
|
# Backward compatibility with versions <= 0.6.0, where the
|
@@ -187,7 +187,7 @@ module Alexandria
|
|
187
187
|
if (md = FIX_BIGNUM_REGEX.match(text))
|
188
188
|
new_yaml = Time.at(md[2].to_i).to_yaml
|
189
189
|
# Remove the "---" prefix.
|
190
|
-
new_yaml.sub!(/^\s*\-+\s*/,
|
190
|
+
new_yaml.sub!(/^\s*\-+\s*/, "")
|
191
191
|
text.sub!(md[0], "loaned_since: #{new_yaml}\n")
|
192
192
|
end
|
193
193
|
|