Skip to content

Commit

Permalink
fix for mza921#118
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Nov 20, 2020
1 parent 4780ac3 commit 74c447d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
46 changes: 26 additions & 20 deletions app/imdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,49 +332,55 @@ def tvdb_get_shows(config_path, plex, data):

def tmdb_get_metadata(config_path, data, type):
# Instantiate TMDB objects
id = int(data)
tmdb_id = int(data)

tmdb_url_prefix = "https://image.tmdb.org/t/p/original"
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_path", "backdrop_path"]:
if type in ["overview", "poster", "backdrop"]:
collection = Collection()
collection.api_key = api_key
collection.language = language
try:
if type == "overview":
return collection.details(id).overview
elif type == "poster_path":
return tmdb_url_prefix + collection.details(id).poster_path
elif type == "backdrop_path":
return tmdb_url_prefix + collection.details(id).backdrop_path
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":
return media.details(id).overview
elif type == "poster_path":
return tmdb_url_prefix + media.details(id).poster_path
elif type == "backdrop_path":
return tmdb_url_prefix + media.details(id).backdrop_path
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("| Config Error: TMBd {} ID: {} not found".format("Movie/Collection" if is_movie else "Show", id))
elif type in ["biography", "profile_path", "name"]:
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":
return person.details(id).biography
elif type == "profile_path":
return tmdb_url_prefix + person.details(id).profile_path
meta = person.details(tmdb_id).biography
elif type == "profile":
meta = person.details(tmdb_id).profile_path
elif type == "name":
return person.details(id).name
meta = person.details(tmdb_id).name
except AttributeError:
raise ValueError("| Config Error: TMBd Actor ID: {} not found".format(id))
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
23 changes: 16 additions & 7 deletions app/plex_auto_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ def check_details(check_name, check_value):
posters_found.append(["url", check_value, check_name])
elif check_name == "tmdb_poster":
try:
posters_found.append(["url", tmdb_get_metadata(config_path, check_value, "poster_path"), check_name])
posters_found.append(["url", tmdb_get_metadata(config_path, check_value, "poster"), check_name])
except ValueError as e:
print(e)
elif check_name == "tmdb_profile":
try:
posters_found.append(["url", tmdb_get_metadata(config_path, check_value, "profile_path"), check_name])
posters_found.append(["url", tmdb_get_metadata(config_path, check_value, "profile"), check_name])
except ValueError as e:
print(e)
elif check_name == "file_poster":
Expand All @@ -373,7 +373,7 @@ def check_details(check_name, check_value):
backgrounds_found.append(["url", check_value, check_name])
elif check_name == "tmdb_background":
try:
backgrounds_found.append(["url", tmdb_get_metadata(config_path, check_value, "backdrop_path"), check_name])
backgrounds_found.append(["url", tmdb_get_metadata(config_path, check_value, "backdrop"), check_name])
except ValueError as e:
print(e)
elif check_name == "file_background":
Expand Down Expand Up @@ -412,7 +412,7 @@ def check_details(check_name, check_value):
if person_id is None:
if "summary" not in details:
details["summary"] = tmdb_get_metadata(config_path, id, "biography")
details["poster"] = ["url", tmdb_get_metadata(config_path, id, "profile_path"), method_name]
details["poster"] = ["url", tmdb_get_metadata(config_path, id, "profile"), method_name]
person_id = id
person_method = method_name
if method_name == "tmdb_actor":
Expand Down Expand Up @@ -441,9 +441,18 @@ def check_details(check_name, check_value):
id = get_method_pair_tmdb(method_name, collections[c][m], "TMDb ID")
if tmdb_id is None:
if "summary" not in details:
details["summary"] = tmdb_get_metadata(config_path, id[1][0], "overview")
details["poster"] = ["url", tmdb_get_metadata(config_path, id[1][0], "poster_path"), method_name]
details["poster"] = ["url", tmdb_get_metadata(config_path, id[1][0], "backdrop_path"), method_name]
try:
details["summary"] = tmdb_get_metadata(config_path, id[1][0], "overview")
except ValueError as e:
print(e)
try:
details["poster"] = ["url", tmdb_get_metadata(config_path, id[1][0], "poster"), method_name]
except ValueError as e:
print(e)
try:
details["background"] = ["url", tmdb_get_metadata(config_path, id[1][0], "backdrop"), method_name]
except ValueError as e:
print(e)
tmdb_id = id[1][0]
methods.append(id)
elif method_name in ["tmdb_popular", "tmdb_top_rated", "tmdb_now_playing", "tmdb_trending_daily", "tmdb_trending_weekly"]:
Expand Down

0 comments on commit 74c447d

Please sign in to comment.