コード例 #1
0
    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
コード例 #2
0
    def _tmdb_image_url(show, image_type):
        types = {'poster': 'poster_path',
                 'banner': None,
                 'fanart': 'backdrop_path',
                 'fanart_all': 'backdrops',
                 '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:
            itemlist = []
            for (src, name) in [(indexer_config.INDEXER_TVDB, 'tvdb'), (indexer_config.INDEXER_IMDB, 'imdb'),
                                (indexer_config.INDEXER_TVRAGE, 'tvrage')]:
                is_id = show.ids.get(src, {}).get('id', None)
                if not is_id:
                    continue

                result = tmdb.Find(is_id).info({'external_source': '%s_id' % name})
                if 'tv_results' not in result or not len(result['tv_results']):
                    continue

                tmdb_show = result['tv_results'][0]

                if 'fanart' == image_type:
                    tv_obj = tmdb.TV(tmdb_show['id'])
                    rjson_info = tv_obj.info({'append_to_response': 'images', 'include_image_language': 'en,null'})
                    rjson_img = rjson_info['images']
                    for art in rjson_img[types['fanart_all']] or []:
                        if 'vote_average' not in art or 'file_path' not in art:
                            continue
                        art_likes = art['vote_average']
                        url = u'%s%s%s' % (base_url, max_size, art['file_path'])
                        itemlist += [[tmdb_show['id'], art_likes, url]]

                    itemlist.sort(lambda a, b: cmp((a[1]), (b[1])), reverse=True)
                    return itemlist

                elif tmdb_show[types[image_type]]:
                    return [[tmdb_show['id'], tmdb_show['vote_average'], '%s%s%s' % (base_url, max_size, tmdb_show[types[image_type]])]]

        except (StandardError, Exception):
            pass

        logger.log(u'Could not find any %s images on TMDB for %s' % (image_type, show.name), logger.DEBUG)