added tmdb_discover

This commit is contained in:
meisnate12 2020-11-06 10:31:58 -05:00
parent 4d177fed8e
commit 8c7e736f45
3 changed files with 90 additions and 58 deletions

View file

@ -8,8 +8,10 @@ from tmdbv3api import TMDb
from tmdbv3api import Movie
from tmdbv3api import List
from tmdbv3api import TV
from tmdbv3api import Discover
from tmdbv3api import Collection
from tmdbv3api import Company
from tmdbv3api import Network
from tmdbv3api import Person
import config_tools
import plex_tools
@ -121,13 +123,20 @@ def imdb_get_movies(config_path, plex, data):
return matched_imdb_movies, missing_imdb_movies
def tmdb_get_movies(config_path, plex, data, method):
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")
if method == "tmdb_discover":
discover = Discover()
discover.api_key = t_tv.api_key
tmdb_shows = discover.discover_movies(data)
for tshow in tmdb_shows:
t_tvs.append(tshow.id)
else:
tmdb_id = int(data)
if method == "tmdb_list":
tmdb = List()
tmdb.api_key = t_movie.api_key
@ -161,7 +170,7 @@ def tmdb_get_movies(config_path, plex, data, method):
t_movs.append(tmdb_id)
except:
raise ValueError("| Config Error: TMDb ID: {} not found".format(tmdb_id))
print("| Processing {}: {} ID: {}".format(method, tmdb_name, tmdb_id))
print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))
# Create dictionary of movies and their guid
@ -266,14 +275,23 @@ def get_tvdb_id_from_tmdb_id(id):
def tmdb_get_shows(config_path, plex, data, method):
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")
def run_discover(dict):
discover = Discover()
discover.api_key = t_tv.api_key
tmdb_shows = discover.discover_tv_shows(dict)
for tshow in tmdb_shows:
t_tvs.append(tshow.id)
if method == "tmdb_discover":
run_discover(data)
else:
tmdb_id = int(data)
if method == "tmdb_list":
tmdb = List()
tmdb.api_key = t_tv.api_key
@ -285,6 +303,12 @@ def tmdb_get_shows(config_path, plex, data, method):
t_tvs.append(ttv.id)
except:
raise ValueError("| Config Error: TMDb List: {} not found".format(tmdb_id))
elif method in ["tmdb_company", "tmdb_network"]:
tmdb = Company() if method == "tmdb_company" else Network()
discover_method = "with_companies" if method == "tmdb_company" else "with_networks"
tmdb.api_key = t_tv.api_key
tmdb_name = str(tmdb.details(tmdb_id))
run_discover({discover_method: tmdb_id})
else:
try:
t_tv.details(tmdb_id).number_of_seasons
@ -292,7 +316,7 @@ def tmdb_get_shows(config_path, plex, data, method):
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))
print("| Processing {}: ({}) {}".format(method, tmdb_id, tmdb_name))
p_tv_map = {}
for item in plex.Library.all():

View file

@ -135,9 +135,11 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
"tmdb_collection",
"tmdb_id",
"tmdb_actor",
"tmdb_company",
"tmdb_director"
"tmdb_writer"
"tmdb_company",
"tmdb_network",
"tmdb_discover",
"tmdb_list",
"tmdb_movie",
"tmdb_show",
@ -162,6 +164,7 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
show_only_lists = [
"tmdb_show",
"tvdb_show"
"tmdb_network",
]
movie_only_lists = [
"tmdb_collection",
@ -402,6 +405,9 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
methods.append(get_method_pair_tmdb(method_name, collections[c][m], "TMDb Collection ID"))
elif method_name == "tmdb_company":
methods.append(get_method_pair_int(method_name, collections[c][m], "TMDb Company ID"))
elif method_name == "tmdb_discover":
#FIGURE THIS OUT LOL
methods.append(get_method_pair_int(method_name, collections[c][m], "TMDb Network ID"))
elif method_name == "tmdb_id":
id = get_method_pair_tmdb(method_name, collections[c][m], "TMDb ID")
if tmdb_id is None:
@ -411,10 +417,12 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
details["poster"] = ["url", tmdb_get_metadata(config_path, id[1][0], "backdrop_path"), method_name]
tmdb_id = id[1][0]
methods.append(id)
elif method_name == "tmdb_list": #TODO: validate
elif method_name == "tmdb_list":
methods.append(get_method_pair_int(method_name, collections[c][m], "TMDb List ID"))
elif method_name == "tmdb_movie":
methods.append(get_method_pair_tmdb(method_name, collections[c][m], "TMDb Movie ID"))
elif method_name == "tmdb_network":
methods.append(get_method_pair_int(method_name, collections[c][m], "TMDb Network ID"))
elif method_name == "tmdb_show":
methods.append(get_method_pair_tmdb(method_name, collections[c][m], "TMDb Show ID"))
elif method_name == "tvdb_show":
@ -433,7 +441,7 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
methods.append((method_name, [regex_first_int(collections[c][m], method_name, default=30)]))
elif method_name == "trakt_watchlist":
methods.append((method_name, get_attribute_list(collections[c][m])))
elif method_name == "tautulli": #TODO:test
elif method_name == "tautulli":
try:
new_dictionary = {}
new_dictionary["list_type"] = check_for_attribute(collections[c][m], "list_type", parent="tautulli", test_list=["popular", "watched"], options="| \tpopular (Most Popular List)\n| \twatched (Most Watched List)", throw=True, save=False)
@ -462,7 +470,7 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
for v in values:
if m == "imdb_list":
print("| \n| Processing {}: {}".format(m, v[0]))
if m not in ["plex_search", "tmdb_list", "tmdb_id", "tmdb_movie", "tmdb_collection", "tmdb_company", "tmdb_show"]:
elif m not in ["plex_search", "tmdb_list", "tmdb_id", "tmdb_movie", "tmdb_collection", "tmdb_company", "tmdb_network", "tmdb_discover", "tmdb_show"]:
print("| \n| Processing {}: {}".format(m, v))
try:
missing, map = add_to_collection(config_path, plex, m, v, c, map, filters)

View file

@ -152,7 +152,7 @@ def add_to_collection(config_path, plex, method, value, c, map, filters=None):
elif plex.library_type == "movie":
if method == "imdb_list":
movies, missing = imdb_tools.imdb_get_movies(config_path, plex, value)
elif method in ["tmdb_list", "tmdb_id", "tmdb_movie", "tmdb_collection", "tmdb_company"]:
elif "tmdb" in method:
movies, missing = imdb_tools.tmdb_get_movies(config_path, plex, value, method)
elif method == "trakt_list":
movies, missing = trakt_tools.trakt_get_movies(config_path, plex, value)
@ -169,7 +169,7 @@ def add_to_collection(config_path, plex, method, value, c, map, filters=None):
else:
print("| Config Error: {} method not supported".format(method))
elif plex.library_type == "show":
if method in ["tmdb_list", "tmdb_id", "tmdb_show"]:
if "tmdb" in method:
shows, missing = imdb_tools.tmdb_get_shows(config_path, plex, value, method)
elif method == "tvdb_show":
shows, missing = imdb_tools.tvdb_get_shows(config_path, plex, value)