Ejemplo n.º 1
0
 def setUp(self):
     self.tmdb = TMDb()
     self.tmdb.api_key = os.environ["TMDB_API_KEY"]
     self.tmdb.language = "en-US"
     self.tmdb.debug = True
     self.tmdb.wait_on_rate_limit = True
     self.tmdb.cache = False
     self.configuration = Configuration()
Ejemplo n.º 2
0
def tmdb_api(movie_name):
    try:
        movie = Movie()
        genre = Genre()
        config = Configuration()
        info = config.info()
        secure_base_url = info.images['secure_base_url']
        poster_size = "w500/"
        ret_dict = {}
        genres = {}
        genres_objs = genre.movie_list()
        for g in genres_objs:
            genres[g.id] = g.name
        movie_list = movie.search(movie_name)
        for i, m in enumerate(movie_list):
            external_ids = movie.external_ids(m.id)
            if 'imdb_id' in external_ids and external_ids[
                    'imdb_id'] is not None:
                external_id = external_ids['imdb_id'][2:]
                release_date = ""
                if hasattr(m, 'release_date') and m.release_date != "":
                    rel_date = m.release_date
                    date_obj = datetime.strptime(rel_date, '%Y-%m-%d')
                    release_date = date_obj.strftime('%d %B %Y')
                poster_path = ""
                if hasattr(m, 'poster_path') and m.poster_path != "" and str(
                        m.poster_path) != "None":
                    poster_path = secure_base_url + poster_size + str(
                        m.poster_path)
                ret_dict[i] = {
                    'title':
                    m.title if hasattr(m, 'title') else "",
                    'plot':
                    m.overview if hasattr(m, 'overview') else "",
                    'image':
                    poster_path,
                    'director':
                    "",
                    'release_date':
                    release_date,
                    'genre':
                    ', '.join(map(lambda x: genres[x], m.genre_ids))
                    if hasattr(m, 'genre_ids') else "",
                    'movie_id':
                    external_id
                }
        return ret_dict

    except exceptions.ConnectionError:
        raise TMDBConnectionException()
    except Exception:
        raise TMDBParsingException()
Ejemplo n.º 3
0
class ConfigurationTests(unittest.TestCase):
    def setUp(self):
        self.tmdb = TMDb()
        self.tmdb.api_key = os.environ["TMDB_API_KEY"]
        self.tmdb.language = "en-US"
        self.tmdb.debug = True
        self.tmdb.wait_on_rate_limit = True
        self.tmdb.cache = False
        self.configuration = Configuration()

    def test_configuration_info(self):
        info = self.configuration.info()
        self.assertTrue(hasattr(info, "images"))
        self.assertTrue(hasattr(info, "change_keys"))
        self.assertIn("base_url", info.images)
        self.assertIn("secure_base_url", info.images)
        self.assertIn("backdrop_sizes", info.images)
        self.assertIn("logo_sizes", info.images)
        self.assertIn("poster_sizes", info.images)
        self.assertIn("profile_sizes", info.images)
        self.assertIn("still_sizes", info.images)

    def test_configuration_countries(self):
        countries = self.configuration.countries()
        self.assertGreater(len(countries), 0)
        for country in countries:
            self.assertIn("iso_3166_1", country)
            self.assertIn("english_name", country)

    def test_configuration_jobs(self):
        jobs = self.configuration.jobs()
        self.assertGreater(len(jobs), 0)
        for job in jobs:
            self.assertIn("department", job)
            self.assertIn("jobs", job)

    def test_configuration_languages(self):
        languages = self.configuration.languages()
        self.assertGreater(len(languages), 0)
        for language in languages:
            self.assertIn("iso_639_1", language)
            self.assertIn("english_name", language)
            self.assertIn("name", language)

    def test_configuration_primary_translations(self):
        primary_translations = self.configuration.primary_translations()
        self.assertGreater(len(primary_translations), 0)
        self.assertIn("en-US", primary_translations)

    def test_configuration_timezones(self):
        timezones = self.configuration.timezones()
        self.assertGreater(len(timezones), 0)
        for timezone in timezones:
            self.assertIn("iso_3166_1", timezone)
            self.assertIn("zones", timezone)
Ejemplo n.º 4
0
 def test_config(self):
     config = Configuration()
     info = config.info()
     self.assertIsNotNone(info)
     self.assertTrue(hasattr(info, 'images'))
Ejemplo n.º 5
0
from tmdbv3api import TMDb, Configuration

tmdb = TMDb()
tmdb.api_key = ''

config = Configuration()
info = config.info()

poster_sizes = info.images['poster_sizes']
print(poster_sizes)

secure_base_url = info.images['secure_base_url']
print(secure_base_url)
Ejemplo n.º 6
0
from tmdbv3api import TMDb, Configuration

tmdb = TMDb()
tmdb.api_key = ""

configuration = Configuration()

info = configuration.info()

print('Change keys: ' + ', '.join(info.change_keys))
print('Base url: ' + info.images["base_url"])
print('Secure base url: ' + info.images["secure_base_url"])
print('Backdrop sizes: ' + ', '.join(info.images["backdrop_sizes"]))
print('Logo sizes: ' + ', '.join(info.images["logo_sizes"]))
print('Poster sizes: ' + ', '.join(info.images["poster_sizes"]))
print('Profile sizes: ' + ', '.join(info.images["profile_sizes"]))
print('Still sizes: ' + ', '.join(info.images["still_sizes"]))

countries = configuration.countries()

for country in countries:
    print('English name: ' + country['english_name'])
    print('iso_3166_1: ' + country['iso_3166_1'])

jobs = configuration.jobs()

for job in jobs:
    print(job['department'] + ': ' + ', '.join(job['jobs']))

languages = configuration.languages()