def maybe_convert_seriesref_to_issue_ref(ref):
    if not ref in self.__series_cache:
       issue_ref = db.query_issue_ref(ref, self.__issue_num_hint_s)
       self.__series_cache[ref] = issue_ref if issue_ref else ref
          
    # 1b. go back to the application thread to do the actual ref change
    def change_ref():  
       self.__ref = self.__series_cache[ref]
       self.__update()
    utils.invoke(self.__coverpanel, change_ref, True)
            def maybe_convert_seriesref_to_issue_ref(ref):
                if not ref in self.__series_cache:
                    issue_ref = db.query_issue_ref(ref,
                                                   self.__issue_num_hint_s)
                    self.__series_cache[ref] = issue_ref if issue_ref else ref

                # 1b. go back to the application thread to do the actual ref change
                def change_ref():
                    self.__ref = self.__series_cache[ref]
                    self.__update()

                utils.invoke(self.__coverpanel, change_ref, 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;
示例#4
0
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;