Example #1
0
    def collections(self, collection_id):
        """Obtains items in the collection of a given TMDB Collection ID.

        Args:
            collection_id: An Integer or String containing the TMDB Collection ID.
        """
        return tmdb.Collections(collection_id).info()
def movie_collection_loader(api_key, collection_id):
    """Load the movie collection information"""
    import tmdbsimple as movie_db
    if collection_id is not None:
        try:
            movie_db.API_KEY = api_key
            return movie_db.Collections(collection_id).info()
        except movie_db.APIKeyError:
            return None
def _get_moviecollection(collection_id, language=None):
    if not collection_id:
        return None
    details = '' if language is not None else 'images'
    collection = tmdbsimple.Collections(collection_id)
    try:
        return collection.info(language=language, append_to_response=details)
    except (Timeout, RequestsConnectionError, RequestException) as ex:
        return _format_error_message(ex)
Example #4
0
    def collections(self, collection_id):
        """Obtains items in the movie collection of a given TMDB Collection ID.

        Args:
            collection_id: An Integer or String containing the TMDB Collection ID.
        """
        try:
            return self._set_content_attributes(
                "movie",
                cache.handler(
                    "get collection by id",
                    page_key=collection_id,
                    function=tmdb.Collections(collection_id).info,
                    cache_duration=COLLECTION_CACHE_TIMEOUT,
                ),
            )

        except:
            log.handler(
                "Failed to obtain collection with ID " + str(collection_id) +
                "!",
                log.ERROR,
                _logger,
            )
Example #5
0
 def test_collections_translations(self):
     id = COLLECTION_ID
     collection = tmdb.Collections(id)
     response = collection.translations()
     self.assertTrue(hasattr(collection, 'translations'))
Example #6
0
 def test_collections_images(self):
     id = COLLECTION_ID
     collection = tmdb.Collections(id)
     response = collection.images()
     self.assertTrue(hasattr(collection, 'backdrops'))
Example #7
0
 def test_collections_info(self):
     id = COLLECTION_ID
     name = COLLECTION_NAME
     collection = tmdb.Collections(id)
     response = collection.info()
     self.assertEqual(collection.name, name)
Example #8
0
def get_tmdb_collection_parts(tmdb_id):
    logger.debug(f"Retrieving movie collection details for: {tmdb_id!r}")
    try:
        collection_details = {}

        # set api key
        tmdb.API_KEY = TMDB_KEY

        # get collection details
        details = tmdb.Collections(tmdb_id).info()
        if not isinstance(details, dict) or not misc.dict_contains_keys(details,
                                                                        ['id', 'name', 'parts', 'poster_path']):
            logger.error(f"Failed retrieving movie collection details from Tmdb for: {tmdb_id!r}")
            return None
        logger.trace(f"Retrieved Tmdb movie collection details for {tmdb_id!r}:")
        logger.trace(json.dumps(details, indent=2))

        # build collection_details
        collection_details['name'] = details['name']
        collection_details['poster_url'] = f"https://image.tmdb.org/t/p/original{details['poster_path']}"
        collection_details['overview'] = details['overview'] if 'overview' in details else ''

        for collection_part in details['parts']:
            if not misc.dict_contains_keys(collection_part, ['id', 'title']):
                logger.error(f"Failed processing collection part due to unexpected keys: {collection_part}")
                return None

            # retrieve movie details
            logger.debug(f"Retrieving movie details for collection part: {collection_part['title']!r} - "
                         f"TmdbId: {collection_part['id']}")
            movie = tmdb.Movies(collection_part['id']).info()

            # validate response
            if not isinstance(movie, dict) or not misc.dict_contains_keys(movie, ['id', 'imdb_id', 'title']):
                logger.error(f"Failed retrieving movie details from Tmdb for: {collection_part['title']!r} - "
                             f"TmdbId: {collection_part['id']}")
                return None

            # add part to collection details
            if 'parts' in collection_details:
                collection_details['parts'].append({
                    'title': movie['title'],
                    'tmdb_id': movie['id'],
                    'imdb_id': movie['imdb_id']
                })
            else:
                collection_details['parts'] = [{
                    'title': movie['title'],
                    'tmdb_id': movie['id'],
                    'imdb_id': movie['imdb_id']
                }]

            logger.trace(f"Retrieved Tmdb movie details for {collection_part['id']!r}:")
            logger.trace(json.dumps(movie, indent=2))

        logger.debug(json.dumps(collection_details, indent=2))
        return collection_details

    except Exception:
        logger.exception(f"Exception retrieving Tmdb collection details for {tmdb_id!r}: ")
    return None