From 4e428219c94c05df0597c54aab9849f227928094 Mon Sep 17 00:00:00 2001 From: Lee Date: Mon, 7 Mar 2011 04:37:47 +0800 Subject: [PATCH] ... --- src/calibre/ebooks/metadata/overdrive.py | 67 +++++++++++++----------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/calibre/ebooks/metadata/overdrive.py b/src/calibre/ebooks/metadata/overdrive.py index cb9ab2c9c9..5afb875fad 100644 --- a/src/calibre/ebooks/metadata/overdrive.py +++ b/src/calibre/ebooks/metadata/overdrive.py @@ -24,32 +24,29 @@ cover_url_cache = {} cache_lock = RLock() base_url = 'http://search.overdrive.com/' -class ContentReserve(Source): - def create_query(self, title=None, authors=None, identifiers={}): - q = '' - if title or authors: - def build_term(prefix, parts): - return ' '.join('in'+prefix + ':' + x for x in parts) - title_tokens = list(self.get_title_tokens(title)) - if title_tokens: - q += build_term('title', title_tokens) - author_tokens = self.get_author_tokens(authors, - only_first_author=True) - if author_tokens: - q += ('+' if q else '') + build_term('author', - author_tokens) - if isinstance(q, unicode): - q = q.encode('utf-8') - if not q: - return None - return BASE_URL+urlencode({ - 'q':q, - 'max-results':20, - 'start-index':1, - 'min-viewability':'none', - }) +def create_query(self, title=None, authors=None, identifiers={}): + q = '' + if title or authors: + def build_term(prefix, parts): + return ' '.join('in'+prefix + ':' + x for x in parts) + title_tokens = list(self.get_title_tokens(title)) + if title_tokens: + q += build_term('title', title_tokens) + author_tokens = self.get_author_tokens(authors, + only_first_author=True) + if author_tokens: + q += ('+' if q else '') + build_term('author', + author_tokens) + + if isinstance(q, unicode): + q = q.encode('utf-8') + if not q: + return None + return BASE_URL+urlencode({ + 'q':q, + }) def get_base_referer(): @@ -82,9 +79,20 @@ def format_results(reserveid, od_title, subtitle, series, publisher, creators, t def overdrive_search(br, q, title, author): q_query = q+'default.aspx/SearchByKeyword' q_init_search = q+'SearchResults.aspx' - + # get first author as string - convert this to a proper cleanup function later + s = Source(None) + print "printing list with string:" + print list(s.get_author_tokens(['J. R. R. Tolkien'])) + print "printing list with author "+str(author)+":" + print list(s.get_author_tokens(author)) + author = list(s.get_author_tokens(author)) + for token in author: + print "cleaned up author is: "+str(token) + author_q = '+'.join(author) + #author_q = separator.join(for x in author) # query terms - author_q = re.sub('\s', '+', author) + #author_q = re.sub('\s', '+', author_q) + print "final author query is "+str(author_q) q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=10&sSearch='+author_q query = '{"szKeyword":"'+title+'"}' @@ -231,9 +239,6 @@ def get_cover_url(isbn, title, author, br): print "isbn is "+str(isbn) print "title is "+str(title) print "author is "+str(author[0]) - cleanup = ContentReserve() - query = cleanup.create_query(author, title) - print "cleansed query is "+str(author) with cache_lock: ans = cover_url_cache.get(isbn, None) @@ -386,8 +391,8 @@ def main(args=sys.argv): for isbn, title, author in [ #('0899661343', 'On the Road', ['Jack Kerouac']), # basic test, no series, single author #('9780061952838', 'The Fellowship of the Ring', ['J. R. R. Tolkien']), # Series test, multi-author - #('9780061952838', 'The Two Towers', ['J. R. R. Tolkien']), # Series test, book 2 - ('9780345505057', 'Deluge', ['Anne McCaffrey']) # Multiple authors + ('9780061952838', 'The Two Towers', ['J. R. R. Tolkien']), # Series test, book 2 + #('9780345505057', 'Deluge', ['Anne McCaffrey']) # Multiple authors #('', 'Deluge', ['Anne McCaffrey']) # Empty ISBN #(None, 'On the Road', ['Jack Kerouac']) # Nonetype ISBN ]: