alexandria-book-collection-manager 0.6.9.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +68 -0
- data/.rubocop_todo.yml +200 -0
- data/CHANGELOG.md +23 -0
- data/COPYING +339 -0
- data/ChangeLog.0 +3598 -0
- data/Gemfile +9 -0
- data/INSTALL.rdoc +156 -0
- data/PACKAGING +36 -0
- data/README.md +88 -0
- data/RELEASE_CHECKLIST +18 -0
- data/Rakefile +264 -0
- data/TODO +24 -0
- data/alexandria-book-collection-manager.gemspec +35 -0
- data/alexandria.desktop.in +10 -0
- data/bin/alexandria +82 -0
- data/doc/AUTHORS +60 -0
- data/doc/BUGS +31 -0
- data/doc/FAQ +369 -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/lib/alexandria.rb +85 -0
- data/lib/alexandria/about.rb +82 -0
- data/lib/alexandria/book_providers.rb +411 -0
- data/lib/alexandria/book_providers/adlibris.rb +235 -0
- data/lib/alexandria/book_providers/amazon_aws.rb +261 -0
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +405 -0
- data/lib/alexandria/book_providers/barnes_and_noble.rb +229 -0
- data/lib/alexandria/book_providers/bol_it.rb +162 -0
- data/lib/alexandria/book_providers/deastore.rb +277 -0
- data/lib/alexandria/book_providers/douban.rb +135 -0
- data/lib/alexandria/book_providers/ibs_it.rb +149 -0
- data/lib/alexandria/book_providers/mcu.rb +177 -0
- data/lib/alexandria/book_providers/proxis.rb +205 -0
- data/lib/alexandria/book_providers/pseudomarc.rb +185 -0
- data/lib/alexandria/book_providers/renaud.rb +142 -0
- data/lib/alexandria/book_providers/siciliano.rb +271 -0
- data/lib/alexandria/book_providers/thalia.rb +197 -0
- data/lib/alexandria/book_providers/web.rb +59 -0
- data/lib/alexandria/book_providers/webster_it.rb +173 -0
- data/lib/alexandria/book_providers/worldcat.rb +251 -0
- data/lib/alexandria/book_providers/z3950.rb +422 -0
- data/lib/alexandria/config.rb +8 -0
- data/lib/alexandria/console.rb +31 -0
- data/lib/alexandria/execution_queue.rb +96 -0
- data/lib/alexandria/export_library.rb +536 -0
- data/lib/alexandria/import_library.rb +316 -0
- data/lib/alexandria/import_library_csv.rb +270 -0
- data/lib/alexandria/logging.rb +159 -0
- data/lib/alexandria/models/book.rb +72 -0
- data/lib/alexandria/models/library.rb +714 -0
- data/lib/alexandria/net.rb +53 -0
- data/lib/alexandria/preferences.rb +324 -0
- data/lib/alexandria/scanners.rb +42 -0
- data/lib/alexandria/scanners/cuecat.rb +118 -0
- data/lib/alexandria/scanners/keyboard.rb +57 -0
- data/lib/alexandria/smart_library.rb +525 -0
- data/lib/alexandria/ui.rb +53 -0
- data/lib/alexandria/ui/builder_base.rb +43 -0
- data/lib/alexandria/ui/callbacks.rb +389 -0
- data/lib/alexandria/ui/completion_models.rb +228 -0
- data/lib/alexandria/ui/dialogs/about_dialog.rb +59 -0
- data/lib/alexandria/ui/dialogs/acquire_dialog.rb +640 -0
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +68 -0
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +43 -0
- data/lib/alexandria/ui/dialogs/barcode_animation.rb +159 -0
- data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +210 -0
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +432 -0
- data/lib/alexandria/ui/dialogs/export_dialog.rb +172 -0
- data/lib/alexandria/ui/dialogs/import_dialog.rb +205 -0
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +85 -0
- data/lib/alexandria/ui/dialogs/new_book_dialog.rb +639 -0
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +153 -0
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +67 -0
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +587 -0
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +56 -0
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +432 -0
- data/lib/alexandria/ui/dndable.rb +81 -0
- data/lib/alexandria/ui/gtk_thread_help.rb +88 -0
- data/lib/alexandria/ui/icons.rb +100 -0
- data/lib/alexandria/ui/iconview.rb +91 -0
- data/lib/alexandria/ui/iconview_tooltips.rb +162 -0
- data/lib/alexandria/ui/init.rb +93 -0
- data/lib/alexandria/ui/libraries_combo.rb +75 -0
- data/lib/alexandria/ui/listview.rb +310 -0
- data/lib/alexandria/ui/main_app.rb +67 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +150 -0
- data/lib/alexandria/ui/sidepane.rb +194 -0
- data/lib/alexandria/ui/sound.rb +107 -0
- data/lib/alexandria/ui/ui_manager.rb +1308 -0
- data/lib/alexandria/undo_manager.rb +78 -0
- data/lib/alexandria/utils.rb +30 -0
- data/lib/alexandria/version.rb +24 -0
- data/lib/alexandria/web_themes.rb +75 -0
- data/misc/sounds/README +15 -0
- data/misc/sounds/bad_scan.csd +62 -0
- data/misc/sounds/good_scan.csd +61 -0
- data/misc/sounds/scanning.csd +46 -0
- data/po/ChangeLog +488 -0
- data/po/Makefile +44 -0
- data/po/README +29 -0
- data/po/commit-po +72 -0
- data/po/cs.po +1437 -0
- data/po/cy.po +1521 -0
- data/po/de.po +1400 -0
- data/po/el.po +1379 -0
- data/po/es.po +1376 -0
- data/po/fr.po +1420 -0
- data/po/ga.po +1359 -0
- data/po/gl.po +1397 -0
- data/po/it.po +1406 -0
- data/po/ja.po +1355 -0
- data/po/mk.po +1373 -0
- data/po/nb.po +1386 -0
- data/po/nl.po +1405 -0
- data/po/pl.po +1373 -0
- data/po/pt.po +1398 -0
- data/po/pt_BR.po +1409 -0
- data/po/ru.po +1372 -0
- data/po/sk.po +1380 -0
- data/po/sv.po +1402 -0
- data/po/uk.po +1423 -0
- data/po/zh_TW.po +1394 -0
- data/schemas/alexandria.schemas +300 -0
- data/share/alexandria/glade/acquire_dialog__builder.glade +201 -0
- data/share/alexandria/glade/book_properties_dialog__builder.glade +910 -0
- data/share/alexandria/glade/main_app__builder.glade +229 -0
- data/share/alexandria/glade/new_book_dialog__builder.glade +379 -0
- data/share/alexandria/glade/preferences_dialog__builder.glade +733 -0
- data/share/alexandria/icons/alexandria.png +0 -0
- data/share/alexandria/icons/alexandria_small.png +0 -0
- data/share/alexandria/icons/book.png +0 -0
- data/share/alexandria/icons/book_icon.png +0 -0
- data/share/alexandria/icons/book_small.png +0 -0
- data/share/alexandria/icons/cuecat.png +0 -0
- data/share/alexandria/icons/cuecat_inactive.png +0 -0
- data/share/alexandria/icons/favorite_tag.png +0 -0
- data/share/alexandria/icons/less.png +0 -0
- data/share/alexandria/icons/library.png +0 -0
- data/share/alexandria/icons/library_small.png +0 -0
- data/share/alexandria/icons/lookup.png +0 -0
- data/share/alexandria/icons/more.png +0 -0
- data/share/alexandria/icons/no_cover.png +0 -0
- data/share/alexandria/icons/smart_library.png +0 -0
- data/share/alexandria/icons/smart_library_small.png +0 -0
- data/share/alexandria/icons/star_set.png +0 -0
- data/share/alexandria/icons/star_unset.png +0 -0
- data/share/alexandria/icons/view_as_icons.png +0 -0
- data/share/alexandria/icons/view_as_list.png +0 -0
- data/share/alexandria/ui/menus.xml +91 -0
- data/share/alexandria/ui/popups.xml +91 -0
- data/share/alexandria/web-themes/clean/clean.css +85 -0
- data/share/alexandria/web-themes/clean/preview.jpg +0 -0
- data/share/alexandria/web-themes/list/list.css +105 -0
- data/share/alexandria/web-themes/list/preview.jpg +0 -0
- data/share/app-icon/16x16/alexandria.png +0 -0
- data/share/app-icon/16x16/alexandria.svg +263 -0
- data/share/app-icon/22x22/alexandria.png +0 -0
- data/share/app-icon/22x22/alexandria.svg +465 -0
- data/share/app-icon/24x24/alexandria.png +0 -0
- data/share/app-icon/32x32/alexandria.png +0 -0
- data/share/app-icon/32x32/alexandria.svg +813 -0
- data/share/app-icon/32x32/alexandria.xpm +241 -0
- data/share/app-icon/48x48/alexandria.png +0 -0
- data/share/app-icon/scalable/alexandria.svg +700 -0
- data/share/gnome/help/alexandria/C/about.xml +44 -0
- data/share/gnome/help/alexandria/C/adding-books.xml +339 -0
- data/share/gnome/help/alexandria/C/alexandria.xml +185 -0
- data/share/gnome/help/alexandria/C/bugs.xml +18 -0
- data/share/gnome/help/alexandria/C/editing-book-properties.xml +124 -0
- data/share/gnome/help/alexandria/C/exporting.xml +81 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_acquire_from_scanner_process.png +0 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_add_by_isbn.png +0 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_isbn_import.png +0 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_manual_details.png +0 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_rename_library_after_import.png +0 -0
- data/share/gnome/help/alexandria/C/figures/adding_books_search_results.png +0 -0
- data/share/gnome/help/alexandria/C/figures/editing_book_properties_info.png +0 -0
- data/share/gnome/help/alexandria/C/figures/editing_book_properties_loaning.png +0 -0
- data/share/gnome/help/alexandria/C/figures/exporting_information_html.png +0 -0
- data/share/gnome/help/alexandria/C/figures/getting_started_first_launched.png +0 -0
- data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view.png +0 -0
- data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view_search.png +0 -0
- data/share/gnome/help/alexandria/C/figures/settings_providers_new_z3950.png +0 -0
- data/share/gnome/help/alexandria/C/figures/smart_libraries_new_smart_library.png +0 -0
- data/share/gnome/help/alexandria/C/figures/working_with_libraries_library_pane.png +0 -0
- data/share/gnome/help/alexandria/C/getting-started.xml +154 -0
- data/share/gnome/help/alexandria/C/gnu-fdl-1.2.xml +543 -0
- data/share/gnome/help/alexandria/C/introduction.xml +142 -0
- data/share/gnome/help/alexandria/C/searching.xml +90 -0
- data/share/gnome/help/alexandria/C/settings.xml +140 -0
- data/share/gnome/help/alexandria/C/smart-libraries.xml +160 -0
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +76 -0
- data/share/gnome/help/alexandria/ChangeLog +99 -0
- data/share/gnome/help/alexandria/fr/alexandria.xml +2292 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_add_button.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_isbn_1.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_search_1.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_add_manually.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_add_z3950.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_close_button.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_edit_info.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_export_web_page.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_importing.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_library_pane.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_list_view.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_list_view_search.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_loaning.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_main_window.png +0 -0
- data/share/gnome/help/alexandria/fr/figures/alexandria_remove_button.png +0 -0
- data/share/gnome/help/alexandria/ja/about.xml +33 -0
- data/share/gnome/help/alexandria/ja/adding-books.xml +314 -0
- data/share/gnome/help/alexandria/ja/alexandria.xml +172 -0
- data/share/gnome/help/alexandria/ja/bugs.xml +11 -0
- data/share/gnome/help/alexandria/ja/editing-book-properties.xml +100 -0
- data/share/gnome/help/alexandria/ja/exporting.xml +98 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_acquire_from_scanner_process.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_add_by_isbn.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_isbn_import.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_manual_details.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_rename_library_after_import.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/adding_books_search_results.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/editing_book_properties_info.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/editing_book_properties_loaning.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/exporting_information_html.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/getting_started_first_launched.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view_search.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/settings_providers_new_z3950.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/smart_libraries_new_smart_library.png +0 -0
- data/share/gnome/help/alexandria/ja/figures/working_with_libraries_library_pane.png +0 -0
- data/share/gnome/help/alexandria/ja/getting-started.xml +144 -0
- data/share/gnome/help/alexandria/ja/gnu-fdl-1.2.xml +541 -0
- data/share/gnome/help/alexandria/ja/introduction.xml +134 -0
- data/share/gnome/help/alexandria/ja/searching.xml +104 -0
- data/share/gnome/help/alexandria/ja/settings.xml +129 -0
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +140 -0
- data/share/gnome/help/alexandria/ja/working-with-libraries.xml +88 -0
- data/share/menu/alexandria +7 -0
- data/share/omf/alexandria/alexandria-C.omf.in +27 -0
- data/share/omf/alexandria/alexandria-fr.omf.in +30 -0
- data/share/sounds/alexandria/bad_scan.ogg +0 -0
- data/share/sounds/alexandria/bad_scan.wav +0 -0
- data/share/sounds/alexandria/good_scan.ogg +0 -0
- data/share/sounds/alexandria/good_scan.wav +0 -0
- data/share/sounds/alexandria/scanning.ogg +0 -0
- data/share/sounds/alexandria/scanning.wav +0 -0
- data/spec/alexandria/library_spec.rb +205 -0
- data/spec/alexandria/preferences_spec.rb +22 -0
- data/spec/alexandria/scanners/cuecat_spec.rb +68 -0
- data/spec/alexandria/smart_library_spec.rb +22 -0
- data/spec/alexandria/ui/dialogs_spec.rb +90 -0
- data/spec/alexandria/ui/iconview_spec.rb +27 -0
- data/spec/alexandria/ui/listview_spec.rb +28 -0
- data/spec/alexandria/ui/main_app_spec.rb +48 -0
- data/spec/alexandria/ui/sidepane_spec.rb +27 -0
- data/spec/alexandria/ui/ui_manager_spec.rb +26 -0
- data/spec/alexandria/ui/ui_utilities_spec.rb +60 -0
- data/spec/alexandria/utilities_spec.rb +50 -0
- data/spec/data/libraries/0.6.1-noisbn/My Library/0201398257.yaml +10 -0
- data/spec/data/libraries/0.6.1-noisbn/My Library/1565920007.yaml +10 -0
- data/spec/data/libraries/0.6.1/My Library/0192812173.yaml +9 -0
- data/spec/data/libraries/0.6.1/My Library/0201398257.cover +0 -0
- data/spec/data/libraries/0.6.1/My Library/0201398257.yaml +10 -0
- data/spec/data/libraries/0.6.1/My Library/1565920007.yaml +10 -0
- data/spec/data/libraries/0.6.2/My Library/9780140266146.cover +0 -0
- data/spec/data/libraries/0.6.2/My Library/9780140266146.yaml +16 -0
- data/spec/data/libraries/0.6.2/My Library/9780140278781.cover +0 -0
- data/spec/data/libraries/0.6.2/My Library/9780140278781.yaml +21 -0
- data/spec/data/libraries/0.6.2/My Library/9780571147168.cover +0 -0
- data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +20 -0
- data/spec/data/libraries/0.6.2/My Library/9780575079038.cover +0 -0
- data/spec/data/libraries/0.6.2/My Library/9780575079038.yaml +20 -0
- data/spec/data/libraries/0.6.2/My Library/9780755322800.cover +0 -0
- data/spec/data/libraries/0.6.2/My Library/9780755322800.yaml +20 -0
- data/spec/spec_helper.rb +46 -0
- data/tasks/rdoc.rake +6 -0
- data/tasks/setup.rb +30 -0
- data/tasks/spec.rake +29 -0
- data/tasks/test.rake +38 -0
- data/test/application_test.rb +39 -0
- data/test/book_test.rb +34 -0
- data/test/data/isbns.txt +3 -0
- data/test/isbn_test.rb +68 -0
- data/test/providers_test.rb +254 -0
- data/test/test_helper.rb +42 -0
- data/util/rake/fileinstall.rb +313 -0
- data/util/rake/gettextgenerate.rb +158 -0
- data/util/rake/omfgenerate.rb +79 -0
- metadata +452 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
# Copyright (C) 2009 Cathal Mc Ginley
|
2
|
+
# Copyright (C) 2010 Martin Sucha
|
3
|
+
#
|
4
|
+
# Alexandria is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU General Public License as
|
6
|
+
# published by the Free Software Foundation; either version 2 of the
|
7
|
+
# License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# Alexandria is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public
|
15
|
+
# License along with Alexandria; see the file COPYING. If not,
|
16
|
+
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
17
|
+
# Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
+
|
19
|
+
module Alexandria
|
20
|
+
# A really simple regex-based parser to grab data out of marc text records.
|
21
|
+
class PseudoMarcParser
|
22
|
+
BNF_FR_MAPPINGS = {
|
23
|
+
title: ['200', 'a'],
|
24
|
+
authors: ['700', 'a'],
|
25
|
+
isbn: ['010', 'a'],
|
26
|
+
publisher: ['210', 'g'],
|
27
|
+
year: ['210', 'd'],
|
28
|
+
binding: ['225', 'a'],
|
29
|
+
notes: ['520', 'a']
|
30
|
+
}
|
31
|
+
|
32
|
+
USMARC_MAPPINGS = {
|
33
|
+
title: ['245', 'a', 'b'],
|
34
|
+
authors: ['100', 'a'],
|
35
|
+
isbn: ['020', 'a'],
|
36
|
+
publisher: ['490', 'a'],
|
37
|
+
year: ['260', 'c'],
|
38
|
+
binding: ['020', 'a'], # listed with isbn here
|
39
|
+
notes: ['520', 'a']
|
40
|
+
}
|
41
|
+
|
42
|
+
def self.get_fields(data, type, stripping, m = USMARC_MAPPINGS)
|
43
|
+
field = ''
|
44
|
+
m[type][1..m[type].length - 1].each do |part|
|
45
|
+
if data.first[part]
|
46
|
+
part_data = data.first[part].strip
|
47
|
+
if part_data =~ stripping
|
48
|
+
part_data = Regexp.last_match[1]
|
49
|
+
part_data = part_data.strip
|
50
|
+
end
|
51
|
+
if field != ''
|
52
|
+
field += ': '
|
53
|
+
end
|
54
|
+
field += part_data
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if field == ''
|
58
|
+
field = nil
|
59
|
+
end
|
60
|
+
field
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.marc_text_to_book(marc, m = USMARC_MAPPINGS)
|
64
|
+
details = marc_text_to_details(marc)
|
65
|
+
unless details.empty?
|
66
|
+
title = nil
|
67
|
+
title_data = details[m[:title][0]]
|
68
|
+
if title_data
|
69
|
+
title_data_all = get_fields(title_data, :title, /(.*)[\/:]$/, m)
|
70
|
+
if title_data_all
|
71
|
+
title = title_data_all
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
authors = []
|
76
|
+
author_data = details[m[:authors][0]]
|
77
|
+
if author_data
|
78
|
+
author_data.each do |ad|
|
79
|
+
author = ad[m[:authors][1]]
|
80
|
+
if author
|
81
|
+
author = author.strip
|
82
|
+
if author =~ /(.*),$/
|
83
|
+
author = Regexp.last_match[1]
|
84
|
+
end
|
85
|
+
authors << author
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
isbn = nil
|
91
|
+
binding = nil
|
92
|
+
isbn_data = details[m[:isbn][0]]
|
93
|
+
if isbn_data
|
94
|
+
if isbn_data.first[m[:isbn][1]] =~ /([-0-9xX]+)/
|
95
|
+
isbn = Regexp.last_match[1]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
binding_data = details[m[:binding][0]]
|
100
|
+
if binding_data
|
101
|
+
if binding_data.first[m[:binding][1]] =~ /([a-zA-Z][a-z\s]+[a-z])/
|
102
|
+
binding = Regexp.last_match[1]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
publisher = nil
|
107
|
+
publisher_data = details[m[:publisher][0]]
|
108
|
+
if publisher_data
|
109
|
+
publisher = publisher_data.first[m[:publisher][1]]
|
110
|
+
end
|
111
|
+
|
112
|
+
year = nil
|
113
|
+
publication_data = details[m[:year][0]]
|
114
|
+
if publication_data
|
115
|
+
year = publication_data.first[m[:year][1]]
|
116
|
+
if year =~ /(\d+)/
|
117
|
+
year = Regexp.last_match[1].to_i
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
notes = ''
|
122
|
+
notes_data = details[m[:notes][0]]
|
123
|
+
if notes_data
|
124
|
+
notes_data.each do |note|
|
125
|
+
txt = note[m[:notes][1]]
|
126
|
+
if txt
|
127
|
+
notes += txt
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
if title.nil? and isbn.nil?
|
133
|
+
# probably didn't undertand the MARC dialect
|
134
|
+
return nil
|
135
|
+
end
|
136
|
+
|
137
|
+
book = Alexandria::Book.new(title, authors, isbn,
|
138
|
+
publisher, year, binding)
|
139
|
+
book.notes = notes unless notes.empty?
|
140
|
+
book
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.marc_text_to_details(marc)
|
145
|
+
details = {}
|
146
|
+
marc.each_line do |line|
|
147
|
+
if line =~ /(\d+)\s*(.+)/
|
148
|
+
code = Regexp.last_match[1]
|
149
|
+
data = Regexp.last_match[2]
|
150
|
+
|
151
|
+
this_line_data = {}
|
152
|
+
|
153
|
+
# puts code
|
154
|
+
# puts data
|
155
|
+
d_idx = 0
|
156
|
+
while d_idx < data.size
|
157
|
+
d_str = data[d_idx..-1]
|
158
|
+
# puts d_str
|
159
|
+
if (idx = d_str =~ /\$([a-z]) ([^\$]+)/)
|
160
|
+
# puts idx
|
161
|
+
sub_code = Regexp.last_match[1]
|
162
|
+
sub_data = Regexp.last_match[2]
|
163
|
+
this_line_data[sub_code] = sub_data
|
164
|
+
# puts " " + $1
|
165
|
+
# puts " " + $2
|
166
|
+
# puts idx
|
167
|
+
d_idx += idx + 2 # (2 extra to push beyond this '$a' etc.)
|
168
|
+
else
|
169
|
+
break
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
unless this_line_data.empty?
|
174
|
+
unless details.key?(code)
|
175
|
+
details[code] = []
|
176
|
+
end
|
177
|
+
details[code] << this_line_data
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
details
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# Copyright (C) 2005-2006-2006 Mathieu Leduc-Hamel
|
2
|
+
#
|
3
|
+
# Alexandria is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU General Public License as
|
5
|
+
# published by the Free Software Foundation; either version 2 of the
|
6
|
+
# License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# Alexandria is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public
|
14
|
+
# License along with Alexandria; see the file COPYING. If not,
|
15
|
+
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
16
|
+
# Fifth Floor, Boston, MA 02110-1301 USA.
|
17
|
+
|
18
|
+
# http://en.wikipedia.org/wiki/Renaud-Bray
|
19
|
+
|
20
|
+
require 'net/http'
|
21
|
+
require 'cgi'
|
22
|
+
|
23
|
+
module Alexandria
|
24
|
+
class BookProviders
|
25
|
+
class RENAUDProvider < GenericProvider
|
26
|
+
include GetText
|
27
|
+
# GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
|
28
|
+
BASE_URI = 'http://www.renaud-bray.com/'
|
29
|
+
ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
super('RENAUD', 'Renaud-Bray (Canada)')
|
33
|
+
end
|
34
|
+
|
35
|
+
def search(criterion, type)
|
36
|
+
criterion = criterion.convert('ISO-8859-1', 'UTF-8')
|
37
|
+
req = BASE_URI + 'francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri='
|
38
|
+
# req = BASE_URI + "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri="
|
39
|
+
req += case type
|
40
|
+
when SEARCH_BY_ISBN
|
41
|
+
'ISBN'
|
42
|
+
when SEARCH_BY_TITLE
|
43
|
+
'Titre'
|
44
|
+
when SEARCH_BY_AUTHORS
|
45
|
+
'Auteur'
|
46
|
+
when SEARCH_BY_KEYWORD
|
47
|
+
''
|
48
|
+
else
|
49
|
+
raise InvalidSearchTypeError
|
50
|
+
end
|
51
|
+
req += '&Phrase='
|
52
|
+
|
53
|
+
req += CGI.escape(criterion)
|
54
|
+
p req if $DEBUG
|
55
|
+
data = transport.get(URI.parse(req))
|
56
|
+
begin
|
57
|
+
if type == SEARCH_BY_ISBN
|
58
|
+
return to_books(data).pop
|
59
|
+
else
|
60
|
+
results = []
|
61
|
+
to_books(data).each {|book|
|
62
|
+
results << book
|
63
|
+
}
|
64
|
+
while /Suivant/.match(data)
|
65
|
+
md = /Enteterouge\">([\d]*)<\/b>/.match(data)
|
66
|
+
num = md[1].to_i + 1
|
67
|
+
data = transport.get(URI.parse(req + '&PageActuelle=' + num.to_s))
|
68
|
+
to_books(data).each {|book|
|
69
|
+
results << book
|
70
|
+
}
|
71
|
+
end
|
72
|
+
return results
|
73
|
+
end
|
74
|
+
rescue
|
75
|
+
raise NoResultsError
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def url(book)
|
80
|
+
# "http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=" + book.isbn
|
81
|
+
'http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=' + book.isbn
|
82
|
+
end
|
83
|
+
|
84
|
+
#######
|
85
|
+
private
|
86
|
+
#######
|
87
|
+
|
88
|
+
def to_books(data)
|
89
|
+
data = CGI.unescapeHTML(data)
|
90
|
+
data = data.convert('UTF-8', 'ISO-8859-1')
|
91
|
+
raise NoResultsError if /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong>/.match(data)
|
92
|
+
|
93
|
+
titles = []
|
94
|
+
data.scan(/"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/).each {|md|
|
95
|
+
titles << md[1].strip
|
96
|
+
}
|
97
|
+
raise if titles.empty?
|
98
|
+
authors = []
|
99
|
+
data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each {|md|
|
100
|
+
authors2 = []
|
101
|
+
for author in md[0].split(' ')
|
102
|
+
authors2 << author.strip
|
103
|
+
end
|
104
|
+
authors << authors2
|
105
|
+
}
|
106
|
+
raise if authors.empty?
|
107
|
+
isbns = []
|
108
|
+
data.scan(/ISBN : ?<\/td><td>(\d+)/).each {|md|
|
109
|
+
isbns << md[0].strip
|
110
|
+
}
|
111
|
+
raise if isbns.empty?
|
112
|
+
editions = []
|
113
|
+
publish_years = []
|
114
|
+
data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each {|md|
|
115
|
+
editions << md[0].strip
|
116
|
+
publish_years << md[0].strip.split(/-/)[0].to_i
|
117
|
+
}
|
118
|
+
raise if editions.empty? or publish_years.empty?
|
119
|
+
publishers = []
|
120
|
+
data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each {|md|
|
121
|
+
publishers << md[0].strip
|
122
|
+
}
|
123
|
+
raise if publishers.empty?
|
124
|
+
book_covers = []
|
125
|
+
data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))|\/francais\/suggestion\/images\/livre\/livre.gif)/).each {|md|
|
126
|
+
book_covers << BASE_URI + md[0].strip
|
127
|
+
}
|
128
|
+
raise if book_covers.empty?
|
129
|
+
|
130
|
+
books = []
|
131
|
+
titles.each_with_index {|title, i|
|
132
|
+
books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
|
133
|
+
book_covers[i]]
|
134
|
+
# print books
|
135
|
+
}
|
136
|
+
raise if books.empty?
|
137
|
+
|
138
|
+
books
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
# Copyright (C) 2004 Laurent Sansonetti
|
2
|
+
# Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
|
3
|
+
# Copyright (C) 2009 Cathal Mc Ginley
|
4
|
+
# Copyright (C) 2011, 2014 Matijs van Zuijlen
|
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.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public
|
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.
|
20
|
+
|
21
|
+
# Adapted code from 'bn.rb' (I hope that it works!)
|
22
|
+
|
23
|
+
# Almost completely rewritten by Cathal Mc Ginley (21 Feb 2009)
|
24
|
+
# based on the new code for Palatina
|
25
|
+
|
26
|
+
require 'net/http'
|
27
|
+
require 'cgi'
|
28
|
+
require 'alexandria/book_providers/web'
|
29
|
+
|
30
|
+
module Alexandria
|
31
|
+
class BookProviders
|
32
|
+
class SicilianoProvider < WebsiteBasedProvider
|
33
|
+
include Logging
|
34
|
+
|
35
|
+
SITE = 'http://www.siciliano.com.br'
|
36
|
+
|
37
|
+
# The string interpolations in this URL are the search term and search
|
38
|
+
# type, respectively.
|
39
|
+
BASE_SEARCH_URL = "#{SITE}/pesquisaweb/pesquisaweb.dll/pesquisa?" \
|
40
|
+
'&FIL_ID=102' \
|
41
|
+
'&PALAVRASN1=%s' \
|
42
|
+
'&FILTRON1=%s' \
|
43
|
+
'&ESTRUTN1=0301&ORDEMN2=E'
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
super('Siciliano', 'Livraria Siciliano (Brasil)')
|
47
|
+
# no preferences for the moment
|
48
|
+
prefs.read
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_book_from_search_result(result)
|
52
|
+
log.info { "Fetching book from #{result[:url]}" }
|
53
|
+
html_data = transport.get(URI.parse(result[:url]))
|
54
|
+
parse_result_data(html_data, result)
|
55
|
+
end
|
56
|
+
|
57
|
+
def search(criterion, type)
|
58
|
+
begin
|
59
|
+
criterion = criterion.convert('ISO-8859-1', 'UTF-8') # still needed??
|
60
|
+
rescue GLib::ConvertError
|
61
|
+
log.info { "Cannot search for non-ISO-8859-1 terms at Siciliano : #{criterion}" }
|
62
|
+
raise NoResultsError
|
63
|
+
end
|
64
|
+
trying_again = false
|
65
|
+
begin
|
66
|
+
req = create_search_uri(type, criterion, trying_again)
|
67
|
+
log.debug { "#{name} #{trying_again ? 'retrying ' : ''}request = #{req}" }
|
68
|
+
data = transport.get(URI.parse(req))
|
69
|
+
results = parse_search_result_data(data)
|
70
|
+
raise NoResultsError if results.empty?
|
71
|
+
|
72
|
+
if type == SEARCH_BY_ISBN
|
73
|
+
get_book_from_search_result(results.first)
|
74
|
+
else
|
75
|
+
results.map { |result| get_book_from_search_result(result) }
|
76
|
+
end
|
77
|
+
|
78
|
+
rescue NoResultsError => err
|
79
|
+
if (type == SEARCH_BY_ISBN) and (trying_again == false)
|
80
|
+
trying_again = true
|
81
|
+
retry
|
82
|
+
else
|
83
|
+
raise err
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# the new Siciliano website no longer has direct links to books by their ISBN
|
89
|
+
# (the permalink now seems to be based on the product id)
|
90
|
+
def url(_book)
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def create_search_uri(search_type, search_term, trying_again = false)
|
97
|
+
search_type_code = { SEARCH_BY_ISBN => 'G',
|
98
|
+
SEARCH_BY_TITLE => 'A',
|
99
|
+
SEARCH_BY_AUTHORS => 'B',
|
100
|
+
SEARCH_BY_KEYWORD => 'X'
|
101
|
+
}[search_type] or 'X'
|
102
|
+
search_term_encoded = search_term
|
103
|
+
if search_type == SEARCH_BY_ISBN
|
104
|
+
if trying_again
|
105
|
+
# on second attempt, try ISBN-10...
|
106
|
+
search_term_encoded = Library.canonicalise_isbn(search_term) # isbn-10
|
107
|
+
else
|
108
|
+
# search by ISBN-13 first
|
109
|
+
search_term_encoded = Library.canonicalise_ean(search_term) # isbn-13
|
110
|
+
end
|
111
|
+
else
|
112
|
+
search_term_encoded = CGI.escape(search_term)
|
113
|
+
end
|
114
|
+
|
115
|
+
BASE_SEARCH_URL % [search_term_encoded, search_type_code]
|
116
|
+
end
|
117
|
+
|
118
|
+
def parse_search_result_data(html)
|
119
|
+
# The layout...
|
120
|
+
# td[@class="normal"]
|
121
|
+
# span[@class="vitrine_nome_produto"]
|
122
|
+
# a (title and link to 'product page')
|
123
|
+
# br
|
124
|
+
# TEXT --> author / publisher
|
125
|
+
# br
|
126
|
+
# div[@class="vitrine_preco_por"] (price info)
|
127
|
+
|
128
|
+
doc = html_to_doc(html)
|
129
|
+
book_search_results = []
|
130
|
+
# each result will be a dict with keys :title, :author, :publisher, :url
|
131
|
+
|
132
|
+
list_items = doc.search('div.pesquisa-item-lista-conteudo')
|
133
|
+
list_items.each do |item|
|
134
|
+
begin
|
135
|
+
result = {}
|
136
|
+
|
137
|
+
# author & publisher
|
138
|
+
author_publisher = ''
|
139
|
+
item.children.each do |node|
|
140
|
+
author_publisher += node.to_s if node.text?
|
141
|
+
author_publisher.strip!
|
142
|
+
break unless author_publisher.empty?
|
143
|
+
end
|
144
|
+
author, publisher = author_publisher.split('/')
|
145
|
+
result[:author] = author.strip if author
|
146
|
+
result[:publisher] = publisher.strip if publisher
|
147
|
+
|
148
|
+
# title & url
|
149
|
+
link = item % 'a'
|
150
|
+
result[:title] = link.inner_text.strip
|
151
|
+
link_to_description = link['href']
|
152
|
+
slash = ''
|
153
|
+
unless link_to_description =~ /^\//
|
154
|
+
slash = '/'
|
155
|
+
end
|
156
|
+
result[:url] = "#{SITE}#{slash}#{link_to_description}"
|
157
|
+
|
158
|
+
book_search_results << result
|
159
|
+
rescue => ex
|
160
|
+
trace = ex.backtrace.join("\n> ")
|
161
|
+
log.error { "Failed parsing Siciliano search page #{ex.message}\n#{trace}" }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
book_search_results
|
166
|
+
end
|
167
|
+
|
168
|
+
def parse_result_data(html, search_result)
|
169
|
+
# checked against Siciliano website 21 Feb 2009
|
170
|
+
doc = html_to_doc(html)
|
171
|
+
# title
|
172
|
+
title_div = doc % 'div#conteudo//div.titulo'
|
173
|
+
raise NoResultsError unless title_div
|
174
|
+
title_h = title_div % 'h2'
|
175
|
+
title = title_h.inner_text if title_h
|
176
|
+
# title = first_non_empty_text_node(title_div)
|
177
|
+
# author_spans = doc/'span.rotulo'
|
178
|
+
author_hs = title_div / 'h3.autor'
|
179
|
+
authors = []
|
180
|
+
author_hs.each do |h|
|
181
|
+
authors << h.inner_text.strip
|
182
|
+
end
|
183
|
+
## synopsis_div = doc % 'div#sinopse'
|
184
|
+
details_div = doc % 'div#tab-caracteristica'
|
185
|
+
details = string_array_to_map(lines_of_text_as_array(details_div))
|
186
|
+
# ISBN
|
187
|
+
isbn = details['ISBN']
|
188
|
+
## ean = details["CdBarras"]
|
189
|
+
translator = details['Tradutor']
|
190
|
+
if translator
|
191
|
+
authors << translator
|
192
|
+
end
|
193
|
+
binding = details['Acabamento']
|
194
|
+
publisher = search_result[:publisher]
|
195
|
+
# publish year
|
196
|
+
publish_year = nil
|
197
|
+
edition = details['Edio']
|
198
|
+
if edition
|
199
|
+
if edition =~ /([12][0-9]{3})/ # publication date
|
200
|
+
publish_year = Regexp.last_match[1].to_i
|
201
|
+
end
|
202
|
+
end
|
203
|
+
# cover
|
204
|
+
# ImgSrc[1]="/imagem/imagem.dll?pro_id=1386929&PIM_Id=658849";
|
205
|
+
image_urls = []
|
206
|
+
(doc / 'script').each do |script|
|
207
|
+
next if script.children.nil?
|
208
|
+
script.children.each do |ch|
|
209
|
+
ch_text = ch.to_s
|
210
|
+
if ch_text =~ /ImgSrc\[[\d]\]="(.+)";/
|
211
|
+
img_link = Regexp.last_match[1]
|
212
|
+
image_urls << img_link
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
book = Book.new(title, authors, isbn, publisher, publish_year, binding)
|
217
|
+
result = [book, image_urls.first]
|
218
|
+
return result
|
219
|
+
rescue => ex
|
220
|
+
trace = ex.backtrace.join("\n> ")
|
221
|
+
log.error { "Failed parsing Siciliano product page #{ex.message}\n#{trace}" }
|
222
|
+
return nil
|
223
|
+
end
|
224
|
+
|
225
|
+
def first_non_empty_text_node(elem)
|
226
|
+
text = ''
|
227
|
+
elem.children.each do |node|
|
228
|
+
next unless node.text?
|
229
|
+
text = node.to_s.strip
|
230
|
+
break unless text.empty?
|
231
|
+
end
|
232
|
+
text
|
233
|
+
end
|
234
|
+
|
235
|
+
def lines_of_text_as_array(elem)
|
236
|
+
lines = []
|
237
|
+
current_text = ''
|
238
|
+
elem.children.each do |e|
|
239
|
+
if e.text?
|
240
|
+
current_text += e.to_s
|
241
|
+
elsif e.name == 'br'
|
242
|
+
lines << current_text.strip
|
243
|
+
current_text = ''
|
244
|
+
else
|
245
|
+
current_text += e.inner_text
|
246
|
+
end
|
247
|
+
end
|
248
|
+
lines << current_text.strip
|
249
|
+
lines.delete('')
|
250
|
+
lines
|
251
|
+
end
|
252
|
+
|
253
|
+
def string_array_to_map(arr)
|
254
|
+
map = {}
|
255
|
+
arr.each do |str|
|
256
|
+
key, val = str.split(':')
|
257
|
+
# a real hack for not handling encoding properly :^)
|
258
|
+
if val
|
259
|
+
map[key.gsub(/[^a-zA-Z]/, '')] = val.strip
|
260
|
+
end
|
261
|
+
end
|
262
|
+
map
|
263
|
+
end
|
264
|
+
|
265
|
+
# def binding_type(binding) # portuguese string
|
266
|
+
# {"brochura" => :paperback,
|
267
|
+
# "encadernado" => :hardback}[binding.downcase] or :unknown
|
268
|
+
# end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|