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_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 tmdb_get_movies(config_path, plex, data): try: tmdb_id = re.search('.*?(\\d+)', data) tmdb_id = tmdb_id.group(1) except AttributeError: # Bad URL Provided return t_movie = Movie() tmdb = Collection() tmdb.api_key = config_tools.TMDB( config_path).apikey # Set TMDb api key for Collection if tmdb.api_key == "None": raise KeyError("Invalid TMDb API Key") t_movie.api_key = tmdb.api_key # Copy same api key to Movie t_col = tmdb.details(tmdb_id) t_movs = [] for tmovie in t_col.parts: t_movs.append(tmovie['id']) # 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] else: guid = "None" p_m_map[m] = guid matched = [] missing = [] # 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 if "tt" not in p_m_map[ m] != "None": # If the Plex movie's guid does not start with tt if int(p_m_map[m]) == int(mid): match = True break if not match: imdb_id = t_movie.details(mid).entries['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: missing.append(t_movie.details(mid).entries['imdb_id']) return matched, missing
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
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.collection = Collection()
def download_image(plex_collection, metadata_type): plex_collection_id = plex_collection.ratingKey tmdb_collection_id = get_tmdb_collection_id(plex_collection) tmdb_metadata_type = convert_to_tmdb(metadata_type) tmdb_collection_images = Collection().images(tmdb_collection_id) image_urls = get_image_urls(tmdb_collection_images, tmdb_metadata_type, IMAGE_ITEM_LIMIT) upload_images_to_plex(image_urls, plex_collection_id, metadata_type)
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 check_collection(plex_collection, section_title, count, total): tmdb_collection_id = get_tmdb_collection_id(plex_collection) collection = Collection().details(collection_id=tmdb_collection_id) tmdb_ids = get_tmdb_ids(plex_collection) curent_year = datetime.now().year missing = [] if not hasattr(collection, 'parts'): click.secho('%s %s [%s/%s] - No TMDB Collection Data' % (u'\uFFFD', plex_collection.title, count, total), fg='yellow') if not DRY_RUN: append_file( section_title, '%s %s [%s/%s] - No TMDB Collection Data\n' % ('\uFFFD', plex_collection.title, count, total)) return for part in collection.parts: if not part.get('release_date'): continue if part.get('id') not in tmdb_ids and int( part.get('release_date')[:4]) <= curent_year: missing.append(part) if not missing: click.secho('%s %s [%s/%s]' % (u'\u2713', plex_collection.title, count, total), fg='green') if not DRY_RUN: append_file( section_title, '%s %s [%s/%s]\n' % ('\u2713', plex_collection.title, count, total)) return click.secho('%s %s [%s/%s]' % (u'\u2717', plex_collection.title, count, total), fg='red') if not DRY_RUN: append_file( section_title, '%s %s [%s/%s]\n' % ('\u2717', plex_collection.title, count, total)) for x in missing: click.secho(' - %s (%s)' % (x.get('title'), x.get('release_date')[:4]), fg='red') if not DRY_RUN: append_file( section_title, ' - %s (%s)\n' % (x.get('title'), x.get('release_date')[:4]))
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")
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 __init__(self, config_path): config = Config(config_path).tmdb if TMDB.valid: self.apikey = check_for_attribute(config, "apikey", parent="tmdb") self.language = check_for_attribute(config, "language", parent="tmdb", default="en", do_print=False) elif TMDB.valid is None: print("| Connecting to TMDb...") fatal_message = "" message = "" tmdb = Collection() try: self.apikey = check_for_attribute(config, "apikey", parent="tmdb", throw=True) except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len( fatal_message) > 0 else str(e) try: self.language = check_for_attribute(config, "language", parent="tmdb", default="en", throw=True) except SystemExit as e: message = message + "\n" + str(e) if len(message) > 0 else str( e) if len(fatal_message) > 0: print(fatal_message + "\n" + message) TMDB.valid = False else: if len(message) > 0: print(message) try: tmdb.api_key = self.apikey tmdb.details("100693").parts TMDB.valid = True except AttributeError: print("| Config Error: Invalid apikey") TMDB.valid = False print("| TMDb Connection {}".format( "Successful" if TMDB.valid else "Failed"))
def test_collection_images(self): c = Collection() images = c.images(10) self.assertTrue(hasattr(images, 'backdrops')) self.assertTrue(hasattr(images, 'posters'))
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
from tmdbv3api import TMDb, Collection tmdb = TMDb() tmdb.api_key = "" tmdb.language = "en" collection = Collection() # Get collection details details = collection.details(10) print(details.id) print(details.name) print(details.overview) print(details.poster_path) for part in details.parts: print(part["id"]) print(part["title"]) # Get collection images # If tmdb.language is 'en-US' will not work. Set tmdb.language to 'en' images = collection.images(10) print(images.id) for image in images.backdrops: print(image["file_path"]) print(image["height"]) print(image["width"]) for image in images.posters: print(image["file_path"])
def tmdb_get_movies(config_path, plex, data, is_list=False): tmdb_id = int(data) 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") tmdb = List() if is_list else Collection() tmdb.api_key = t_movie.api_key t_col = tmdb.details(tmdb_id) if is_list: try: 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)) else: try: for tmovie in t_col.parts: t_movs.append(tmovie['id']) except AttributeError: try: t_movie.details(tmdb_id).imdb_id t_movs.append(tmdb_id) except: raise ValueError( "| Config Error: TMDb ID: {} not found".format(tmdb_id)) # 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
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
def get_tmdb_summary(plex_collection_movies): tmdb_collection_id = get_tmdb_collection_id(plex_collection_movies) collection = Collection().details(collection_id=tmdb_collection_id) return collection.entries.get('overview')