Beispiel #1
0
 def download_task():
    
    # 3a. load the image. 
    new_image = db.query_image(ref) # disposed later
       
    # 3b. now that we've loaded a new image, the following method is
    #     passed back to the gui thread and run to update our gui 
    def update_image():
       
       # if somehow the image we just loaded is already in the cache,
       # take it out and dispose it.  this should be rare.    
       if ref in self.__image_cache:
          old_image = self.__image_cache[ref]
          del self.__image_cache[ref]
          if old_image:
             old_image.Dispose()
       
       # cache the new image, so we never have to load it again
       if new_image:
          self.__image_cache[ref] = new_image
       
       # if the __current_image_ref hasn't changed, switch this 
       # PictureBox to display that image.  otherwise, we already 
       # loading a new one, so don't do a pointless visual update.
       if ref == self.__current_image_ref:
          switchimage(new_image)
          
    utils.invoke(self, update_image, False) 
Beispiel #2
0
def __get_remote_hash(ref):
    ''' 
   Gets the image hash for a remote comic book resource.  This resource
   can be a SeriesRef (hashes series art), an IssueRef (hashes the 
   first issue cover) or a URL to an image on the web.
   
   Returns None if the ref led to an image that was empty or 
   couldn't be hashed for any reason.
   '''
    hash = None  # matches nothing
    try:
        image = db.query_image(ref) if ref else None
        if image:
            image = utils.strip_back_cover(image)
            hash = imagehash.hash(image)
    finally:
        if "image" in locals() and image: image.Dispose()
    return hash
def __get_remote_hash(ref):
   ''' 
   Gets the image hash for a remote comic book resource.  This resource
   can be a SeriesRef (hashes series art), an IssueRef (hashes the 
   first issue cover) or a URL to an image on the web.
   
   Returns None if the ref led to an image that was empty or 
   couldn't be hashed for any reason.
   '''  
   hash = None # matches nothing
   try:
      image = db.query_image(ref) if ref else None
      if image:
         image = utils.strip_back_cover(image)
         hash = imagehash.hash(image)
   finally:
      if "image" in locals() and image: image.Dispose()
   return hash 
Beispiel #4
0
   def update(self):
      '''
      Overridden to implement abstract method defined in superclass. Writes all 
      eligible properties in this object out to their counterparts in ComicRack 
      (i.e. back into the ComicBook object that was passed into __init__.) 
      '''
      ok_to_update = self.updated_properties()
      
      
      # removes commas from the the given string  
      def cleanup(s):
         s = re.sub(r",(\s+)", r"\1", s) if s else ""
         return re.sub(r",", r" ", s)
      
      
      if "series_s" in ok_to_update:
         self.__crbook.Series = self.series_s
         ok_to_update.remove("series_s")

      if "issue_num_s" in ok_to_update:
         self.__crbook.Number = self.issue_num_s
         ok_to_update.remove("issue_num_s")
      
      if "volume_year_n" in ok_to_update:
         self.__crbook.Volume = self.volume_year_n
         ok_to_update.remove("volume_year_n")
         
      if "format_s" in ok_to_update:
         self.__crbook.Format = self.format_s
         ok_to_update.remove("format_s")
         
      if "title_s" in ok_to_update:
         self.__crbook.Title = self.title_s
         ok_to_update.remove("title_s")
         
      if "crossovers_sl" in ok_to_update:
         self.__crbook.AlternateSeries = \
            ', '.join([cleanup(x) for x in self.crossovers_sl])
         ok_to_update.remove("crossovers_sl")
         
      if "summary_s" in ok_to_update:
         self.__crbook.Summary = self.summary_s
         ok_to_update.remove("summary_s")
         
      if "publisher_s" in ok_to_update:
         self.__crbook.Publisher = self.publisher_s
         ok_to_update.remove("publisher_s")
         
      if "imprint_s" in ok_to_update:
         self.__crbook.Imprint = self.imprint_s
         ok_to_update.remove("imprint_s")
         
      if "characters_sl" in ok_to_update:
         self.__crbook.Characters = \
            ', '.join([cleanup(x) for x in self.characters_sl])
         ok_to_update.remove("characters_sl")
            
      if "teams_sl" in ok_to_update:
         self.__crbook.Teams = \
            ', '.join([cleanup(x) for x in self.teams_sl])
         ok_to_update.remove("teams_sl")
            
      if "locations_sl" in ok_to_update:
         self.__crbook.Locations = \
            ', '.join([cleanup(x) for x in self.locations_sl])
         ok_to_update.remove("locations_sl")
            
      if "writers_sl" in ok_to_update:
         self.__crbook.Writer = \
            ', '.join([cleanup(x) for x in self.writers_sl])
         ok_to_update.remove("writers_sl")
            
      if "pencillers_sl" in ok_to_update:
         self.__crbook.Penciller = \
            ', '.join([cleanup(x) for x in self.pencillers_sl])
         ok_to_update.remove("pencillers_sl")
            
      if "inkers_sl" in ok_to_update:
         self.__crbook.Inker = \
            ', '.join([cleanup(x) for x in self.inkers_sl])
         ok_to_update.remove("inkers_sl")
         
      if "colorists_sl" in ok_to_update:
         self.__crbook.Colorist = \
            ', '.join([cleanup(x) for x in self.colorists_sl])
         ok_to_update.remove("colorists_sl")
         
      if "letterers_sl" in ok_to_update:
         self.__crbook.Letterer = \
            ', '.join([cleanup(x) for x in self.letterers_sl])
         ok_to_update.remove("letterers_sl")
            
      if "cover_artists_sl" in ok_to_update:
         self.__crbook.CoverArtist = \
            ', '.join([cleanup(x) for x in self.cover_artists_sl])
         ok_to_update.remove("cover_artists_sl")
            
      if "editors_sl" in ok_to_update:
         self.__crbook.Editor = \
            ', '.join([cleanup(x) for x in self.editors_sl])
         ok_to_update.remove("editors_sl")
         
      if "tags_sl" in ok_to_update:
         self.__crbook.Tags = \
            ', '.join([cleanup(x) for x in self.tags_sl])
         ok_to_update.remove("tags_sl")
            
      if "notes_s" in ok_to_update:
         self.__crbook.Notes = self.notes_s
         ok_to_update.remove("notes_s")
         
      if "webpage_s" in ok_to_update:
         self.__crbook.Web = self.webpage_s
         ok_to_update.remove("webpage_s")
         
      if "rating_n" in ok_to_update:
         self.__crbook.CommunityRating = self.rating_n
         ok_to_update.remove("rating_n")
         
      if "issue_key_s" in ok_to_update:
         self.__crbook.SetCustomValue(
            PluginBookData.__ISSUE_KEY, sstr(self.issue_key_s))
         ok_to_update.remove("issue_key_s")
         
      if "series_key_s" in ok_to_update:
         self.__crbook.SetCustomValue(
            PluginBookData.__SERIES_KEY, sstr(self.series_key_s))
         ok_to_update.remove("series_key_s")
         
         
      # dates are a little special.  any element in the data could be blank
      # (missing), and we only update the released date if NONE of the 
      # elements are missing.  the published date, however, can have a missing
      # day, or a missing day and month, and we'll still update the rest
      if "rel_year_n" in ok_to_update and \
         "rel_month_n" in ok_to_update and \
         "rel_day_n" in ok_to_update:
         if self.rel_year_n != BookData.blank("rel_year_n") and \
            self.rel_month_n != BookData.blank("rel_month_n") and \
            self.rel_day_n != BookData.blank("rel_day_n"):
            date = DateTime(self.rel_year_n, self.rel_month_n, self.rel_day_n)
            self.__crbook.ReleasedTime = date
         ok_to_update.remove("rel_year_n")
         ok_to_update.remove("rel_month_n")
         ok_to_update.remove("rel_day_n")
         
        
      if "pub_year_n" in ok_to_update:
         if self.pub_year_n != BookData.blank("pub_year_n"):
            self.__crbook.Year = self.pub_year_n
         ok_to_update.remove("pub_year_n")
         
      if "pub_month_n" in ok_to_update:
         if self.pub_year_n != BookData.blank("pub_year_n") and \
            self.pub_month_n != BookData.blank("pub_month_n"):
            self.__crbook.Month = self.pub_month_n
         ok_to_update.remove("pub_month_n")
         
      if "pub_day_n" in ok_to_update:
         if self.pub_year_n != BookData.blank("pub_year_n") and \
            self.pub_month_n != BookData.blank("pub_month_n") and \
            self.pub_day_n != BookData.blank("pub_day_n"):
            self.__crbook.Day = self.pub_day_n
         ok_to_update.remove("pub_day_n")
      
   
      # we only download and install a thumbnail for fileless CR books, and
      # even then, only if the user's prefs indicate that they want us to      
      if "cover_url_s" in ok_to_update:
         already_has_thumb = self.__crbook.CustomThumbnailKey
         book_is_fileless = not self.path_s
         config = self.__scraper.config
   
         if not self.cover_url_s or not book_is_fileless or \
               not config.download_thumbs_b or \
               (already_has_thumb and config.preserve_thumbs_b): 
            pass
         else:
            image = db.query_image(self.cover_url_s)
            if not image:
               log.debug("ERROR: can't download thumbnail: ", self.cover_url_s)
            else:
               cr = self.__scraper.comicrack.App
               success = cr.SetCustomBookThumbnail(self.__crbook, image)
               if not success:
                  log.debug("ERROR: can't set thumbnail: ", self.cover_url_s)
         ok_to_update.remove("cover_url_s")

         
      # a nice safety check to make sure we didn't miss anything
      if len(ok_to_update) > 0:
         for s in ok_to_update:
            log.debug(self.__class__.__name__ + " can't update property: " + s)
         raise Exception()