def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = "en" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.person = Person()
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['api_key'] self.movie = Movie() self.discover = Discover() self.tv = TV() self.person = Person() self.collection = Collection() self.company = Company() self.season = Season()
def tmdb_get_summary(data, type): collection = Collection() person = Person() collection.api_key = config_tools.TMDB().apikey person.api_key = collection.api_key collection.language = config_tools.TMDB().language person.language = collection.language if type == "overview": return collection.details(data).overview elif type == "biography": return person.details(data).biography
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = 'en' self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.movie = Movie() self.discover = Discover() self.tv = TV() self.person = Person() self.collection = Collection() self.company = Company() self.season = Season()
def makeWebhookResult(data): print("starting makeWebhookResult...") res = data['results'] result = res[0] id = result['id'] person = Person() p = person.details(id) speech = "Here is a short biography of " + p.name + ": \n\n" + p.biography print("Response:") print(speech) return {"fulfillmentText": speech, "source": "apiai-movie-webhook-sample"}
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ["TMDB_API_KEY"] self.tmdb.language = "en" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.movie = Movie() self.discover = Discover() self.tv = TV() self.person = Person() self.collection = Collection() self.company = Company() self.network = Network() self.search = Search() self.season = Season() self.list = List()
def import_actor(start, end): person_list = [] for i in range(start, end): try: p = Person().details(i) tmdb_id = p.id imdb_id = p.imdb_id name = p.name biography = p.biography profile_path = p.profile_path gender = "Other" # 0 - Not specified 1 - Female 2 - Male 3 - no binary if p.gender == 2: gender = "Male" elif p.gender == 1: gender = "Female" date_birth = p.birthday actor = DbActor(tmdb_id, imdb_id, name, biography, profile_path, gender, date_birth) person_list.append(actor) print(actor.tmdb_id, actor.imdb_id, actor.name, actor.profile_path, actor.gender, actor.date_birth) # print(actor.biography) except TMDbException: pass return person_list
def clean_votes(award, vote_list): actor_contain = 'performance' in award or 'director' in award or 'screenplay' in award or 'score' in award or 'actor' in award or 'actress' in award if(not actor_contain): actor_contain = award in PEOPLE_AWARDS mov_contain = 'motion picture' in award or 'feature' in award or 'film' in award if(not mov_contain): mov_contain = award in ENTITY_AWARDS tv_contain = 'television' in award cleaned_votes = [] if(actor_contain): for vote in vote_list: text = vote[0] person = Person() result = person.search(text) if(len(result) > 0): res = str(result[0]) ind = get_curr_index(res, cleaned_votes) if(ind != -1): cleaned_votes[ind][1] = cleaned_votes[ind][1] + vote[1] else: cleaned_votes.append([res, vote[1]]) elif(mov_contain): for vote in vote_list: text = vote[0] movie = Movie() result = movie.search(text) if(len(result) > 0): res = str(result[0]) ind = get_curr_index(res, cleaned_votes) if(ind != -1): cleaned_votes[ind][1] = cleaned_votes[ind][1] + vote[1] else: cleaned_votes.append([res, vote[1]]) if(tv_contain and not actor_contain): for vote in vote_list: text = vote[0] tv = TV() result = tv.search(text) if(len(result) > 0): res = str(result[0]) ind = get_curr_index(res, cleaned_votes) if(ind != -1): cleaned_votes[ind][1] = cleaned_votes[ind][1] + vote[1] else: cleaned_votes.append([res, vote[1]]) return cleaned_votes
def tmdb_get_metadata(config_path, data, type): # Instantiate TMDB objects tmdb_id = int(data) api_key = config_tools.TMDB(config_path).apikey language = config_tools.TMDB(config_path).language is_movie = config_tools.Plex(config_path).library_type == "movie" if type in ["overview", "poster", "backdrop"]: collection = Collection() collection.api_key = api_key collection.language = language try: if type == "overview": meta = collection.details(tmdb_id).overview elif type == "poster": meta = collection.details(tmdb_id).poster_path elif type == "backdrop": meta = collection.details(tmdb_id).backdrop_path except AttributeError: media = Movie() if is_movie else TV() media.api_key = api_key media.language = language try: if type == "overview": meta = media.details(tmdb_id).overview elif type == "poster": meta = media.details(tmdb_id).poster_path elif type == "backdrop": meta = media.details(tmdb_id).backdrop_path except AttributeError: raise ValueError( "| TMDb Error: TMBd {} ID: {} not found".format( "Movie/Collection" if is_movie else "Show", tmdb_id)) elif type in ["biography", "profile", "name"]: person = Person() person.api_key = api_key person.language = language try: if type == "biography": meta = person.details(tmdb_id).biography elif type == "profile": meta = person.details(tmdb_id).profile_path elif type == "name": meta = person.details(tmdb_id).name except AttributeError: raise ValueError( "| TMDb Error: TMBd Actor ID: {} not found".format(tmdb_id)) else: raise RuntimeError( "type {} not yet supported in tmdb_get_metadata".format(type)) if meta is None: raise ValueError("| TMDb Error: TMDB ID {} has no {}".format( tmdb_id, type)) elif type in ["profile", "poster", "backdrop"]: return "https://image.tmdb.org/t/p/original" + meta else: return meta
class PersonTests(unittest.TestCase): def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = "en" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.person = Person() def test_get_person(self): person = self.person.details(234) self.assertIsNotNone(person) self.assertTrue(hasattr(person, "id")) def test_get_person_search(self): search_person = self.person.search("Bryan") self.assertIsNotNone(search_person) self.assertGreater(len(search_person), 0) for person in search_person: self.assertTrue(hasattr(person, "id")) def test_get_person_popular(self): popular = self.person.popular() self.assertTrue(len(popular) > 0) first = popular[0] self.assertTrue(hasattr(first, "name")) self.assertTrue(hasattr(first, "known_for")) def test_get_person_latest(self): latest = self.person.latest() self.assertIsNotNone(latest) self.assertTrue(hasattr(latest, "name")) self.assertTrue(hasattr(latest, "id")) def test_get_person_images(self): images = self.person.images(11) self.assertIsNotNone(images) self.assertTrue(hasattr(images, "profiles")) self.assertTrue(hasattr(images, "id"))
def present_voter(tweets, award, nom_list): curr_votes_list = [] for tweet in tweets: tweet_text = tweet["text"] tweet_tags = tweet["tags"] people = tweet_tags[0] # contains = award in tweet_text contains = partial_award_check(award.lower(), tweet_text) if(contains): for person in people: ind = get_curr_index(person, curr_votes_list) if(ind != -1): curr_votes_list[ind][1] = curr_votes_list[ind][1] + 1 else: curr_votes_list.append([person, 1]) cleaned_votes = [] for vote in curr_votes_list: text = vote[0] person = Person() result = person.search(text) if(len(result) > 0): res = str(result[0]) if(res in nom_list): continue ind = get_curr_index(res, cleaned_votes) if(ind != -1): cleaned_votes[ind][1] = cleaned_votes[ind][1] + vote[1] else: cleaned_votes.append([res, vote[1]]) cleaned_votes.sort(key=vote_sort, reverse=True) count = 0 presenters_list = [] for vote in cleaned_votes: if(count == 1): break presenters_list.append(vote[0]) count += 1 return presenters_list
def __init__(self): api_key = "e9ee4dd66aa205b259f29ccb98e9a989" self.tmdb = TMDb() self.tmdb.api_key = api_key self.tmdb.language = 'en' self.tmdb.debug = True self.movie = Movie(self.tmdb) self.discover = Discover(self.tmdb) # build the genre database self.genre = Genre(self.tmdb) genres = self.genre.movie_list() # list self.genres_dict = {} # a dict with keys: genre names and values: id for g in genres: self.genres_dict[g.name] = g.id # build the language database (ISO 639-1) self.language_dict = {} with open('./csv/language-codes_csv.csv', newline='') as csvfile: reader = csv.reader(csvfile, delimiter=',') for row in reader: self.language_dict[row[1]] = row[0] self.person = Person(self.tmdb) self.company = Company(self.tmdb) # initialize the searching attributes self.search_genre = None self.search_without_genre = None self.search_cast = None self.search_crew = None self.search_people = None self.search_company = None self.search_year = None self.search_upper_year = None self.search_lower_year = None self.search_rating = None self.search_language = None
def tmdb_get_summary(config_path, data, type): # Instantiate TMDB objects collection = Collection() collection.api_key = config_tools.TMDB(config_path).apikey collection.language = config_tools.TMDB(config_path).language person = Person() person.api_key = collection.api_key person.language = collection.language # Return object based on type if type == "overview": return collection.details(data).overview elif type == "biography": return person.details(data).biography elif type == "poster_path": return collection.details(data).poster_path elif type == "profile_path": return person.details(data).profile_path else: raise RuntimeError("type not yet supported in tmdb_get_summary")
# import of python modules import configparser import time import requests # import of the movie database module from tmdbv3api import TMDb from tmdbv3api import Movie from tmdbv3api import TV from tmdbv3api import Person # variables for the movie database module tmdb = TMDb() movie = Movie() tv = TV() person = Person() # reading the ini files for the offline genres of movies and series config = configparser.ConfigParser() config.read("moviegenre.ini") config.read("seriegenre.ini") # start by asking The movie database account or not def start(): TMDB_or_not = input( "Do you have an account for The movie database? type 'y' for yes and 'n' for no " ) if (TMDB_or_not == "y"): print( "You selected yes, you will be directed to The movie database login."
class TMDbTests(unittest.TestCase): def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = 'en' self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.movie = Movie() self.discover = Discover() self.tv = TV() self.person = Person() self.collection = Collection() self.company = Company() self.season = Season() def test_get_movie(self): movie = self.movie.details(111) self.assertIsNotNone(movie) self.assertEqual(movie.title, 'Scarface') self.assertEqual(movie.id, 111) self.assertTrue(hasattr(movie, 'title')) self.assertTrue(hasattr(movie, 'overview')) self.assertTrue(hasattr(movie, 'id')) def test_get_movie_reviews(self): search = self.movie.search("Mad Max") self.assertTrue(len(search) > 0) first = search[0] reviews = self.movie.reviews(first.id) self.assertTrue(len(reviews) > 0) for review in reviews: self.assertTrue(hasattr(review, 'id')) self.assertTrue(hasattr(review, 'content')) def test_get_movie_lists(self): lists = self.movie.lists(111) self.assertTrue(len(lists) > 0) self.assertTrue(hasattr(lists[0], 'description')) self.assertTrue(hasattr(lists[0], 'name')) def test_get_movie_videos(self): videos = self.movie.videos(111) self.assertTrue(len(videos) > 0) self.assertTrue(hasattr(videos[0], 'id')) def test_get_movie_recommendations(self): recs = self.movie.recommendations(111) self.assertTrue(len(recs) > 0) self.assertTrue(hasattr(recs[0], 'id')) def test_discover_movies(self): discover = self.discover.discover_movies({ 'primary_release_year': '2015', 'with_genres': '28', 'page': '1', 'vote_average.gte': '8' }) self.assertTrue(len(discover) > 0) self.assertTrue(hasattr(discover[0], 'id')) movie = discover[0] has_genre = False for genre_id in movie.genre_ids: if genre_id == 28: has_genre = True self.assertTrue(has_genre) def test_discover_tv_shows(self): discover = self.discover.discover_tv_shows({ 'with_genres': '16', 'vote_average.gte': '8', 'page': '1' }) self.assertTrue(len(discover) > 0) self.assertTrue(hasattr(discover[0], 'id')) movie = discover[0] has_genre = False for genre_id in movie.genre_ids: if genre_id == 16: has_genre = True self.assertTrue(has_genre) def test_get_latest_movie(self): videos = self.movie.latest() self.assertIsNotNone(videos) self.assertTrue(hasattr(videos, 'id')) def test_now_playing(self): now_playing = self.movie.now_playing() self.assertTrue(len(now_playing) > 0) self.assertTrue(hasattr(now_playing[0], 'id')) def test_top_rated(self): top_rated = self.movie.top_rated() self.assertTrue(len(top_rated) > 0) self.assertTrue(hasattr(top_rated[0], 'id')) def test_upcoming(self): upcoming = self.movie.upcoming() self.assertTrue(len(upcoming) > 0) self.assertTrue(hasattr(upcoming[0], 'id')) def test_popular(self): popular = self.movie.popular() self.assertTrue(len(popular) > 0) self.assertTrue(hasattr(popular[0], 'id')) def test_search(self): search = self.movie.search('Mad Max') self.assertTrue(len(search) > 0) self.assertTrue(hasattr(search[0], 'id')) def test_similar(self): similar = self.movie.similar(111) self.assertTrue(len(similar) > 0) self.assertTrue(hasattr(similar[0], 'id')) def test_get_tv_show(self): show = self.tv.details(12) self.assertIsNotNone(show) self.assertTrue(hasattr(show, 'id')) def test_get_latest_tv_show(self): latest_tv = self.tv.latest() self.assertIsNotNone(latest_tv) self.assertTrue(hasattr(latest_tv, 'id')) def test_search_tv(self): search_tv = self.tv.search('Sunny') self.assertTrue(len(search_tv) > 0) self.assertTrue(hasattr(search_tv[0], 'id')) def test_popular_shows(self): popular = self.tv.popular() self.assertTrue(len(popular) > 0) self.assertTrue(hasattr(popular[0], 'id')) def test_top_rated_shows(self): top_rated = self.tv.top_rated() self.assertTrue(len(top_rated) > 0) self.assertTrue(hasattr(top_rated[0], 'id')) def test_get_person(self): person = self.person.details(234) self.assertIsNotNone(person) self.assertTrue(hasattr(person, 'id')) def test_search_person(self): search_person = self.person.search('Bryan') self.assertTrue(len(search_person) > 0) self.assertTrue(hasattr(search_person[0], 'id')) def test_collection_details(self): c = Collection() details = c.details(10) self.assertEqual(details.name, 'Star Wars Collection') self.assertEqual(details.id, 10) self.assertTrue(hasattr(details, 'overview')) self.assertTrue(hasattr(details, 'poster_path')) def test_collection_images(self): c = Collection() images = c.images(10) self.assertTrue(hasattr(images, 'backdrops')) self.assertTrue(hasattr(images, 'posters')) def test_popular_people(self): popular = self.person.popular() self.assertTrue(len(popular) > 0) first = popular[0] self.assertTrue(hasattr(first, 'name')) self.assertTrue(hasattr(first, 'known_for')) def test_latest_person(self): latest_person = self.person.latest() self.assertIsNotNone(latest_person) self.assertTrue(hasattr(latest_person, 'name')) self.assertTrue(hasattr(latest_person, 'id')) def test_person_images(self): images = self.person.images(11) self.assertIsNotNone(images) self.assertTrue(hasattr(images, 'profiles')) self.assertTrue(hasattr(images, 'id')) def test_company_details(self): c = self.company.details(1) self.assertTrue(hasattr(c, 'name')) self.assertEqual(c.name, 'Lucasfilm') def test_company_movies(self): company = self.company.movies(1) self.assertTrue(len(company) > 0) first = company[0] self.assertTrue(hasattr(first, 'title')) self.assertTrue(hasattr(first, 'overview')) def test_config(self): config = Configuration() info = config.info() self.assertIsNotNone(info) self.assertTrue(hasattr(info, 'images')) def test_genres(self): genres = Genre() movie_genres = genres.movie_list() self.assertIsNotNone(movie_genres) tv_genres = genres.tv_list() self.assertIsNotNone(tv_genres) def test_season(self): s = self.season.details(1418, 1) self.assertIsNotNone(s) self.assertEqual(s.name, 'Season 1') self.assertEqual(s.id, 3738) self.assertTrue(hasattr(s, 'episodes')) self.assertTrue(hasattr(s, 'overview')) self.assertTrue(hasattr(s, 'id')) def test_get_season_changes(self): s = self.season.changes(1418, 1) self.assertIsNotNone(s) def test_get_season_external_ids(self): s = self.season.external_ids(1418, 1) self.assertIsNotNone(s) self.assertIsNotNone(s['tvdb_id']) def test_get_season_videos(self): s = self.season.videos(1418, 1) def test_get_season_images(self): s = self.season.images(1418, 1) for l in s: self.assertIsNotNone(l.width) self.assertIsNotNone(l.height) def test_get_season_credits(self): s = self.season.credits(1418, 1) for c in s: self.assertIsNotNone(c.name) self.assertIsNotNone(c.character) def test_get_movie_by_external_id(self): ex = self.movie.external(external_id="tt8155288", external_source="imdb_id") res = ex['movie_results'][0] self.assertTrue(res['title'] == "Happy Death Day 2U")
class tmdb_base(): def __init__(self): api_key = "e9ee4dd66aa205b259f29ccb98e9a989" self.tmdb = TMDb() self.tmdb.api_key = api_key self.tmdb.language = 'en' self.tmdb.debug = True self.movie = Movie(self.tmdb) self.discover = Discover(self.tmdb) # build the genre database self.genre = Genre(self.tmdb) genres = self.genre.movie_list() # list self.genres_dict = {} # a dict with keys: genre names and values: id for g in genres: self.genres_dict[g.name] = g.id # build the language database (ISO 639-1) self.language_dict = {} with open('./csv/language-codes_csv.csv', newline='') as csvfile: reader = csv.reader(csvfile, delimiter=',') for row in reader: self.language_dict[row[1]] = row[0] self.person = Person(self.tmdb) self.company = Company(self.tmdb) # initialize the searching attributes self.search_genre = None self.search_without_genre = None self.search_cast = None self.search_crew = None self.search_people = None self.search_company = None self.search_year = None self.search_upper_year = None self.search_lower_year = None self.search_rating = None self.search_language = None def set_attributes(self, json_): """ given a json from furhat, set the searching attributes """ # conv = json.loads(json_) conv = json_ actor = conv["actors"]["selected"] # list. genre = conv["genres"]["selected"] # list. without_genre = conv["genres"]["deselected"] # list. company = conv["company"]["selected"] # list. language = conv["language"]["selected"] # list. director = conv["director"]["selected"] # list. upper_year = conv["years"]["upper"] # None or int. lower_year = conv["years"]["lower"] # None or int. rating = conv["rating"] # None or int. self.search_upper_year = upper_year self.search_lower_year = lower_year self.rating = rating if len(actor) > 0: self.search_cast = actor if len(director) > 0: self.search_crew = director if len(genre) > 0: self.search_genre = genre if len(without_genre) > 0: self.search_without_genre = without_genre if len(company) > 0: self.search_company = company if len(language) > 0: self.search_language = language def set_language(self, language): """ set the query language, better not change it language: sting: English, Spanish, etc """ self.tmdb.language = self.language_dict[str(language).capitalize()] def name_to_id(self, names): """ names: List of strings return: id: string """ ids = [] for name in names: id_ = self.person.search_id(name) if len(id_) > 0: ids.append(str(id_[0])) return ",".join(ids) def genre_to_id(self, genres): """ genres: List of strings return: id: string """ ids = [] for genre in genres: id_ = self.genres_dict[str(genre).capitalize()] ids.append(str(id_)) return ",".join(ids) def company_to_id(self, companies): """ companies: List of strings return: id: string """ ids = [] for company in companies: id_ = self.company.search_id(company) if len(id_) > 0: id_sorted = sorted([item.id for item in id_]) ids.append(str(id_sorted[0])) return ",".join(ids) def language_to_iso_639(self, languages): """ languages: List of strings return: languages in ISO 639-1 format: string """ ids = [] for language in languages: id_ = self.language_dict[str(language).capitalize()] ids.append(id_) return ",".join(ids) def search_movies(self, top=10): """ with_genres: string: Comma separated value of genre ids that you want to include in the results. without_genres: string: Comma separated value of genre ids that you want to exclude from the results. with_cast: string: A comma separated list of person ID's. Only include movies that have one of the ID's added as an actor. with_crew: string: A comma separated list of person ID's. Only include movies that have one of the ID's added as a crew member. with_people: string: A comma separated list of person ID's. Only include movies that have one of the ID's added as a either a actor or a crew member. with_companies: string: A comma separated list of production company ID's. Only include movies that have one of the ID's added as a production company. year: integer: A filter to limit the results to a specific year (looking at all release dates). release_date.gte: string (year-month-day): Filter and only include movies that have a release date (looking at all release dates) that is greater or equal to the specified value. release_date.lte: string (year-month-day): Filter and only include movies that have a release date (looking at all release dates) that is less than or equal to the specified value. vote_average.gte: number: Filter and only include movies that have a rating that is greater or equal to the specified value. with_original_language: string: Specify an ISO 639-1 string to filter results by their original language value. """ request_dic = {} request_dic['sort_by'] = 'vote_average.desc' request_dic['vote_count.gte'] = 10 if self.search_genre is not None: request_dic['with_genres'] = self.genre_to_id(self.search_genre) if self.search_without_genre is not None: request_dic['without_genres'] = self.genre_to_id( self.search_without_genre) if self.search_year is not None: request_dic['year'] = self.search_year else: if self.search_upper_year is not None: request_dic['release_date.lte'] = str( self.search_upper_year) + "-12-31" if self.search_lower_year is not None: request_dic['release_date.gte'] = str( self.search_lower_year) + "-01-01" if self.search_rating is not None: request_dic['vote_average.gte'] = self.search_rating if self.search_company is not None: request_dic['with_companies'] = self.company_to_id( self.search_company) if self.search_cast is not None: request_dic['with_cast'] = self.name_to_id(self.search_cast) elif self.search_crew is not None: request_dic['with_crew'] = self.name_to_id(self.search_crew) elif self.search_people is not None: request_dic['with_people'] = self.name_to_id(self.search_people) if self.search_language is not None: request_dic['with_original_language'] = self.language_to_iso_639( self.search_language) show = self.discover.discover_movies(request_dic) # return the top 10 list by default return [str(item) for item in show[:top]]
class TMDbTests(unittest.TestCase): def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ["TMDB_API_KEY"] self.tmdb.language = "en" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.movie = Movie() self.discover = Discover() self.tv = TV() self.person = Person() self.collection = Collection() self.company = Company() self.season = Season() self.list = List() def test_get_tv_keywords(self): keywords = self.tv.keywords(1396) self.assertGreater(len(keywords), 0) def test_get_tv_reviews(self): reviews = self.tv.reviews(1396) self.assertGreater(len(reviews), 0) def test_get_movie_repr(self): search = self.movie.search("Mad Max") for results in search: print(results) def test_get_tv_show_repr(self): search_tv = self.tv.search("Breaking Bad") for results in search_tv: print(results) def test_get_movie(self): movie = self.movie.details(111) self.assertIsNotNone(movie) self.assertEqual(movie.title, "Scarface") self.assertEqual(movie.id, 111) self.assertTrue(hasattr(movie, "title")) self.assertTrue(hasattr(movie, "overview")) self.assertTrue(hasattr(movie, "id")) def test_get_movie_reviews(self): search = self.movie.search("Mad Max") self.assertTrue(len(search) > 0) first = search[0] reviews = self.movie.reviews(first.id) self.assertTrue(len(reviews) > 0) for review in reviews: self.assertTrue(hasattr(review, "id")) self.assertTrue(hasattr(review, "content")) def test_get_movie_lists(self): lists = self.movie.lists(111) self.assertTrue(len(lists) > 0) self.assertTrue(hasattr(lists[0], "description")) self.assertTrue(hasattr(lists[0], "name")) def test_get_movie_credits(self): credits = self.movie.credits(111) print(credits) self.assertIsNotNone(credits) def test_get_movie_images(self): images = self.movie.images(111) print(images) self.assertIsNotNone(images) def test_get_movie_videos(self): videos = self.movie.videos(111) self.assertTrue(len(videos) > 0) self.assertTrue(hasattr(videos[0], "id")) def test_get_movie_recommendations(self): recs = self.movie.recommendations(111) self.assertTrue(len(recs) > 0) self.assertTrue(hasattr(recs[0], "id")) def test_discover_movies(self): discover = self.discover.discover_movies({ "primary_release_year": "2015", "with_genres": "28", "page": "1", "vote_average.gte": "8", }) self.assertTrue(len(discover) > 0) self.assertTrue(hasattr(discover[0], "id")) movie = discover[0] has_genre = False for genre_id in movie.genre_ids: if genre_id == 28: has_genre = True self.assertTrue(has_genre) def test_discover_tv_shows(self): discover = self.discover.discover_tv_shows({ "with_genres": "16", "vote_average.gte": "8", "page": "1" }) self.assertTrue(len(discover) > 0) self.assertTrue(hasattr(discover[0], "id")) movie = discover[0] has_genre = False for genre_id in movie.genre_ids: if genre_id == 16: has_genre = True self.assertTrue(has_genre) def test_get_latest_movie(self): videos = self.movie.latest() self.assertIsNotNone(videos) self.assertTrue(hasattr(videos, "id")) def test_now_playing(self): now_playing = self.movie.now_playing() self.assertTrue(len(now_playing) > 0) self.assertTrue(hasattr(now_playing[0], "id")) def test_top_rated(self): top_rated = self.movie.top_rated() self.assertTrue(len(top_rated) > 0) self.assertTrue(hasattr(top_rated[0], "id")) def test_upcoming(self): upcoming = self.movie.upcoming() self.assertTrue(len(upcoming) > 0) self.assertTrue(hasattr(upcoming[0], "id")) def test_popular(self): popular = self.movie.popular() self.assertTrue(len(popular) > 0) self.assertTrue(hasattr(popular[0], "id")) def test_search(self): search = self.movie.search("Mad Max") self.assertTrue(len(search) > 0) self.assertTrue(hasattr(search[0], "id")) def test_similar(self): similar = self.movie.similar(111) self.assertTrue(len(similar) > 0) self.assertTrue(hasattr(similar[0], "id")) def test_get_tv_show(self): show = self.tv.details(12) self.assertIsNotNone(show) self.assertTrue(hasattr(show, "id")) def test_on_the_air(self): show = self.tv.on_the_air() self.assertTrue(len(show) > 0) def test_airing_today(self): show = self.tv.on_the_air() self.assertTrue(len(show) > 0) def test_tv_videos(self): show = self.tv.videos(1396) self.assertTrue(len(show) > 0) def test_tv_recommendations(self): show = self.tv.recommendations(1396) self.assertTrue(len(show) > 0) def test_external_ids(self): show = self.tv.external_ids(1776) self.assertEqual(show["imdb_id"], "tt0488262") def test_get_latest_tv_show(self): latest_tv = self.tv.latest() self.assertIsNotNone(latest_tv) self.assertTrue(hasattr(latest_tv, "id")) def test_search_tv(self): search_tv = self.tv.search("Sunny") self.assertTrue(len(search_tv) > 0) self.assertTrue(hasattr(search_tv[0], "id")) def test_popular_shows(self): popular = self.tv.popular() self.assertTrue(len(popular) > 0) self.assertTrue(hasattr(popular[0], "id")) def test_top_rated_shows(self): top_rated = self.tv.top_rated() self.assertTrue(len(top_rated) > 0) self.assertTrue(hasattr(top_rated[0], "id")) def test_get_person(self): person = self.person.details(234) self.assertIsNotNone(person) self.assertTrue(hasattr(person, "id")) def test_search_person(self): search_person = self.person.search("Bryan") self.assertTrue(len(search_person) > 0) self.assertTrue(hasattr(search_person[0], "id")) def test_collection_details(self): c = Collection() details = c.details(10) self.assertEqual(details.name, "Star Wars Collection") self.assertEqual(details.id, 10) self.assertTrue(hasattr(details, "overview")) self.assertTrue(hasattr(details, "poster_path")) def test_collection_images(self): c = Collection() images = c.images(10) self.assertTrue(hasattr(images, "backdrops")) self.assertTrue(hasattr(images, "posters")) def test_popular_people(self): popular = self.person.popular() self.assertTrue(len(popular) > 0) first = popular[0] self.assertTrue(hasattr(first, "name")) self.assertTrue(hasattr(first, "known_for")) def test_latest_person(self): latest_person = self.person.latest() self.assertIsNotNone(latest_person) self.assertTrue(hasattr(latest_person, "name")) self.assertTrue(hasattr(latest_person, "id")) def test_person_images(self): images = self.person.images(11) self.assertIsNotNone(images) self.assertTrue(hasattr(images, "profiles")) self.assertTrue(hasattr(images, "id")) def test_company_details(self): c = self.company.details(1) self.assertTrue(hasattr(c, "name")) self.assertEqual(c.name, "Lucasfilm Ltd.") def test_company_movies(self): company = self.company.movies(1) self.assertTrue(len(company) > 0) first = company[0] self.assertTrue(hasattr(first, "title")) self.assertTrue(hasattr(first, "overview")) def test_config(self): config = Configuration() info = config.info() self.assertIsNotNone(info) self.assertTrue(hasattr(info, "images")) def test_genres(self): genres = Genre() movie_genres = genres.movie_list() self.assertIsNotNone(movie_genres) tv_genres = genres.tv_list() self.assertIsNotNone(tv_genres) def test_season(self): s = self.season.details(1418, 1) self.assertIsNotNone(s) self.assertEqual(s.name, "Season 1") self.assertEqual(s.id, 3738) self.assertTrue(hasattr(s, "episodes")) self.assertTrue(hasattr(s, "overview")) self.assertTrue(hasattr(s, "id")) def test_get_season_changes(self): s = self.season.changes(1418) self.assertIsNotNone(s) def test_get_season_external_ids(self): s = self.season.external_ids(1418, 1) self.assertIsNotNone(s) self.assertIsNotNone(s["tvdb_id"]) def test_get_season_videos(self): s = self.season.videos(1418, 1) def test_get_season_images(self): s = self.season.images(1418, 1) for l in s: self.assertIsNotNone(l.width) self.assertIsNotNone(l.height) def test_get_season_credits(self): s = self.season.credits(1418, 1) for c in s: self.assertIsNotNone(c.name) self.assertIsNotNone(c.character) def test_get_movie_by_external_id(self): ex = self.movie.external(external_id="tt8155288", external_source="imdb_id") res = ex["movie_results"][0] self.assertTrue(res["title"] == "Happy Death Day 2U") def test_get_list(self): list = self.list.details(list_id="112870") self.assertTrue(len(list) > 10) self.assertTrue(hasattr(list[0], "id")) self.assertTrue(hasattr(list[0], "title")) def test_get_certifications(self): certifications = Certification() movie_certifications = certifications.movie_list() self.assertIsNotNone(movie_certifications) tv_certifications = certifications.tv_list() self.assertIsNotNone(tv_certifications)
def options_tmdb(): print("") print("Type 0 to go exit the program.") print("Type 1 to get a list of the top 20 popular movies.") print("Type 2 to search for a movie.") print("Type 3 to see movie details by ID.") print("Type 4 to search for a serie.") print("Type 5 to search for information about a actor or actress.") TMDB_options = input( "What do you want to do on The movie database? Type a number from one of the options above. " ) print("") if (TMDB_options == "0"): exit() if (TMDB_options == "1"): popular = movie.popular() for p in popular: print("ID:", p.id) print("Title:", p.title) print("__________________________________________________") print("") time.sleep(3) options_tmdb() if (TMDB_options == "2"): search_input = input( "Type here the name of the movie you want to search: ") search_movie = movie.search(search_input) for res in search_movie: print("Movie ID:", res.id) print("Movie Title:", res.title) print("Average rating movie:", res.vote_average) print("__________________________________________________") print("") time.sleep(3) options_tmdb() if (TMDB_options == "3"): input_id = input( "What is the ID of the movie you want to know more about? ") m = movie.details(input_id) print("Movie title:", m.title) print("") print("Movie description:") print(m.overview) print("__________________________________________________") print("") time.sleep(3) options_tmdb() if (TMDB_options == "4"): show_input = input( "Type here the name of the serie you want to search: ") show = tv.search(show_input) for result in show: print("Serie title:", result.name) print("") print("Serie description:") print(result.overview) print("__________________________________________________") print("") time.sleep(3) options_tmdb() if (TMDB_options == "5"): print( "Who do you want to search? Please fill in the firstname and surname of the actor or actress." ) firstname = input("Firstname: ") surname = input("Surname: ") print("") fullname = firstname + "+" + surname url = "https://api.themoviedb.org/3/search/person?api_key=" + tmdb.api_key + "&query=" + fullname actordata = requests.get(url) x = actordata.text idfront = x.index("id") + 4 idback = x.index("known") - 2 id = x[idfront:idback] person = Person() p = person.details(id) print("Name actor/actress:", p.name) print("") print("Biography actor/actress:") print(p.biography) print("") time.sleep(3) options_tmdb() else: print( "You didn't type in one of the numbers in the list, Please try again." ) options_tmdb()