def _retrieve_show_images_from_tmdb(self, name, id=None, backdrop=False, poster=False): tmdb = TMDB(sickbeard.TMDB_API_KEY) result = None # get TMDB configuration info config = tmdb.Configuration() response = config.info() base_url = response['images']['base_url'] sizes = response['images']['poster_sizes'] def size_str_to_int(x): return float("inf") if x == 'original' else int(x[1:]) max_size = max(sizes, key=size_str_to_int) try: if id is None: search = tmdb.Search() response = search.collection({'query': name}) id = response['results'][0]['id'] result = tmdb.Collections(id) except: try: if id is None: search = tmdb.Search() response = search.tv({'query': name}) id = response['results'][0]['id'] result = tmdb.TV(id) except: pass if result is None: return None images = result.images() if len(images) > 0: # get backdrop urls if backdrop: rel_path = images['backdrops'][0]['file_path'] url = "{0}{1}{2}".format(base_url, max_size, rel_path) return url # get poster urls if poster: rel_path = images['posters'][0]['file_path'] url = "{0}{1}{2}".format(base_url, max_size, rel_path) return url return None
def _retrieve_show_images_from_tmdb(self, show, backdrop=False, poster=False): # get TMDB configuration info tmdb = TMDB(sickbeard.TMDB_API_KEY) config = tmdb.Configuration() response = config.info() base_url = response['images']['base_url'] sizes = response['images']['poster_sizes'] def size_str_to_int(x): return float("inf") if x == 'original' else int(x[1:]) max_size = max(sizes, key=size_str_to_int) try: search = tmdb.Search() for show_name in set(allPossibleShowNames(show)): for result in search.collection({'query': show_name})['results'] + search.tv({'query': show_name})[ 'results']: if backdrop and result['backdrop_path']: return "{0}{1}{2}".format(base_url, max_size, result['backdrop_path']) elif poster and result['poster_path']: return "{0}{1}{2}".format(base_url, max_size, result['poster_path']) except Exception, e: pass
def _retrieve_show_images_from_tmdb(self, show, type): types = { 'poster': 'poster_path', 'banner': None, 'fanart': 'backdrop_path', 'poster_thumb': 'poster_path', 'banner_thumb': None } # get TMDB configuration info tmdb = TMDB(sickbeard.TMDB_API_KEY) config = tmdb.Configuration() response = config.info() base_url = response['images']['base_url'] sizes = response['images']['poster_sizes'] def size_str_to_int(x): return float("inf") if x == 'original' else int(x[1:]) max_size = max(sizes, key=size_str_to_int) try: search = tmdb.Search() for show_name in set(allPossibleShowNames(show)): for result in search.collection({ 'query': show_name })['results'] + search.tv({'query': show_name})['results']: if types[type] and getattr(result, types[type]): return "{0}{1}{2}".format(base_url, max_size, result[types[type]]) except Exception as e: pass logger.log( u"Could not find any " + type + " images on TMDB for " + show.name, logger.DEBUG)