def update_cache(): #runs on scheduler thread issue = db.query_issue(ref, True) \ if type(ref) == IssueRef else None def update_bmodel(): # runs on application thread bmodel = cache[ref] if issue and len(issue.image_urls_sl) > 1: for i in range(1, len(issue.image_urls_sl)): bmodel.add_new_ref(issue.image_urls_sl[i]) bmodel.set_status('searched') self.__update() # recurse! utils.invoke(self, update_bmodel, True)
def find_series_ref(book, config): ''' Performs a number of queries on the database, in an attempt to find a SeriesRef object that strongly matches the given book. A variety of techniques are employed, including checking for matching issue numbers in the prospective series, and image matching the cover of the prospective issue in the prospective series. The user's search and filtering preferences (in 'config') are also taken into account. Returns None if no clear seroes identification could be made. ''' # tests to see if two hashes are close enough to be considered "the same" def are_the_same(hash1, hash2): x = imagehash.similarity(hash1, hash2) return x > __MATCH_THRESHOLD retval = None series_ref = __find_best_series(book, config) if series_ref: matches = False hash_local = __get_local_hash(book) if hash_local: # 1. convert SeriesRef + issue num to an IssueRef iff its possible. ref = db.query_issue_ref(series_ref, book.issue_num_s) \ if book.issue_num_s else series_ref ref = series_ref if not ref else ref # 2. see if the local and remote hashes match up hash_remote = __get_remote_hash(ref) matches = are_the_same(hash_local, hash_remote) # 3. if the given ref is an IssueRef, we can try to load the issue's # additional cover images and see if any of them match, too. if not matches and type(ref) == IssueRef: issue = db.query_issue(ref, True) if issue: for ref in issue.image_urls_sl: hash_remote = __get_remote_hash(ref) matches = are_the_same(hash_local, hash_remote) if matches: break retval = series_ref if matches else None return retval;