mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
fix issue where overdrive can get in an ifinite loop
This commit is contained in:
parent
58923e2243
commit
d07b4556e9
@ -208,8 +208,8 @@ class OverDrive(Source):
|
|||||||
if len(xref_q) < len(token):
|
if len(xref_q) < len(token):
|
||||||
xref_q = token
|
xref_q = token
|
||||||
|
|
||||||
#log.error('Initial query is %s'%initial_q)
|
log.error('Initial query is %s'%initial_q)
|
||||||
#log.error('Cross reference query is %s'%xref_q)
|
log.error('Cross reference query is %s'%xref_q)
|
||||||
|
|
||||||
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
||||||
query = '{"szKeyword":"'+initial_q+'"}'
|
query = '{"szKeyword":"'+initial_q+'"}'
|
||||||
@ -224,29 +224,30 @@ class OverDrive(Source):
|
|||||||
|
|
||||||
# get the search results object
|
# get the search results object
|
||||||
results = False
|
results = False
|
||||||
|
iterations = 0
|
||||||
while results == False:
|
while results == False:
|
||||||
|
iterations += 1
|
||||||
xreq = mechanize.Request(q_xref)
|
xreq = mechanize.Request(q_xref)
|
||||||
xreq.add_header('X-Requested-With', 'XMLHttpRequest')
|
xreq.add_header('X-Requested-With', 'XMLHttpRequest')
|
||||||
xreq.add_header('Referer', q_init_search)
|
xreq.add_header('Referer', q_init_search)
|
||||||
xreq.add_header('Accept', 'application/json, text/javascript, */*')
|
xreq.add_header('Accept', 'application/json, text/javascript, */*')
|
||||||
raw = br.open_novisit(xreq).read()
|
raw = br.open_novisit(xreq).read()
|
||||||
for m in re.finditer(ur'"iTotalDisplayRecords":(?P<displayrecords>\d+).*?"iTotalRecords":(?P<totalrecords>\d+)', raw):
|
for m in re.finditer(ur'"iTotalDisplayRecords":(?P<displayrecords>\d+).*?"iTotalRecords":(?P<totalrecords>\d+)', raw):
|
||||||
if int(m.group('displayrecords')) >= 1:
|
if int(m.group('totalrecords')) == 0:
|
||||||
results = True
|
|
||||||
elif int(m.group('totalrecords')) >= 1:
|
|
||||||
if int(m.group('totalrecords')) >= 100:
|
|
||||||
if xref_q.find('+') != -1:
|
|
||||||
xref_tokens = xref_q.split('+')
|
|
||||||
xref_q = xref_tokens[0]
|
|
||||||
for token in xref_tokens:
|
|
||||||
if len(xref_q) < len(token):
|
|
||||||
xref_q = token
|
|
||||||
#log.error('rewrote xref_q, new query is '+xref_q)
|
|
||||||
else:
|
|
||||||
xref_q = ''
|
|
||||||
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
|
||||||
elif int(m.group('totalrecords')) == 0:
|
|
||||||
return ''
|
return ''
|
||||||
|
elif int(m.group('displayrecords')) >= 1:
|
||||||
|
results = True
|
||||||
|
elif int(m.group('totalrecords')) >= 1 and iterations < 3:
|
||||||
|
if xref_q.find('+') != -1:
|
||||||
|
xref_tokens = xref_q.split('+')
|
||||||
|
xref_q = xref_tokens[0]
|
||||||
|
for token in xref_tokens:
|
||||||
|
if len(xref_q) < len(token):
|
||||||
|
xref_q = token
|
||||||
|
#log.error('rewrote xref_q, new query is '+xref_q)
|
||||||
|
else:
|
||||||
|
xref_q = ''
|
||||||
|
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
||||||
|
|
||||||
return self.sort_ovrdrv_results(raw, log, title, title_tokens, author, author_tokens)
|
return self.sort_ovrdrv_results(raw, log, title, title_tokens, author, author_tokens)
|
||||||
|
|
||||||
@ -461,10 +462,10 @@ if __name__ == '__main__':
|
|||||||
[
|
[
|
||||||
|
|
||||||
(
|
(
|
||||||
{'title':'Foundation and Earth',
|
{'title':'The Sea Kings Daughter',
|
||||||
'authors':['Asimov']},
|
'authors':['Elizabeth Peters']},
|
||||||
[title_test('Foundation and Earth', exact=True),
|
[title_test('The Sea Kings Daughter', exact=False),
|
||||||
authors_test(['Isaac Asimov'])]
|
authors_test(['Elizabeth Peters'])]
|
||||||
),
|
),
|
||||||
|
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user