Misc: Use common variables to pass into functions.

pull/105/head
desimaniac 5 years ago
parent 27ff7ad036
commit 129e9bb803

@ -31,13 +31,7 @@ def verify_movie_exists_on_tmdb(movie_title, movie_year, movie_tmdb_id):
return False return False
def check_movie_tmdb_id(sorted_movie): def check_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id):
movie_title = sorted_movie['movie']['title']
movie_year = str(sorted_movie['movie']['year']) \
if sorted_movie['movie']['year'] else '????'
movie_tmdb_id = sorted_movie['movie']['ids']['tmdb']
try: try:
if validate_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id) and \ if validate_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id) and \
verify_movie_exists_on_tmdb(movie_title, movie_year, movie_tmdb_id): verify_movie_exists_on_tmdb(movie_title, movie_year, movie_tmdb_id):

@ -31,13 +31,7 @@ def verify_series_exists_on_tvdb(series_title, series_year, series_tvdb_id):
return False return False
def check_series_tvdb_id(series): def check_series_tvdb_id(series_title, series_year, series_tvdb_id):
series_title = series['show']['title']
series_year = str(series['show']['year']) \
if series['show']['year'] else '????'
series_tvdb_id = series['show']['ids']['tvdb']
try: try:
if validate_series_tvdb_id(series_title, series_year, series_tvdb_id) and \ if validate_series_tvdb_id(series_title, series_year, series_tvdb_id) and \
verify_series_exists_on_tvdb(series_title, series_year, series_tvdb_id): verify_series_exists_on_tvdb(series_title, series_year, series_tvdb_id):

@ -169,6 +169,9 @@ def show(show_id, folder=None, no_search=False):
log.error("Aborting due to failure to retrieve Trakt show") log.error("Aborting due to failure to retrieve Trakt show")
return None return None
# set common series variables
series_title = trakt_show['title']
# convert series year to string # convert series year to string
if trakt_show['year']: if trakt_show['year']:
series_year = str(trakt_show['year']) series_year = str(trakt_show['year'])
@ -177,8 +180,7 @@ def show(show_id, folder=None, no_search=False):
else: else:
series_year = '????' series_year = '????'
log.info("Retrieved Trakt show information for \'%s\': \'%s (%s)\'", show_id, trakt_show['title'], log.info("Retrieved Trakt show information for \'%s\': \'%s (%s)\'", show_id, series_title, series_year)
series_year)
# profile id # profile id
profile_id = get_profile_id(sonarr, cfg.sonarr.profile) profile_id = get_profile_id(sonarr, cfg.sonarr.profile)
@ -195,19 +197,25 @@ def show(show_id, folder=None, no_search=False):
readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags) readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags)
# add show to sonarr # add show to sonarr
if sonarr.add_series(trakt_show['ids']['tvdb'], trakt_show['title'], trakt_show['ids']['slug'], profile_id, if sonarr.add_series(trakt_show['ids']['tvdb'],
cfg.sonarr.root_folder, use_tags, not no_search): series_title,
trakt_show['ids']['slug'],
profile_id,
cfg.sonarr.root_folder,
use_tags,
not no_search,
):
if profile_tags is not None: if profile_tags is not None:
log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", trakt_show['title'], series_year, log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) readable_tags)
else: else:
log.info("ADDED: \'%s (%s)\'", trakt_show['title'], series_year) log.info("ADDED: \'%s (%s)\'", series_title, series_year)
else: else:
if profile_tags is not None: if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", trakt_show['title'], series_year, log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) readable_tags)
else: else:
log.info("FAILED ADDING: \'%s (%s)\'", trakt_show['title'], series_year) log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
return return
@ -397,6 +405,10 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde
for series in sorted_series_list: for series in sorted_series_list:
# noinspection PyBroadException # noinspection PyBroadException
# set common series variables
series_tvdb_id = series['show']['ids']['tvdb']
series_title = series['show']['title']
# convert series year to string # convert series year to string
if series['show']['year']: if series['show']['year']:
series_year = str(series['show']['year']) series_year = str(series['show']['year'])
@ -410,12 +422,12 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde
try: try:
# check if movie has a valid TVDB ID and that it exists on TVDB # check if movie has a valid TVDB ID and that it exists on TVDB
if not tvdb_helper.check_series_tvdb_id(series): if not tvdb_helper.check_series_tvdb_id(series_title, series_year, series_tvdb_id):
continue continue
# check if genre matches genre supplied via argument # check if genre matches genre supplied via argument
if genre and not misc_helper.allowed_genres(genre, 'show', series): if genre and not misc_helper.allowed_genres(genre, 'show', series):
log.debug("SKIPPING: \'%s\' because it was not from genre: %s", series['show']['title'], log.debug("SKIPPING: \'%s\' because it was not from genre: %s", series_title,
genre.title()) genre.title())
continue continue
@ -424,12 +436,13 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde
callback_remove_recommended callback_remove_recommended
if remove_rejected_from_recommended else None): if remove_rejected_from_recommended else None):
log.info("ADDING: %s (%s) | Country: %s | Language: %s | Genre: %s | Network: %s", log.info("ADDING: %s (%s) | Country: %s | Language: %s | Genre: %s | Network: %s",
series['show']['title'], series_title,
series_year, series_year,
(series['show']['country'] or 'N/A').upper(), (series['show']['country'] or 'N/A').upper(),
(series['show']['language'] or 'N/A').upper(), (series['show']['language'] or 'N/A').upper(),
series_genres, series_genres,
series['show']['network']) (series['show']['network'] or 'N/A').upper(),
)
# profile tags # profile tags
use_tags = None use_tags = None
@ -442,27 +455,32 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde
readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags) readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags)
# add show to sonarr # add show to sonarr
if sonarr.add_series(series['show']['ids']['tvdb'], series['show']['title'], if sonarr.add_series(series['show']['ids']['tvdb'],
series['show']['ids']['slug'], profile_id, cfg.sonarr.root_folder, use_tags, series_title,
not no_search): series['show']['ids']['slug'],
profile_id,
cfg.sonarr.root_folder,
use_tags,
not no_search,
):
if profile_tags is not None: if profile_tags is not None:
log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series['show']['title'], series_year, log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) readable_tags)
else: else:
log.info("ADDED: \'%s (%s)\'", series['show']['title'], series_year) log.info("ADDED: \'%s (%s)\'", series_title, series_year)
if notifications: if notifications:
callback_notify({'event': 'add_show', 'list_type': list_type, 'show': series['show']}) callback_notify({'event': 'add_show', 'list_type': list_type, 'show': series['show']})
added_shows += 1 added_shows += 1
else: else:
if profile_tags is not None: if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series['show']['title'], series_year, log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) readable_tags)
else: else:
log.info("FAILED ADDING: \'%s (%s)\'", series['show']['title'], series_year) log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
continue continue
else: else:
log.info("SKIPPED: \'%s (%s)\'", series['show']['title'], series_year) log.info("SKIPPED: \'%s (%s)\'", series_title, series_year)
continue continue
# stop adding shows, if added_shows >= add_limit # stop adding shows, if added_shows >= add_limit
@ -473,7 +491,7 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde
time.sleep(add_delay) time.sleep(add_delay)
except Exception: except Exception:
log.exception("Exception while processing show \'%s\': ", series['show']['title']) log.exception("Exception while processing show \'%s\': ", series_title)
log.info("Added %d new show(s) to Sonarr", added_shows) log.info("Added %d new show(s) to Sonarr", added_shows)
@ -546,9 +564,15 @@ def movie(movie_id, folder=None, minimum_availability=None, no_search=False):
log.info("Retrieved Trakt movie information for \'%s\': \'%s (%s)\'", movie_id, trakt_movie['title'], movie_year) log.info("Retrieved Trakt movie information for \'%s\': \'%s (%s)\'", movie_id, trakt_movie['title'], movie_year)
# add movie to radarr # add movie to radarr
if radarr.add_movie(trakt_movie['ids']['tmdb'], trakt_movie['title'], trakt_movie['year'], if radarr.add_movie(trakt_movie['ids']['tmdb'],
trakt_movie['ids']['slug'], profile_id, cfg.radarr.root_folder, trakt_movie['title'],
cfg.radarr.minimum_availability, not no_search): trakt_movie['year'],
trakt_movie['ids']['slug'],
profile_id,
cfg.radarr.root_folder,
cfg.radarr.minimum_availability,
not no_search,
):
log.info("ADDED \'%s (%s)\'", trakt_movie['title'], movie_year) log.info("ADDED \'%s (%s)\'", trakt_movie['title'], movie_year)
else: else:
log.error("FAILED ADDING \'%s (%s)\'", trakt_movie['title'], movie_year) log.error("FAILED ADDING \'%s (%s)\'", trakt_movie['title'], movie_year)
@ -771,6 +795,10 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen
for sorted_movie in sorted_movies_list: for sorted_movie in sorted_movies_list:
# noinspection PyBroadException # noinspection PyBroadException
# set common series variables
movie_title = sorted_movie['movie']['title']
movie_tmdb_id = sorted_movie['movie']['ids']['tmdb']
# convert movie year to string # convert movie year to string
movie_year = str(sorted_movie['movie']['year']) \ movie_year = str(sorted_movie['movie']['year']) \
if sorted_movie['movie']['year'] else '????' if sorted_movie['movie']['year'] else '????'
@ -781,12 +809,12 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen
try: try:
# check if movie has a valid TMDb ID and that it exists on TMDb # check if movie has a valid TMDb ID and that it exists on TMDb
if not tmdb_helper.check_movie_tmdb_id(sorted_movie): if not tmdb_helper.check_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id):
continue continue
# check if genre matches genre supplied via argument # check if genre matches genre supplied via argument
if genre and not misc_helper.allowed_genres(genre, 'movie', sorted_movie): if genre and not misc_helper.allowed_genres(genre, 'movie', sorted_movie):
log.debug("SKIPPING: \'%s (%s)\' because it was not from genre: %s", sorted_movie['movie']['title'], log.debug("SKIPPING: \'%s (%s)\' because it was not from genre: %s", movie_title,
movie_year, genre.title()) movie_year, genre.title())
continue continue
@ -801,24 +829,33 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen
continue continue
log.info("ADDING: \'%s (%s)\' | Country: %s | Language: %s | Genre: %s ", log.info("ADDING: \'%s (%s)\' | Country: %s | Language: %s | Genre: %s ",
sorted_movie['movie']['title'], movie_year, movie_title,
movie_year,
(sorted_movie['movie']['country'] or 'N/A').upper(), (sorted_movie['movie']['country'] or 'N/A').upper(),
(sorted_movie['movie']['language'] or 'N/A').upper(), movie_genres) (sorted_movie['movie']['language'] or 'N/A').upper(),
movie_genres,
)
# add movie to radarr # add movie to radarr
if radarr.add_movie(sorted_movie['movie']['ids']['tmdb'], sorted_movie['movie']['title'], if radarr.add_movie(sorted_movie['movie']['ids']['tmdb'],
movie_year, sorted_movie['movie']['ids']['slug'], profile_id, movie_title,
cfg.radarr.root_folder, cfg.radarr.minimum_availability, not no_search): movie_year,
sorted_movie['movie']['ids']['slug'],
log.info("ADDED: \'%s (%s)\'", sorted_movie['movie']['title'], movie_year) profile_id,
cfg.radarr.root_folder,
cfg.radarr.minimum_availability,
not no_search,
):
log.info("ADDED: \'%s (%s)\'", movie_title, movie_year)
if notifications: if notifications:
callback_notify({'event': 'add_movie', 'list_type': list_type, 'movie': sorted_movie['movie']}) callback_notify({'event': 'add_movie', 'list_type': list_type, 'movie': sorted_movie['movie']})
added_movies += 1 added_movies += 1
else: else:
log.error("FAILED ADDING: \'%s (%s)\'", sorted_movie['movie']['title'], movie_year) log.error("FAILED ADDING: \'%s (%s)\'", movie_title, movie_year)
continue continue
else: else:
log.info("SKIPPED: \'%s (%s)\'", sorted_movie['movie']['title'], movie_year) log.info("SKIPPED: \'%s (%s)\'", movie_title, movie_year)
continue continue
# stop adding movies, if added_movies >= add_limit # stop adding movies, if added_movies >= add_limit
@ -829,7 +866,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen
time.sleep(add_delay) time.sleep(add_delay)
except Exception: except Exception:
log.exception("Exception while processing movie \'%s\': ", sorted_movie['movie']['title']) log.exception("Exception while processing movie \'%s\': ", movie_title)
log.info("Added %d new movie(s) to Radarr", added_movies) log.info("Added %d new movie(s) to Radarr", added_movies)

Loading…
Cancel
Save