Ticket #3764: GetBooks_Internet_Archive_Catalog_Support.patch

File GetBooks_Internet_Archive_Catalog_Support.patch, 6.8 KB (added by godiard, 12 years ago)
  • GetBooks.activity/get-books.cfg

    diff -u -r -N '-x=*.pyc/*.*~' /home/dcastelo/Downloads/GetBooks.activity/get-books.cfg /home/dcastelo/Activities/GetBooks.activity/get-books.cfg
    old new  
    2222name = Internet Archive
    2323query_uri = http://bookserver.archive.org/catalog/opensearch?q=
    2424opds_cover = http://opds-spec.org/image
    25 #opds_cover = http://opds-spec.org/image/thumbnail
     25
     26[Catalogs_Internet Archive]
     27Index = http://bookserver.archive.org/catalog/
     28
     29[Ceibal]
     30name = Ceibal
     31query_uri = http://biblioteca.ceibal.edu.uy/latest.atom?q=
     32opds_cover = http://opds-spec.org/cover
     33summary_field = summary
     34
     35[Catalogs_Ceibal]
     36indice = http://biblioteca.ceibal.edu.uy/static_media/catalogo_inicial.htm
  • GetBooks.activity/GetIABooksActivity.py

    diff -u -r -N '-x=*.pyc/*.*~' /home/dcastelo/Downloads/GetBooks.activity/GetIABooksActivity.py /home/dcastelo/Activities/GetBooks.activity/GetIABooksActivity.py
    old new  
    7878        self.show_images = True
    7979        self.languages = {}
    8080        self._lang_code_handler = languagenames.LanguageNames()
    81         self.catalogs = {}
     81        self.catalogs_configuration = {}
    8282        self.catalog_history = []
    8383
    8484        if os.path.exists('/etc/get-books.cfg'):
     
    210210
    211211                _SOURCES_CONFIG[section] = repo_config
    212212
     213        self.source = _SOURCES_CONFIG.keys()[0]
     214
    213215        logging.error('_SOURCES %s', _SOURCES)
    214216        logging.error('_SOURCES_CONFIG %s', _SOURCES_CONFIG)
    215217
     
    230232                    catalog_config['name'] = catalog
    231233                    catalog_config['summary_field'] = \
    232234                        source_config['summary_field']
    233                     self.catalogs[catalog] = catalog_config
     235                    self.catalogs_configuration[catalog] = catalog_config
     236
     237
     238        self.catalogs = {}
     239        for catalog_key in self.catalogs_configuration:
     240            catalog = self.catalogs_configuration[catalog_key]
     241            if catalog['source'] == self.source:
     242                self.catalogs[catalog_key]=catalog
    234243
    235244        logging.error('languages %s', self.languages)
    236245        logging.error('catalogs %s', self.catalogs)
     
    498507        self.bt_move_up_catalog.hide_image()
    499508        self.treecol.set_widget(self.bt_move_up_catalog)
    500509
    501         if len(self.catalogs) > 0:
    502             self.catalog_history.append({'title': _('Catalogs'),
    503                 'catalogs': self.catalogs})
    504             self.categories = []
    505             self.path_iter = {}
    506             for key in self.catalogs.keys():
    507                 self.categories.append({'text': key, 'dentro': []})
    508             self.treemodel.clear()
    509             for p in self.categories:
    510                 self.path_iter[p['text']] = self.treemodel.append([p['text']])
     510        self.load_source_catalogs()
     511
    511512        self.tree_scroller = gtk.ScrolledWindow(hadjustment=None,
    512513                vadjustment=None)
    513514        self.tree_scroller.set_policy(gtk.POLICY_NEVER,
     
    865866        else:
    866867            self.catalog_history.pop()
    867868
     869    def load_source_catalogs(self):
     870        self.catalogs = {}
     871
     872        for catalog_key in self.catalogs_configuration:
     873            catalog = self.catalogs_configuration[catalog_key]
     874            if catalog['source'] == self.source:
     875                self.catalogs[catalog_key]=catalog
     876
     877        if len(self.catalogs) > 0:
     878            self.categories = []
     879            self.path_iter = {}
     880            self.catalog_history = []
     881            self.catalog_history.append({'title': _('Catalogs'),
     882                'catalogs': self.catalogs})
     883            for key in self.catalogs.keys():
     884                self.categories.append({'text': key, 'dentro': []})
     885            self.treemodel.clear()
     886
     887            for p in self.categories:
     888                self.path_iter[p['text']] = self.treemodel.append([p['text']])
     889
     890
    868891    def __source_changed_cb(self, widget):
    869892        search_terms = self.get_search_terms()
    870893        if search_terms == '':
     
    873896            self.find_books(search_terms)
    874897        # enable/disable catalogs button if configuration is available
    875898        self.source = self._books_toolbar.source_combo.props.value
    876         have_catalogs = False
    877         for catalog_name in self.catalogs.keys():
    878             catalog_config = self.catalogs[catalog_name]
    879             if catalog_config['source'] == self.source:
    880                 have_catalogs = True
    881                 break
    882         if have_catalogs:
     899                # Get catalogs for this source
     900        self.load_source_catalogs()
     901
     902        if len(self.catalogs)>0:
    883903            self.bt_catalogs.show()
    884904            self.bt_catalogs.set_active(True)
    885905        else:
  • GetBooks.activity/opds.py

    diff -u -r -N '-x=*.pyc/*.*~' /home/dcastelo/Downloads/GetBooks.activity/opds.py /home/dcastelo/Activities/GetBooks.activity/opds.py
    old new  
    3838_REL_SUBSECTION = 'subsection'
    3939_REL_OPDS_POPULAR = u'http://opds-spec.org/sort/popular'
    4040_REL_OPDS_NEW = u'http://opds-spec.org/sort/new'
     41_REL_ALTERNATE = 'alternate'
     42_REL_CRAWLABLE = 'http://opds-spec.org/crawlable'
    4143
    4244gobject.threads_init()
    4345
     
    9193        else:
    9294            feedobj = feedparser.parse(self.obj._uri)
    9395
     96                # Get catalog Type
     97        CATALOG_TYPE = 'COMMON'
     98        if 'links' in feedobj['feed']:         
     99            for link in feedobj['feed']['links']:
     100                if link['rel'] == _REL_CRAWLABLE:       
     101                    CATALOG_TYPE = 'CRAWLABLE'
     102                    break                 
     103                   
    94104        for entry in feedobj['entries']:
    95             if entry_type(entry) == 'BOOK':
     105            if entry_type(entry) == 'BOOK' and CATALOG_TYPE is not 'CRAWLABLE':
    96106                self.obj._booklist.append(Book(self.obj._configuration, entry))
    97             elif entry_type(entry) == 'CATALOG':
     107            elif entry_type(entry) == 'CATALOG' or CATALOG_TYPE == 'CRAWLABLE':
    98108                self.obj._cataloglist.append( \
    99109                    Book(self.obj._configuration, entry))
    100110
     
    147157            elif link['rel'] in \
    148158            [_REL_OPDS_POPULAR, _REL_OPDS_NEW, _REL_SUBSECTION]:
    149159                ret[link['type']] = link['href']
     160            elif link['rel'] == _REL_ALTERNATE:
     161                ret[link['type']] = link['href']
    150162            else:
    151163                pass
    152164        return ret