def _retrieve_show_image(self, image_type, show_obj, episode=None, which=None): """ Get an image URL from theTVDB.com and TMDB.com, download it and returns the data. :param image_type: type of image to retrieve (currently supported: fanart, poster, banner) :param show_obj: a Series object to use when searching for the image :param episode: Episode object (only needed for episode thumbnails) :param which: optional, a specific numbered poster to look for :return: the binary image data if available, or else None """ image_url = None indexer_show_obj = self._get_show_data(show_obj) if not indexer_show_obj: return None if image_type not in (u'fanart', u'poster', u'banner', u'thumbnail', u'poster_thumb', u'banner_thumb'): log.error( u'Invalid {image}, unable to find it in the {indexer}', {u'image': image_type, u'indexer': show_obj.indexer_name} ) return None if image_type == u'thumbnail' and episode: image_url = self._get_episode_thumb_url(indexer_show_obj, episode) elif image_type == u'poster_thumb': if getattr(indexer_show_obj, u'poster', None): if show_obj.indexer == INDEXER_TVDBV2 or INDEXER_GLOTZ: image_url = indexer_show_obj[u'poster'].replace('.jpg', '_t.jpg') else: image_url = re.sub(u'posters', u'_cache/posters', indexer_show_obj[u'poster']) if not image_url: # Try and get images from TMDB image_url = self._retrieve_show_images_from_tmdb(show_obj, image_type) elif image_type == u'banner_thumb': if getattr(indexer_show_obj, u'banner', None): if show_obj.indexer == INDEXER_TVDBV2 or INDEXER_GLOTZ: image_url = indexer_show_obj[u'banner'].replace('.jpg', '_t.jpg') else: image_url = re.sub(u'graphical', u'_cache/graphical', indexer_show_obj[u'banner']) else: if getattr(indexer_show_obj, image_type, None): image_url = indexer_show_obj[image_type] if not image_url and show_obj.indexer != INDEXER_TMDB: # Try and get images from TMDB image_url = self._retrieve_show_images_from_tmdb(show_obj, image_type) if image_url: image_data = get_image(image_url, which) return image_data return None
def save_season_banners(self, show_obj, season): """ Saves all season banners to disk for the given show. show_obj: a Series object for which to save the season thumbs Cycles through all seasons and saves the season banners if possible. This method should not need to be overridden by implementing classes, changing _season_banners_dict and get_season_banner_path should be good enough. """ season_dict = self._season_banners_dict(show_obj, season) result = [] # Returns a nested dictionary of season art with the season # number as primary key. It's really overkill but gives the option # to present to user via ui to pick down the road. for cur_season in season_dict: cur_season_art = season_dict[cur_season] if not cur_season_art: continue # Just grab whatever's there for now _, season_url = cur_season_art.popitem() # @UnusedVariable season_banner_file_path = self.get_season_banner_path( show_obj, cur_season) if not season_banner_file_path: log.debug( u'Path for season {number} came back blank, skipping this season', {u'number': cur_season}) continue seasonData = get_image(season_url) if not seasonData: log.debug( u'No season banner data available, skipping this season') continue result += [self._write_image(seasonData, season_banner_file_path)] if result: return all(result) else: return False