From c8b0bec34066c35604f2d73ba85a22d8930f9660 Mon Sep 17 00:00:00 2001 From: Lee Date: Sat, 23 Apr 2011 14:02:42 +0800 Subject: [PATCH] fix two situations where the Overdrive plugin returned no results even though the book was in their database --- .../ebooks/metadata/sources/overdrive.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/overdrive.py b/src/calibre/ebooks/metadata/sources/overdrive.py index e975d41ea6..0b8fc15c1e 100755 --- a/src/calibre/ebooks/metadata/sources/overdrive.py +++ b/src/calibre/ebooks/metadata/sources/overdrive.py @@ -229,28 +229,33 @@ class OverDrive(Source): if int(m.group('displayrecords')) >= 1: results = True 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 elif int(m.group('totalrecords')) == 0: 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 = [] raw = re.sub('.*?\[\[(?P.*?)\]\].*', '[[\g]]', 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, # sort through the results for closest match/format if results: for reserveid, od_title, subtitle, edition, series, publisher, format, formatid, creators, \ thumbimage, shortdescription, worldcatlink, excerptlink, creatorfile, sorttitle, \ 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]: - #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, creators, thumbimage, worldcatlink, formatid) 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)) else: 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: return close_matches[0] else: @@ -289,7 +298,7 @@ class OverDrive(Source): else: 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+'}' 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)) clean_cj = mechanize.CookieJar() 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): @@ -319,7 +328,7 @@ class OverDrive(Source): if ovrdrv_id is None: return self.overdrive_search(br, log, q, title, author) else: - return self.overdrive_get_record(br, q, ovrdrv_id) + return self.overdrive_get_record(br, log, q, ovrdrv_id)