From 47ef1650b99cc626398fb80e87c7992817ef9ceb Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Sat, 11 Jun 2011 02:00:09 +0000 Subject: Implementation of dynamic catalogs The combo with the list of catalogs is updated with the info from the opds querys. Signed-off-by: Daniel Castelo Acked-by: Gonzalo Odiard --- diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py index fa31a87..c1b9f78 100755..100644 --- a/GetIABooksActivity.py +++ b/GetIABooksActivity.py @@ -197,7 +197,8 @@ class GetIABooksActivity(activity.Activity): repo_config['query_uri'] = config.get(section, 'query_uri') repo_config['opds_cover'] = config.get(section, 'opds_cover') if config.has_option(section, 'summary_field'): - repo_config['summary_field'] = config.get(section, 'summary_field') + repo_config['summary_field'] = \ + config.get(section, 'summary_field') else: repo_config['summary_field'] = None _SOURCES_CONFIG[section] = repo_config @@ -219,6 +220,9 @@ class GetIABooksActivity(activity.Activity): catalog_config['query_uri'] = config.get(section, catalog) catalog_config['opds_cover'] = opds_cover catalog_config['source'] = catalog_source + catalog_config['name'] = catalog + catalog_config['summary_field'] = \ + source_config['summary_field'] self.catalogs[catalog] = catalog_config logging.error('languages %s', self.languages) @@ -262,20 +266,19 @@ class GetIABooksActivity(activity.Activity): self.__language_changed_cb) if len(self.catalogs) > 0: - bt_catalogs = ToolButton('catalogs') - bt_catalogs.set_tooltip(_('Catalogs')) - - toolbar.insert(bt_catalogs, -1) - bt_catalogs.show() - palette = bt_catalogs.get_palette() + self.bt_catalogs = ToolButton('catalogs') + self.bt_catalogs.set_tooltip(_('Catalogs')) + toolbar.insert(self.bt_catalogs, -1) + self.bt_catalogs.show() + palette = self.bt_catalogs.get_palette() for key in self.catalogs.keys(): menu_item = MenuItem(key) menu_item.connect('activate', self.__activate_catalog_cb, self.catalogs[key]) palette.menu.append(menu_item) menu_item.show() - bt_catalogs.connect('clicked',self.__bt_catalogs_clicked_cb) + self.bt_catalogs.connect('clicked', self.__bt_catalogs_clicked_cb) self._device_manager = devicemanager.DeviceManager() self._refresh_sources(toolbar) @@ -299,8 +302,8 @@ class GetIABooksActivity(activity.Activity): self.listview.clear() logging.error('SOURCE %s', catalog_config['source']) self._books_toolbar.search_entry.props.text = '' - source = catalog_config['source'] - position = _SOURCES_CONFIG[source]['position'] + self.source = catalog_config['source'] + position = _SOURCES_CONFIG[self.source]['position'] self._books_toolbar.source_combo.set_active(position) if self.queryresults is not None: @@ -680,9 +683,13 @@ class GetIABooksActivity(activity.Activity): def __query_updated_cb(self, query, midway): logging.debug('__query_updated_cb midway %s', midway) self.listview.populate(self.queryresults) - if len(self.queryresults) == 0: + if (len(self.queryresults.get_catalog_list()) > 0): + self.show_message(_('New catalog list %s was found') \ + % self.queryresults._configuration["name"]) + self.catalogs_updated(query, midway) + elif len(self.queryresults) == 0: self.show_message(_('Sorry, no books could be found.')) - elif not midway: + if not midway and len(self.queryresults) > 0: self.hide_message() query_language = self.get_query_language() logging.error('LANGUAGE %s', query_language) @@ -700,6 +707,35 @@ class GetIABooksActivity(activity.Activity): self.window.set_cursor(None) self._allow_suspend() + def catalogs_updated(self, query, midway): + self.catalogs = {} + for catalog_item in self.queryresults.get_catalog_list(): + catalog_config = {} + download_link = '' + download_links = catalog_item.get_download_links() + for link in download_links.keys(): + download_link = download_links[link] + break + catalog_config['query_uri'] = download_link + catalog_config['opds_cover'] = \ + catalog_item._configuration['opds_cover'] + catalog_config['source'] = catalog_item._configuration['source'] + catalog_config['name'] = catalog_item.get_title() + catalog_config['summary_field'] = \ + catalog_item._configuration['summary_field'] + self.catalogs[catalog_item.get_title().strip()] = catalog_config + + if len(self.catalogs) > 0: + palette = self.bt_catalogs.get_palette() + for menu_item in palette.menu.get_children(): + palette.menu.remove(menu_item) + for key in self.catalogs.keys(): + menu_item = MenuItem(key) + menu_item.connect('activate', + self.__activate_catalog_cb, self.catalogs[key]) + palette.menu.append(menu_item) + menu_item.show() + def __source_changed_cb(self, widget): search_terms = self.get_search_terms() if search_terms == '': @@ -753,7 +789,7 @@ class GetIABooksActivity(activity.Activity): self._getter.connect("finished", self._get_book_result_cb) self._getter.connect("progress", self._get_book_progress_cb) self._getter.connect("error", self._get_book_error_cb) - _logger.debug("Starting download from %s to %s" % (url,path)) + _logger.debug("Starting download from %s to %s" % (url, path)) try: self._getter.start(path) except: diff --git a/activity/get-ia-books.svg b/activity/get-ia-books.svg index 53b5f55..53b5f55 100755..100644 --- a/activity/get-ia-books.svg +++ b/activity/get-ia-books.svg diff --git a/get-books.cfg b/get-books.cfg index 8309aa5..f1c642b 100644 --- a/get-books.cfg +++ b/get-books.cfg @@ -14,6 +14,7 @@ Short stories = http://www.feedbooks.com/books/top?category=FBFIC029000&range=we Fairy Tales, Folk Tales & Mythology = http://www.feedbooks.com/books/top?category=FBFIC010000&range=week Juvenile = http://www.feedbooks.com/books/top?category=FBJUV000000&range=week Action & Adventure = http://www.feedbooks.com/books/top?category=FBFIC002000&range=week +Feed Books Catalog Index = http://www.feedbooks.com/catalog [Internet Archive] name = Internet Archive diff --git a/opds.py b/opds.py index 9918811..4f5d089 100755..100644 --- a/opds.py +++ b/opds.py @@ -35,6 +35,9 @@ import feedparser _logger = logging.getLogger('get-ia-books-activity') _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' gobject.threads_init() @@ -67,6 +70,15 @@ class DownloadThread(threading.Thread): self.stopthread = threading.Event() def _download(self): + + def entry_type(entry): + for link in entry['links']: + if link['rel'] in \ + [_REL_OPDS_POPULAR, _REL_OPDS_NEW, _REL_SUBSECTION]: + return "CATALOG" + else: + return 'BOOK' + logging.debug('feedparser version %s', feedparser.__version__) if not self.obj.is_local() and self.midway == False: uri = self.obj._uri + self.obj._queryterm.replace(' ', '+') @@ -79,10 +91,13 @@ class DownloadThread(threading.Thread): else: feedobj = feedparser.parse(self.obj._uri) - logging.debug('despues de feedparser %d entries', len(feedobj['entries'])) for entry in feedobj['entries']: - #logging.error('%s', entry) - self.obj._booklist.append(Book(self.obj._configuration, entry)) + if entry_type(entry) == 'BOOK': + self.obj._booklist.append(Book(self.obj._configuration, entry)) + elif entry_type(entry) == 'CATALOG': + self.obj._cataloglist.append( \ + Book(self.obj._configuration, entry)) + self.obj._feedobj = feedobj self.obj._ready = True gobject.idle_add(self.obj.notify_updated, self.midway) @@ -129,7 +144,11 @@ class Book(object): + os.path.join(self._basepath, link['href']) else: ret[link['type']] = link['href'] - + elif link['rel'] in \ + [_REL_OPDS_POPULAR, _REL_OPDS_NEW, _REL_SUBSECTION]: + ret[link['type']] = link['href'] + else: + pass return ret def get_publisher(self): @@ -173,14 +192,14 @@ class Book(object): return ret def get_summary(self): - - if self._configuration is not None and 'summary_field' in self._configuration: - try: - ret = self._entry[self._configuration['summary_field']] - except KeyError: + if self._configuration is not None \ + and 'summary_field' in self._configuration: + try: + ret = self._entry[self._configuration['summary_field']] + except KeyError: + ret = 'Unknown' + else: ret = 'Unknown' - else: - ret = 'Unknown' return ret def get_object_id(self): @@ -221,6 +240,7 @@ class QueryResult(gobject.GObject): self._next_uri = '' self._ready = False self._booklist = [] + self._cataloglist = [] self.threads = [] self._start_download() @@ -278,6 +298,12 @@ class QueryResult(gobject.GObject): ''' return self._booklist + def get_catalog_list(self): + ''' + Gets the entire catalog list + ''' + return self._cataloglist + def is_ready(self): ''' Returns False if a query is in progress -- cgit v0.9.1