mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
fix two situations where the Overdrive plugin returned no results even though the book was in their database
This commit is contained in:
parent
eb73df9609
commit
c8b0bec340
@ -229,28 +229,33 @@ class OverDrive(Source):
|
|||||||
if int(m.group('displayrecords')) >= 1:
|
if int(m.group('displayrecords')) >= 1:
|
||||||
results = True
|
results = True
|
||||||
elif int(m.group('totalrecords')) >= 1:
|
elif int(m.group('totalrecords')) >= 1:
|
||||||
xref_q = ''
|
if int(m.group('totalrecords')) >= 500:
|
||||||
|
if xref_q.find('+') != -1:
|
||||||
|
xref_tokens = xref_q.split('+')
|
||||||
|
xref_q = xref_tokens[0]
|
||||||
|
else:
|
||||||
|
xref_q = ''
|
||||||
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
q_xref = q+'SearchResults.svc/GetResults?iDisplayLength=50&sSearch='+xref_q
|
||||||
elif int(m.group('totalrecords')) == 0:
|
elif int(m.group('totalrecords')) == 0:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return self.sort_ovrdrv_results(raw, title, title_tokens, author, author_tokens)
|
return self.sort_ovrdrv_results(raw, log, title, title_tokens, author, author_tokens)
|
||||||
|
|
||||||
|
|
||||||
def sort_ovrdrv_results(self, raw, title=None, title_tokens=None, author=None, author_tokens=None, ovrdrv_id=None):
|
def sort_ovrdrv_results(self, raw, log, title=None, title_tokens=None, author=None, author_tokens=None, ovrdrv_id=None):
|
||||||
close_matches = []
|
close_matches = []
|
||||||
raw = re.sub('.*?\[\[(?P<content>.*?)\]\].*', '[[\g<content>]]', raw)
|
raw = re.sub('.*?\[\[(?P<content>.*?)\]\].*', '[[\g<content>]]', raw)
|
||||||
results = json.loads(raw)
|
results = json.loads(raw)
|
||||||
#print results
|
#log.error('raw results are:'+str(results))
|
||||||
# The search results are either from a keyword search or a multi-format list from a single ID,
|
# The search results are either from a keyword search or a multi-format list from a single ID,
|
||||||
# sort through the results for closest match/format
|
# sort through the results for closest match/format
|
||||||
if results:
|
if results:
|
||||||
for reserveid, od_title, subtitle, edition, series, publisher, format, formatid, creators, \
|
for reserveid, od_title, subtitle, edition, series, publisher, format, formatid, creators, \
|
||||||
thumbimage, shortdescription, worldcatlink, excerptlink, creatorfile, sorttitle, \
|
thumbimage, shortdescription, worldcatlink, excerptlink, creatorfile, sorttitle, \
|
||||||
availabletolibrary, availabletoretailer, relevancyrank, unknown1, unknown2, unknown3 in results:
|
availabletolibrary, availabletoretailer, relevancyrank, unknown1, unknown2, unknown3 in results:
|
||||||
#print "this record's title is "+od_title+", subtitle is "+subtitle+", author[s] are "+creators+", series is "+series
|
#log.error("this record's title is "+od_title+", subtitle is "+subtitle+", author[s] are "+creators+", series is "+series)
|
||||||
if ovrdrv_id is not None and int(formatid) in [1, 50, 410, 900]:
|
if ovrdrv_id is not None and int(formatid) in [1, 50, 410, 900]:
|
||||||
#print "overdrive id is not None, searching based on format type priority"
|
#log.error('overdrive id is not None, searching based on format type priority')
|
||||||
return self.format_results(reserveid, od_title, subtitle, series, publisher,
|
return self.format_results(reserveid, od_title, subtitle, series, publisher,
|
||||||
creators, thumbimage, worldcatlink, formatid)
|
creators, thumbimage, worldcatlink, formatid)
|
||||||
else:
|
else:
|
||||||
@ -282,6 +287,10 @@ class OverDrive(Source):
|
|||||||
close_matches.insert(0, self.format_results(reserveid, od_title, subtitle, series, publisher, creators, thumbimage, worldcatlink, formatid))
|
close_matches.insert(0, self.format_results(reserveid, od_title, subtitle, series, publisher, creators, thumbimage, worldcatlink, formatid))
|
||||||
else:
|
else:
|
||||||
close_matches.append(self.format_results(reserveid, od_title, subtitle, series, publisher, creators, thumbimage, worldcatlink, formatid))
|
close_matches.append(self.format_results(reserveid, od_title, subtitle, series, publisher, creators, thumbimage, worldcatlink, formatid))
|
||||||
|
|
||||||
|
elif close_title_match and close_author_match and int(formatid) in [1, 50, 410, 900]:
|
||||||
|
close_matches.append(self.format_results(reserveid, od_title, subtitle, series, publisher, creators, thumbimage, worldcatlink, formatid))
|
||||||
|
|
||||||
if close_matches:
|
if close_matches:
|
||||||
return close_matches[0]
|
return close_matches[0]
|
||||||
else:
|
else:
|
||||||
@ -289,7 +298,7 @@ class OverDrive(Source):
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def overdrive_get_record(self, br, q, ovrdrv_id):
|
def overdrive_get_record(self, br, log, q, ovrdrv_id):
|
||||||
search_url = q+'SearchResults.aspx?ReserveID={'+ovrdrv_id+'}'
|
search_url = q+'SearchResults.aspx?ReserveID={'+ovrdrv_id+'}'
|
||||||
results_url = q+'SearchResults.svc/GetResults?sEcho=1&iColumns=18&sColumns=ReserveID%2CTitle%2CSubtitle%2CEdition%2CSeries%2CPublisher%2CFormat%2CFormatID%2CCreators%2CThumbImage%2CShortDescription%2CWorldCatLink%2CExcerptLink%2CCreatorFile%2CSortTitle%2CAvailableToLibrary%2CAvailableToRetailer%2CRelevancyRank&iDisplayStart=0&iDisplayLength=10&sSearch=&bEscapeRegex=true&iSortingCols=1&iSortCol_0=17&sSortDir_0=asc'
|
results_url = q+'SearchResults.svc/GetResults?sEcho=1&iColumns=18&sColumns=ReserveID%2CTitle%2CSubtitle%2CEdition%2CSeries%2CPublisher%2CFormat%2CFormatID%2CCreators%2CThumbImage%2CShortDescription%2CWorldCatLink%2CExcerptLink%2CCreatorFile%2CSortTitle%2CAvailableToLibrary%2CAvailableToRetailer%2CRelevancyRank&iDisplayStart=0&iDisplayLength=10&sSearch=&bEscapeRegex=true&iSortingCols=1&iSortCol_0=17&sSortDir_0=asc'
|
||||||
|
|
||||||
@ -311,7 +320,7 @@ class OverDrive(Source):
|
|||||||
raw = str(list(raw))
|
raw = str(list(raw))
|
||||||
clean_cj = mechanize.CookieJar()
|
clean_cj = mechanize.CookieJar()
|
||||||
br.set_cookiejar(clean_cj)
|
br.set_cookiejar(clean_cj)
|
||||||
return self.sort_ovrdrv_results(raw, None, None, None, ovrdrv_id)
|
return self.sort_ovrdrv_results(raw, log, None, None, None, ovrdrv_id)
|
||||||
|
|
||||||
|
|
||||||
def find_ovrdrv_data(self, br, log, title, author, isbn, ovrdrv_id=None):
|
def find_ovrdrv_data(self, br, log, title, author, isbn, ovrdrv_id=None):
|
||||||
@ -319,7 +328,7 @@ class OverDrive(Source):
|
|||||||
if ovrdrv_id is None:
|
if ovrdrv_id is None:
|
||||||
return self.overdrive_search(br, log, q, title, author)
|
return self.overdrive_search(br, log, q, title, author)
|
||||||
else:
|
else:
|
||||||
return self.overdrive_get_record(br, q, ovrdrv_id)
|
return self.overdrive_get_record(br, log, q, ovrdrv_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user