Small change to the API for medata source plugins. get_book_url must now return a tuple

This commit is contained in:
Kovid Goyal 2011-04-25 11:12:47 -06:00
parent 90326b1baa
commit da05725612
5 changed files with 11 additions and 8 deletions

View File

@ -301,7 +301,7 @@ class Amazon(Source):
if asin is None: if asin is None:
asin = identifiers.get('asin', None) asin = identifiers.get('asin', None)
if asin: if asin:
return 'http://amzn.com/%s'%asin return ('amazon', asin, 'http://amzn.com/%s'%asin)
# }}} # }}}
def create_query(self, log, title=None, authors=None, identifiers={}): # {{{ def create_query(self, log, title=None, authors=None, identifiers={}): # {{{

View File

@ -374,7 +374,11 @@ class Source(Plugin):
def get_book_url(self, identifiers): def get_book_url(self, identifiers):
''' '''
Return the URL for the book identified by identifiers at this source. Return a 3-tuple or None. The 3-tuple is of the form:
(identifier_type, identifier_value, URL).
The URL is the URL for the book identified by identifiers at this
source. identifier_type, identifier_value specify the identifier
corresponding to the URL.
This URL must be browseable to by a human using a browser. It is meant This URL must be browseable to by a human using a browser. It is meant
to provide a clickable link for the user to easily visit the books page to provide a clickable link for the user to easily visit the books page
at this source. at this source.

View File

@ -173,7 +173,7 @@ class GoogleBooks(Source):
def get_book_url(self, identifiers): # {{{ def get_book_url(self, identifiers): # {{{
goog = identifiers.get('google', None) goog = identifiers.get('google', None)
if goog is not None: if goog is not None:
return 'http://books.google.com/books?id=%s'%goog return ('google', goog, 'http://books.google.com/books?id=%s'%goog)
# }}} # }}}
def create_query(self, log, title=None, authors=None, identifiers={}): # {{{ def create_query(self, log, title=None, authors=None, identifiers={}): # {{{

View File

@ -438,14 +438,13 @@ def urls_from_identifiers(identifiers): # {{{
ans = [] ans = []
for plugin in all_metadata_plugins(): for plugin in all_metadata_plugins():
try: try:
url = plugin.get_book_url(identifiers) id_type, id_val, url = plugin.get_book_url(identifiers)
if url is not None: ans.append((plugin.name, id_type, id_val, url))
ans.append((plugin.name, url))
except: except:
pass pass
isbn = identifiers.get('isbn', None) isbn = identifiers.get('isbn', None)
if isbn: if isbn:
ans.append((isbn, ans.append((isbn, 'isbn', isbn,
'http://www.worldcat.org/search?q=bn%%3A%s&qt=advanced'%isbn)) 'http://www.worldcat.org/search?q=bn%%3A%s&qt=advanced'%isbn))
return ans return ans
# }}} # }}}

View File

@ -253,7 +253,7 @@ class ResultsView(QTableView): # {{{
parts.append('</center>') parts.append('</center>')
if book.identifiers: if book.identifiers:
urls = urls_from_identifiers(book.identifiers) urls = urls_from_identifiers(book.identifiers)
ids = ['<a href="%s">%s</a>'%(url, name) for name, url in urls] ids = ['<a href="%s">%s</a>'%(url, name) for name, ign, ign, url in urls]
if ids: if ids:
parts.append('<div><b>%s:</b> %s</div><br>'%(_('See at'), ', '.join(ids))) parts.append('<div><b>%s:</b> %s</div><br>'%(_('See at'), ', '.join(ids)))
if book.tags: if book.tags: