diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-09-13 22:07:10 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-09-14 12:03:04 (GMT) |
commit | e80bcb51ae2a589410f9955fcd8a484bb417d55e (patch) | |
tree | a703806aad45c59c3b285fb4b2ff76926a01017c | |
parent | aa2ed57a34a1dc4bd5544202b5534a35abbed341 (diff) |
Read Internet Archive catalogs
Internet Archive publish catalog with a different format.
Signed-off-by: Daniel Castelo <dcastelo@plan.ceibal.edu.uy>
-rw-r--r-- | GetIABooksActivity.py | 55 | ||||
-rw-r--r-- | get-books.cfg | 4 | ||||
-rw-r--r-- | opds.py | 16 |
3 files changed, 53 insertions, 22 deletions
diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py index 9dba0f4..371ea79 100644 --- a/GetIABooksActivity.py +++ b/GetIABooksActivity.py @@ -81,7 +81,7 @@ class GetIABooksActivity(activity.Activity): self.show_images = True self.languages = {} self._lang_code_handler = languagenames.LanguageNames() - self.catalogs = {} + self.catalogs_configuration = {} self.catalog_history = [] if os.path.exists('/etc/get-books.cfg'): @@ -221,7 +221,11 @@ class GetIABooksActivity(activity.Activity): catalog_config['name'] = catalog catalog_config['summary_field'] = \ source_config['summary_field'] - self.catalogs[catalog] = catalog_config + self.catalogs_configuration[catalog] = catalog_config + + self.source = _SOURCES_CONFIG.keys()[0] + + self.filter_catalogs_by_source() logging.error('languages %s', self.languages) logging.error('catalogs %s', self.catalogs) @@ -495,16 +499,8 @@ class GetIABooksActivity(activity.Activity): self.bt_move_up_catalog.hide_image() self.treecol.set_widget(self.bt_move_up_catalog) - if len(self.catalogs) > 0: - self.catalog_history.append({'title': _('Catalogs'), - 'catalogs': self.catalogs}) - self.categories = [] - self.path_iter = {} - for key in self.catalogs.keys(): - self.categories.append({'text': key, 'dentro': []}) - self.treemodel.clear() - for p in self.categories: - self.path_iter[p['text']] = self.treemodel.append([p['text']]) + self.load_source_catalogs() + self.tree_scroller = Gtk.ScrolledWindow(hadjustment=None, vadjustment=None) self.tree_scroller.set_policy(Gtk.PolicyType.NEVER, @@ -597,6 +593,29 @@ class GetIABooksActivity(activity.Activity): if len(self.catalogs) > 0: self.bt_catalogs.set_active(True) + def filter_catalogs_by_source(self): + self.catalogs = {} + for catalog_key in self.catalogs_configuration: + catalog = self.catalogs_configuration[catalog_key] + if catalog['source'] == self.source: + self.catalogs[catalog_key] = catalog + + def load_source_catalogs(self): + self.filter_catalogs_by_source() + + if len(self.catalogs) > 0: + self.categories = [] + self.path_iter = {} + self.catalog_history = [] + self.catalog_history.append({'title': _('Catalogs'), + 'catalogs': self.catalogs}) + for key in self.catalogs.keys(): + self.categories.append({'text': key, 'dentro': []}) + self.treemodel.clear() + + for p in self.categories: + self.path_iter[p['text']] = self.treemodel.append([p['text']]) + def can_close(self): if self.queryresults is not None: self.queryresults.cancel() @@ -882,13 +901,11 @@ class GetIABooksActivity(activity.Activity): self.find_books(search_terms) # enable/disable catalogs button if configuration is available self.source = self._books_toolbar.source_combo.props.value - have_catalogs = False - for catalog_name in self.catalogs.keys(): - catalog_config = self.catalogs[catalog_name] - if catalog_config['source'] == self.source: - have_catalogs = True - break - if have_catalogs: + + # Get catalogs for this source + self.load_source_catalogs() + + if len(self.catalogs) > 0: self.bt_catalogs.show() self.bt_catalogs.set_active(True) else: diff --git a/get-books.cfg b/get-books.cfg index dd07716..385403a 100644 --- a/get-books.cfg +++ b/get-books.cfg @@ -22,4 +22,6 @@ Public Domain Books = http://www.feedbooks.com/publicdomain/catalog.atom name = Internet Archive query_uri = http://bookserver.archive.org/catalog/opensearch?q= opds_cover = http://opds-spec.org/image -#opds_cover = http://opds-spec.org/image/thumbnail + +[Catalogs_Internet Archive] +Index = http://bookserver.archive.org/catalog/ @@ -38,6 +38,8 @@ _REL_OPDS_ACQUISTION = u'http://opds-spec.org/acquisition' _REL_SUBSECTION = 'subsection' _REL_OPDS_POPULAR = u'http://opds-spec.org/sort/popular' _REL_OPDS_NEW = u'http://opds-spec.org/sort/new' +_REL_ALTERNATE = 'alternate' +_REL_CRAWLABLE = 'http://opds-spec.org/crawlable' GObject.threads_init() @@ -91,10 +93,18 @@ class DownloadThread(threading.Thread): else: feedobj = feedparser.parse(self.obj._uri) + # Get catalog Type + CATALOG_TYPE = 'COMMON' + if 'links' in feedobj['feed']: + for link in feedobj['feed']['links']: + if link['rel'] == _REL_CRAWLABLE: + CATALOG_TYPE = 'CRAWLABLE' + break + for entry in feedobj['entries']: - if entry_type(entry) == 'BOOK': + if entry_type(entry) == 'BOOK' and CATALOG_TYPE is not 'CRAWLABLE': self.obj._booklist.append(Book(self.obj._configuration, entry)) - elif entry_type(entry) == 'CATALOG': + elif entry_type(entry) == 'CATALOG' or CATALOG_TYPE == 'CRAWLABLE': self.obj._cataloglist.append( \ Book(self.obj._configuration, entry)) @@ -147,6 +157,8 @@ class Book(object): elif link['rel'] in \ [_REL_OPDS_POPULAR, _REL_OPDS_NEW, _REL_SUBSECTION]: ret[link['type']] = link['href'] + elif link['rel'] == _REL_ALTERNATE: + ret[link['type']] = link['href'] else: pass return ret |