def tmdb_get_shows(config_path, plex, data, is_list=False): config_tools.TraktClient(config_path) tmdb_id = int(data) 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") if is_list: tmdb = List() tmdb.api_key = t_tv.api_key try: t_col = tmdb.details(tmdb_id) 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 t_tvs.append(tmdb_id) except: raise ValueError( "| Config Error: TMDb ID: {} not found".format(tmdb_id)) 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_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
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_tvdb(config_path, tmdb_id): show = TV() show.api_key = config_tools.TMDB(config_path).apikey search = show.external_ids(tmdb_id)['tvdb_id'] if search: return str(search)
def tmdb_get_tvdb(config_path, tmdb_id): show = TV() show.api_key = config_tools.TMDB(config_path).apikey return show.external_ids(tmdb_id)['tvdb_id']