mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
6091edca84
commit
4e428219c9
@ -24,32 +24,29 @@ cover_url_cache = {}
|
|||||||
cache_lock = RLock()
|
cache_lock = RLock()
|
||||||
base_url = 'http://search.overdrive.com/'
|
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):
|
def create_query(self, title=None, authors=None, identifiers={}):
|
||||||
q = q.encode('utf-8')
|
q = ''
|
||||||
if not q:
|
if title or authors:
|
||||||
return None
|
def build_term(prefix, parts):
|
||||||
return BASE_URL+urlencode({
|
return ' '.join('in'+prefix + ':' + x for x in parts)
|
||||||
'q':q,
|
title_tokens = list(self.get_title_tokens(title))
|
||||||
'max-results':20,
|
if title_tokens:
|
||||||
'start-index':1,
|
q += build_term('title', title_tokens)
|
||||||
'min-viewability':'none',
|
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():
|
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):
|
def overdrive_search(br, q, title, author):
|
||||||
q_query = q+'default.aspx/SearchByKeyword'
|
q_query = q+'default.aspx/SearchByKeyword'
|
||||||
q_init_search = q+'SearchResults.aspx'
|
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
|
# 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
|
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=10&sSearch='+author_q
|
||||||
query = '{"szKeyword":"'+title+'"}'
|
query = '{"szKeyword":"'+title+'"}'
|
||||||
|
|
||||||
@ -231,9 +239,6 @@ def get_cover_url(isbn, title, author, br):
|
|||||||
print "isbn is "+str(isbn)
|
print "isbn is "+str(isbn)
|
||||||
print "title is "+str(title)
|
print "title is "+str(title)
|
||||||
print "author is "+str(author[0])
|
print "author is "+str(author[0])
|
||||||
cleanup = ContentReserve()
|
|
||||||
query = cleanup.create_query(author, title)
|
|
||||||
print "cleansed query is "+str(author)
|
|
||||||
|
|
||||||
with cache_lock:
|
with cache_lock:
|
||||||
ans = cover_url_cache.get(isbn, None)
|
ans = cover_url_cache.get(isbn, None)
|
||||||
@ -386,8 +391,8 @@ def main(args=sys.argv):
|
|||||||
for isbn, title, author in [
|
for isbn, title, author in [
|
||||||
#('0899661343', 'On the Road', ['Jack Kerouac']), # basic test, no series, single author
|
#('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 Fellowship of the Ring', ['J. R. R. Tolkien']), # Series test, multi-author
|
||||||
#('9780061952838', 'The Two Towers', ['J. R. R. Tolkien']), # Series test, book 2
|
('9780061952838', 'The Two Towers', ['J. R. R. Tolkien']), # Series test, book 2
|
||||||
('9780345505057', 'Deluge', ['Anne McCaffrey']) # Multiple authors
|
#('9780345505057', 'Deluge', ['Anne McCaffrey']) # Multiple authors
|
||||||
#('', 'Deluge', ['Anne McCaffrey']) # Empty ISBN
|
#('', 'Deluge', ['Anne McCaffrey']) # Empty ISBN
|
||||||
#(None, 'On the Road', ['Jack Kerouac']) # Nonetype ISBN
|
#(None, 'On the Road', ['Jack Kerouac']) # Nonetype ISBN
|
||||||
]:
|
]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user