Skip to content

Commit

Permalink
updated outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Mar 27, 2021
1 parent 778d483 commit 39f2b52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
10 changes: 5 additions & 5 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
elif attribute not in loaded_config[parent]: loaded_config[parent][attribute] = default
else: endline = ""
yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), indent=ind_in, block_seq_indent=bsi_in)
elif not data[attribute] and data[attribute] is not False:
elif data[attribute] is None:
if default_is_none is True: return None
else: message = f"{text} is blank"
elif var_type == "bool":
Expand Down Expand Up @@ -325,7 +325,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
library = PlexAPI(params, self.TMDb, self.TVDb)
logger.info(f"{params['name']} Library Connection Successful")
except Failed as e:
logger.error(e)
util.print_multiline(e, error=True)
logger.info(f"{params['name']} Library Connection Failed")
continue

Expand All @@ -343,7 +343,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
radarr_params["tag"] = check_for_attribute(lib, "search", parent="radarr", var_type="lower_list", default=self.general["radarr"]["tag"], default_is_none=True, save=False)
library.Radarr = RadarrAPI(self.TMDb, radarr_params)
except Failed as e:
util.print_multiline(e)
util.print_multiline(e, error=True)
logger.info(f"{params['name']} library's Radarr Connection {'Failed' if library.Radarr is None else 'Successful'}")

if self.general["sonarr"]["url"] or "sonarr" in lib:
Expand All @@ -361,7 +361,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
sonarr_params["tag"] = check_for_attribute(lib, "search", parent="sonarr", var_type="lower_list", default=self.general["sonarr"]["tag"], default_is_none=True, save=False)
library.Sonarr = SonarrAPI(self.TVDb, sonarr_params, library.Plex.language)
except Failed as e:
util.print_multiline(e)
util.print_multiline(e, error=True)
logger.info(f"{params['name']} library's Sonarr Connection {'Failed' if library.Sonarr is None else 'Successful'}")

if self.general["tautulli"]["url"] or "tautulli" in lib:
Expand All @@ -372,7 +372,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
tautulli_params["apikey"] = check_for_attribute(lib, "apikey", parent="tautulli", default=self.general["tautulli"]["apikey"], req_default=True, save=False)
library.Tautulli = TautulliAPI(tautulli_params)
except Failed as e:
util.print_multiline(e)
util.print_multiline(e, error=True)
logger.info(f"{params['name']} library's Tautulli Connection {'Failed' if library.Tautulli is None else 'Successful'}")

self.libraries.append(library)
Expand Down
28 changes: 19 additions & 9 deletions modules/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ def update_metadata(self, TMDb, test):
tagline = tmdb_item.tagline if tmdb_item and len(tmdb_item.tagline) > 0 else None
summary = tmdb_item.overview if tmdb_item else None

details_updated = False
advance_details_updated = False
genre_updated = False
label_updated = False
season_updated = False
episode_updated = False

edits = {}
def add_edit(name, current, group, alias, key=None, value=None):
if value or name in alias:
Expand All @@ -329,15 +336,14 @@ def add_edit(name, current, group, alias, key=None, value=None):
add_edit("summary", item.summary, meta, methods, value=summary)
if len(edits) > 0:
logger.debug(f"Details Update: {edits}")
details_updated = True
try:
item.edit(**edits)
item.reload()
logger.info(f"{item_type}: {mapping_name} Details Update Successful")
except BadRequest:
util.print_stacktrace()
logger.error(f"{item_type}: {mapping_name} Details Update Failed")
else:
logger.info(f"{item_type}: {mapping_name} Details Update Not Needed")

advance_edits = {}
if self.is_show:
Expand Down Expand Up @@ -476,6 +482,7 @@ def add_edit(name, current, group, alias, key=None, value=None):

if len(advance_edits) > 0:
logger.debug(f"Details Update: {advance_edits}")
advance_details_updated = True
try:
check_dict = {pref.id: list(pref.enumValues.keys()) for pref in item.preferences()}
logger.info(check_dict)
Expand All @@ -484,9 +491,7 @@ def add_edit(name, current, group, alias, key=None, value=None):
logger.info(f"{item_type}: {mapping_name} Advanced Details Update Successful")
except BadRequest:
util.print_stacktrace()
logger.error(f"{item_type}: {mapping_name} Details Update Failed")
else:
logger.info(f"{item_type}: {mapping_name} Details Update Not Needed")
logger.error(f"{item_type}: {mapping_name} Advanced Details Update Failed")

genres = []
if tmdb_item:
Expand All @@ -505,9 +510,11 @@ def add_edit(name, current, group, alias, key=None, value=None):
logger.error("Metadata Error: genre_sync_mode attribute must be either 'append' or 'sync' defaulting to append")
elif str(meta["genre_sync_mode"]).lower() == "sync":
for genre in (g for g in item_genres if g not in genres):
genre_updated = True
item.removeGenre(genre)
logger.info(f"Detail: Genre {genre} removed")
for genre in (g for g in genres if g not in item_genres):
genre_updated = True
item.addGenre(genre)
logger.info(f"Detail: Genre {genre} added")

Expand All @@ -522,9 +529,11 @@ def add_edit(name, current, group, alias, key=None, value=None):
logger.error("Metadata Error: label_sync_mode attribute must be either 'append' or 'sync' defaulting to append")
elif str(meta[methods["label_sync_mode"]]).lower() == "sync":
for label in (la for la in item_labels if la not in labels):
label_updated = True
item.removeLabel(label)
logger.info(f"Detail: Label {label} removed")
for label in (la for la in labels if la not in item_labels):
label_updated = True
item.addLabel(label)
logger.info(f"Detail: Label {label} added")
else:
Expand Down Expand Up @@ -561,15 +570,14 @@ def add_edit(name, current, group, alias, key=None, value=None):
add_edit("summary", season.summary, season_methods, season_dict)
if len(edits) > 0:
logger.debug(f"Season: {season_id} Details Update: {edits}")
season_updated = True
try:
season.edit(**edits)
season.reload()
logger.info(f"Season: {season_id} Details Update Successful")
except BadRequest:
util.print_stacktrace()
logger.error(f"Season: {season_id} Details Update Failed")
else:
logger.info(f"Season: {season_id} Details Update Not Needed")
else:
logger.error(f"Metadata Error: Season: {season_id} invalid, it must be an integer")
else:
Expand Down Expand Up @@ -612,6 +620,7 @@ def add_edit(name, current, group, alias, key=None, value=None):
add_edit("summary", episode.summary, episode_dict, episode_methods)
if len(edits) > 0:
logger.debug(f"Season: {season_id} Episode: {episode_id} Details Update: {edits}")
episode_updated = True
try:
episode.edit(**edits)
episode.reload()
Expand All @@ -620,9 +629,10 @@ def add_edit(name, current, group, alias, key=None, value=None):
except BadRequest:
util.print_stacktrace()
logger.error(f"Season: {season_id} Episode: {episode_id} Details Update Failed")
else:
logger.info(f"Season: {season_id} Episode: {episode_id} Details Update Not Needed")
else:
logger.error(f"Metadata Error: episode {episode_str} invalid must have S##E## format")
else:
logger.error("Metadata Error: episodes attribute is blank")

if not details_updated and not advance_details_updated and not genre_updated and not label_updated and not season_updated and not episode_updated:
logger.info(f"{item_type}: {mapping_name} Details Update Not Needed")

0 comments on commit 39f2b52

Please sign in to comment.