Beispiel #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.company = Company()
Beispiel #2
0
 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()
Beispiel #3
0
 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()
Beispiel #4
0
class CompanyTests(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.company = Company()

    def test_get_company_details(self):
        details = self.company.details(1)
        self.assertTrue(hasattr(details, "description"))
        self.assertTrue(hasattr(details, "headquarters"))
        self.assertTrue(hasattr(details, "homepage"))
        self.assertTrue(hasattr(details, "id"))
        self.assertTrue(hasattr(details, "logo_path"))
        self.assertTrue(hasattr(details, "name"))
        self.assertTrue(hasattr(details, "origin_country"))
        self.assertTrue(hasattr(details, "parent_company"))

    def test_get_company_alternative_names(self):
        alternative_names = self.company.alternative_names(1)
        self.assertGreater(len(alternative_names), 0)
        for alternative_name in alternative_names:
            self.assertTrue(hasattr(alternative_name, "name"))
            self.assertTrue(hasattr(alternative_name, "type"))

    def test_get_company_images(self):
        images = self.company.images(1)
        self.assertGreater(len(images), 0)
        for image in images:
            self.assertTrue(hasattr(image, "aspect_ratio"))
            self.assertTrue(hasattr(image, "file_path"))
            self.assertTrue(hasattr(image, "height"))
            self.assertTrue(hasattr(image, "id"))
            self.assertTrue(hasattr(image, "file_type"))
            self.assertTrue(hasattr(image, "vote_average"))
            self.assertTrue(hasattr(image, "vote_count"))
            self.assertTrue(hasattr(image, "width"))

    def test_get_company_movies(self):
        movies = self.company.movies(1)
        self.assertGreater(len(movies), 0)
        for movie in movies:
            self.assertTrue(hasattr(movie, "id"))
            self.assertTrue(hasattr(movie, "title"))
            self.assertTrue(hasattr(movie, "overview"))
Beispiel #5
0
 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()
Beispiel #6
0
    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
Beispiel #7
0
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")
Beispiel #8
0
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)
Beispiel #9
0
def tmdb_get_shows(config_path, plex, plex_map, data, method):
    config_tools.TraktClient(config_path)

    t_tvs = []
    t_tv = TV()
    t_tv.api_key = config_tools.TMDB(config_path).apikey
    if t_tv.api_key == "None":
        raise KeyError("Invalid TMDb API Key")

    count = 0
    if method in ["tmdb_discover", "tmdb_company", "tmdb_network"]:
        if method in ["tmdb_company", "tmdb_network"]:
            tmdb = Company() if method == "tmdb_company" else Network()
            tmdb.api_key = t_tv.api_key
            tmdb_id = int(data)
            tmdb_name = str(tmdb.details(tmdb_id))
            discover_method = "with_companies" if method == "tmdb_company" else "with_networks"
            attrs = {discover_method: tmdb_id}
            limit = 0
        else:
            attrs = data.copy()
            limit = int(attrs.pop('limit'))
        discover = Discover()
        discover.api_key = t_tv.api_key
        discover.discover_tv_shows(attrs)
        total_pages = int(os.environ["total_pages"])
        total_results = int(os.environ["total_results"])
        amount = total_results if limit == 0 or total_results < limit else limit
        if method in ["tmdb_company", "tmdb_network"]:
            print("| Processing {}: {} ({} {} shows)".format(
                method, tmdb_id, amount, tmdb_name))
        else:
            print("| Processing {}: {} shows".format(method, amount))
            for attr, value in attrs.items():
                print("|            {}: {}".format(attr, value))
        for x in range(total_pages):
            attrs["page"] = x + 1
            tmdb_shows = discover.discover_tv_shows(attrs)
            for tshow in tmdb_shows:
                count += 1
                t_tvs.append(tshow.id)
                if count == data:
                    break
            if count == data:
                break
    elif method in [
            "tmdb_popular", "tmdb_top_rated", "tmdb_trending_daily",
            "tmdb_trending_weekly"
    ]:
        trending = Trending()
        trending.api_key = t_tv.api_key
        for x in range(int(int(data) / 20) + 1):
            if method == "tmdb_popular":
                tmdb_shows = t_tv.popular(x + 1)
            elif method == "tmdb_top_rated":
                tmdb_shows = t_tv.top_rated(x + 1)
            elif method == "tmdb_trending_daily":
                tmdb_shows = trending.tv_day(x + 1)
            elif method == "tmdb_trending_weekly":
                tmdb_shows = trending.tv_week(x + 1)
            for tshow in tmdb_shows:
                count += 1
                t_tvs.append(tshow.id)
                if count == amount:
                    break
            if count == amount:
                break
        print("| Processing {}: {} Items".format(method, data))
    else:
        tmdb_id = int(data)
        if method == "tmdb_list":
            tmdb = List()
            tmdb.api_key = t_tv.api_key
            try:
                t_col = tmdb.details(tmdb_id)
                tmdb_name = str(t_col)
                for ttv in t_col:
                    if ttv.media_type == "tv":
                        t_tvs.append(ttv.id)
            except:
                raise ValueError(
                    "| Config Error: TMDb List: {} not found".format(tmdb_id))
        else:
            try:
                t_tv.details(tmdb_id).number_of_seasons
                tmdb_name = str(t_tv.details(tmdb_id))
                t_tvs.append(tmdb_id)
            except:
                raise ValueError(
                    "| Config Error: TMDb ID: {} not found".format(tmdb_id))
        print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))

    matched = []
    missing = []
    for mid in t_tvs:
        tvdb_id = tmdb_get_tvdb(config_path, mid)
        if tvdb_id is None:
            print(
                "| TMDb Error: tmdb_id: {} ({}) has no associated tvdb_id. Try just using tvdb_id instead"
                .format(mid,
                        t_tv.details(mid).name))
        elif tvdb_id in plex_map:
            matched.append(plex.Server.fetchItem(plex_map[tvdb_id]))
        else:
            missing.append(tvdb_id)

    return matched, missing
Beispiel #10
0
def tmdb_get_movies(config_path, plex, plex_map, data, method):
    t_movs = []
    t_movie = Movie()
    t_movie.api_key = config_tools.TMDB(
        config_path).apikey  # Set TMDb api key for Movie
    if t_movie.api_key == "None":
        raise KeyError("Invalid TMDb API Key")

    count = 0
    if method == "tmdb_discover":
        attrs = data.copy()
        discover = Discover()
        discover.api_key = t_movie.api_key
        discover.discover_movies(attrs)
        total_pages = int(os.environ["total_pages"])
        total_results = int(os.environ["total_results"])
        limit = int(attrs.pop('limit'))
        amount = total_results if limit == 0 or total_results < limit else limit
        print("| Processing {}: {} movies".format(method, amount))
        for attr, value in attrs.items():
            print("|            {}: {}".format(attr, value))
        for x in range(total_pages):
            attrs["page"] = x + 1
            tmdb_movies = discover.discover_movies(attrs)
            for tmovie in tmdb_movies:
                count += 1
                t_movs.append(tmovie.id)
                if count == amount:
                    break
            if count == amount:
                break
    elif method in [
            "tmdb_popular", "tmdb_top_rated", "tmdb_now_playing",
            "tmdb_trending_daily", "tmdb_trending_weekly"
    ]:
        trending = Trending()
        trending.api_key = t_movie.api_key
        for x in range(int(int(data) / 20) + 1):
            if method == "tmdb_popular":
                tmdb_movies = t_movie.popular(x + 1)
            elif method == "tmdb_top_rated":
                tmdb_movies = t_movie.top_rated(x + 1)
            elif method == "tmdb_now_playing":
                tmdb_movies = t_movie.now_playing(x + 1)
            elif method == "tmdb_trending_daily":
                tmdb_movies = trending.movie_day(x + 1)
            elif method == "tmdb_trending_weekly":
                tmdb_movies = trending.movie_week(x + 1)
            for tmovie in tmdb_movies:
                count += 1
                t_movs.append(tmovie.id)
                if count == data:
                    break
            if count == data:
                break
        print("| Processing {}: {} Items".format(method, data))
    else:
        tmdb_id = int(data)
        if method == "tmdb_list":
            tmdb = List()
            tmdb.api_key = t_movie.api_key
            try:
                t_col = tmdb.details(tmdb_id)
                tmdb_name = str(t_col)
                for tmovie in t_col:
                    if tmovie.media_type == "movie":
                        t_movs.append(tmovie.id)
            except:
                raise ValueError(
                    "| Config Error: TMDb List: {} not found".format(tmdb_id))
        elif method == "tmdb_company":
            tmdb = Company()
            tmdb.api_key = t_movie.api_key
            tmdb_name = str(tmdb.details(tmdb_id))
            company_movies = tmdb.movies(tmdb_id)
            for tmovie in company_movies:
                t_movs.append(tmovie.id)
        else:
            tmdb = Collection()
            tmdb.api_key = t_movie.api_key
            t_col = tmdb.details(tmdb_id)
            tmdb_name = str(t_col)
            try:
                for tmovie in t_col.parts:
                    t_movs.append(tmovie['id'])
            except AttributeError:
                try:
                    t_movie.details(tmdb_id).imdb_id
                    tmdb_name = str(t_movie.details(tmdb_id))
                    t_movs.append(tmdb_id)
                except:
                    raise ValueError(
                        "| Config Error: TMDb ID: {} not found".format(
                            tmdb_id))
        print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))

    matched = []
    missing = []
    for mid in t_movs:
        mid = str(mid)
        if mid in plex_map:
            matched.append(plex.Server.fetchItem(plex_map[mid]))
        else:
            missing.append(mid)

    return matched, missing
Beispiel #11
0
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]]
def tmdb_get_shows(config_path, plex, data, method):
    config_tools.TraktClient(config_path)

    t_tvs = []
    t_tv = TV()
    t_tv.api_key = config_tools.TMDB(config_path).apikey  # Set TMDb api key for Movie
    if t_tv.api_key == "None":
        raise KeyError("Invalid TMDb API Key")
    discover = Discover()
    discover.api_key = t_tv.api_key

    count = 0
    if method == "tmdb_discover":
        discover.discover_tv_shows(data)
        total_pages = int(os.environ["total_pages"])
        total_results = int(os.environ["total_results"])
        limit = int(data.pop('limit'))
        amount = total_results if total_results < limit else limit
        print("| Processing {}: {} items".format(method, amount))
        for attr, value in data.items():
            print("|            {}: {}".format(attr, value))
        for x in range(total_pages):
            data["page"] = x + 1
            tmdb_shows = discover.discover_tv_shows(data)
            for tshow in tmdb_shows:
                count += 1
                t_tvs.append(tshow.id)
                if count == amount:
                    break
            if count == amount:
                break
        run_discover(data)
    elif method in ["tmdb_popular", "tmdb_top_rated", "tmdb_trending_daily", "tmdb_trending_weekly"]:
        #trending = Trending()                  #TURNON:Trending
        #trending.api_key = t_movie.api_key     #TURNON:Trending
        for x in range(int(data / 20) + 1):
            if method == "tmdb_popular":
                tmdb_shows = t_tv.popular(x + 1)
            elif method == "tmdb_top_rated":
                tmdb_shows = t_tv.top_rated(x + 1)
            #elif method == "tmdb_trending_daily":      #TURNON:Trending
            #    tmdb_shows = trending.tv_day(x + 1)    #TURNON:Trending
            #elif method == "tmdb_trending_weekly":     #TURNON:Trending
            #    tmdb_shows = trending.tv_week(x + 1)   #TURNON:Trending
            for tshow in tmdb_shows:
                count += 1
                t_tvs.append(tshow.id)
                if count == amount:
                    break
            if count == amount:
                break
        print("| Processing {}: {} Items".format(method, data))
    else:
        tmdb_id = int(data)
        if method == "tmdb_list":
            tmdb = List()
            tmdb.api_key = t_tv.api_key
            try:
                t_col = tmdb.details(tmdb_id)
                tmdb_name = str(t_col)
                for ttv in t_col:
                    if ttv.media_type == "tv":
                        t_tvs.append(ttv.id)
            except:
                raise ValueError("| Config Error: TMDb List: {} not found".format(tmdb_id))
        elif method in ["tmdb_company", "tmdb_network"]:
            if method == "tmdb_company":
                tmdb = Company()
                tmdb.api_key = t_tv.api_key
                tmdb_name = str(tmdb.details(tmdb_id))
            else:
                #tmdb = Network()                           #TURNON:Trending
                #tmdb.api_key = t_tv.api_key                #TURNON:Trending
                tmdb_name = ""#str(tmdb.details(tmdb_id))   #TURNON:Trending
            discover_method = "with_companies" if method == "tmdb_company" else "with_networks"
            tmdb_shows = discover.discover_tv_shows({discover_method: tmdb_id})
            for tshow in tmdb_shows:
                t_tvs.append(tshow.id)
        else:
            try:
                t_tv.details(tmdb_id).number_of_seasons
                tmdb_name = str(t_tv.details(tmdb_id))
                t_tvs.append(tmdb_id)
            except:
                raise ValueError("| Config Error: TMDb ID: {} not found".format(tmdb_id))
        print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))

    p_tv_map = {}
    for item in plex.Library.all():
        guid = urlparse(item.guid)
        item_type = guid.scheme.split('.')[-1]
        if item_type == 'thetvdb':
            tvdb_id = guid.netloc
        elif item_type == 'themoviedb':
            tvdb_id = get_tvdb_id_from_tmdb_id(guid.netloc)
        else:
            tvdb_id = None
        p_tv_map[item] = tvdb_id

    matched = []
    missing = []
    for mid in t_tvs:
        match = False
        tvdb_id = get_tvdb_id_from_tmdb_id(mid)
        if tvdb_id is None:
            print("| Trakt Error: tmbd_id: {} could not converted to tvdb_id try just using tvdb_id instead".format(mid))
        else:
            for t in p_tv_map:
                if p_tv_map[t] and "tt" not in p_tv_map[t] != "None":
                    if p_tv_map[t] is not None and int(p_tv_map[t]) == int(tvdb_id):
                        match = True
                        break
        if match:
            matched.append(t)
        else:
            missing.append(tvdb_id)

    return matched, missing
def tmdb_get_movies(config_path, plex, data, method):
    t_movs = []
    t_movie = Movie()
    t_movie.api_key = config_tools.TMDB(config_path).apikey  # Set TMDb api key for Movie
    if t_movie.api_key == "None":
        raise KeyError("Invalid TMDb API Key")

    count = 0
    if method == "tmdb_discover":
        discover = Discover()
        discover.api_key = t_movie.api_key
        discover.discover_movies(data)
        total_pages = int(os.environ["total_pages"])
        total_results = int(os.environ["total_results"])
        limit = int(data.pop('limit'))
        amount = total_results if total_results < limit else limit
        print("| Processing {}: {} items".format(method, amount))
        for attr, value in data.items():
            print("|            {}: {}".format(attr, value))
        for x in range(total_pages):
            data["page"] = x + 1
            tmdb_movies = discover.discover_movies(data)
            for tmovie in tmdb_movies:
                count += 1
                t_movs.append(tmovie.id)
                if count == amount:
                    break
            if count == amount:
                break
    elif method in ["tmdb_popular", "tmdb_top_rated", "tmdb_now_playing", "tmdb_trending_daily", "tmdb_trending_weekly"]:
        #trending = Trending()                  #TURNON:Trending
        #trending.api_key = t_movie.api_key     #TURNON:Trending
        for x in range(int(data / 20) + 1):
            if method == "tmdb_popular":
                tmdb_movies = t_movie.popular(x + 1)
            elif method == "tmdb_top_rated":
                tmdb_movies = t_movie.top_rated(x + 1)
            elif method == "tmdb_now_playing":
                tmdb_movies = t_movie.now_playing(x + 1)
            #elif method == "tmdb_trending_daily":          #TURNON:Trending
            #    tmdb_movies = trending.movie_day(x + 1)    #TURNON:Trending
            #elif method == "tmdb_trending_weekly":         #TURNON:Trending
            #    tmdb_movies = trending.movie_week(x + 1)   #TURNON:Trending
            for tmovie in tmdb_movies:
                count += 1
                t_movs.append(tmovie.id)
                if count == data:
                    break
            if count == data:
                break
        print("| Processing {}: {} Items".format(method, data))
    else:
        tmdb_id = int(data)
        if method == "tmdb_list":
            tmdb = List()
            tmdb.api_key = t_movie.api_key
            try:
                t_col = tmdb.details(tmdb_id)
                tmdb_name = str(t_col)
                for tmovie in t_col:
                    if tmovie.media_type == "movie":
                        t_movs.append(tmovie.id)
            except:
                raise ValueError("| Config Error: TMDb List: {} not found".format(tmdb_id))
        elif method == "tmdb_company":
            tmdb = Company()
            tmdb.api_key = t_movie.api_key
            tmdb_name = str(tmdb.details(tmdb_id))
            company_movies = tmdb.movies(tmdb_id)
            for tmovie in company_movies:
                t_movs.append(tmovie.id)
        else:
            tmdb = Collection()
            tmdb.api_key = t_movie.api_key
            t_col = tmdb.details(tmdb_id)
            tmdb_name = str(t_col)
            try:
                for tmovie in t_col.parts:
                    t_movs.append(tmovie['id'])
            except AttributeError:
                try:
                    t_movie.details(tmdb_id).imdb_id
                    tmdb_name = str(t_movie.details(tmdb_id))
                    t_movs.append(tmdb_id)
                except:
                    raise ValueError("| Config Error: TMDb ID: {} not found".format(tmdb_id))
        print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))


    # Create dictionary of movies and their guid
    # GUIDs reference from which source Plex has pulled the metadata
    p_m_map = {}
    p_movies = plex.Library.all()
    for m in p_movies:
        guid = m.guid
        if "themoviedb://" in guid:
            guid = guid.split('themoviedb://')[1].split('?')[0]
        elif "imdb://" in guid:
            guid = guid.split('imdb://')[1].split('?')[0]
        elif "plex://" in guid:
            guid = guid.split('plex://')[1].split('?')[0]
        else:
            guid = "None"
        p_m_map[m] = guid

    matched = []
    missing = []
    plex_tools.create_cache(config_path)
    # We want to search for a match first to limit TMDb API calls
    # Too many rapid calls can cause a momentary block
    # If needed in future maybe add a delay after x calls to let the limit reset
    for mid in t_movs:  # For each TMBd ID in TMBd Collection
        match = False
        for m in p_m_map:  # For each movie in Plex
            item = m
            agent_type = urlparse(m.guid).scheme.split('.')[-1]
            # Plex movie agent
            if agent_type == 'plex':
                # Check cache for tmdb_id
                tmdb_id = plex_tools.query_cache(config_path, item.guid, 'tmdb_id')
                imdb_id = plex_tools.query_cache(config_path, item.guid, 'imdb_id')
                if not tmdb_id:
                    imdb_id, tmdb_id = plex_tools.alt_id_lookup(plex, item)
                    print("| Cache | + | {} | {} | {} | {}".format(item.guid, imdb_id, tmdb_id, item.title))
                    plex_tools.update_cache(config_path, item.guid, imdb_id=imdb_id, tmdb_id=tmdb_id)
                if int(tmdb_id) == int(mid):
                    match = True
                    break
            elif agent_type == 'themoviedb':
                if int(p_m_map[m]) == int(mid):
                    match = True
                    break
            elif agent_type == 'imdb':
                imdb_id = t_movie.details(mid).imdb_id
                for m in p_m_map:
                    if "tt" in p_m_map[m]:
                        if p_m_map[m] == imdb_id:
                            match = True
                            break
        if match:
            matched.append(m)
        else:
            # Duplicate TMDb call?
            missing.append(t_movie.details(mid).imdb_id)

    return matched, missing
Beispiel #14
0
from tmdbv3api import TMDb, Company

tmdb = TMDb()

tmdb.api_key = ""

company = Company()

# Company details

details = company.details(1)
print(details.description)
print(details.headquarters)
print(details.homepage)
print(details.id)
print(details.logo_path)
print(details.name)
print(details.origin_country)
print(details.parent_company)

# Company alternative names

alternative_names = company.alternative_names(1)
for alternative_name in alternative_names:
    print(alternative_name.name)
    print(alternative_name.type)

# Company images

images = company.images(1)
for image in images: