From b46e8c7cb8dc18bde8f258963c375b320c90989d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 20 Apr 2019 13:38:26 -0400 Subject: [PATCH] Fix for subtitles upgrading not taking use_sonarr/use_radarr into account. --- bazarr/get_subtitle.py | 80 ++++++++++++++++++++++-------------------- bazarr/scheduler.py | 3 +- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index d59b90b67..33f7836ca 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -791,14 +791,16 @@ def upgrade_subtitles(): db.close() episodes_to_upgrade = [] - for episode in episodes_list: - if os.path.exists(path_replace(episode[0])) and int(episode[2]) < 360: - episodes_to_upgrade.append(episode) + if settings.general.getboolean('use_sonarr'): + for episode in episodes_list: + if os.path.exists(path_replace(episode[0])) and int(episode[2]) < 360: + episodes_to_upgrade.append(episode) movies_to_upgrade = [] - for movie in movies_list: - if os.path.exists(path_replace_movie(movie[0])) and int(movie[2]) < 120: - movies_to_upgrade.append(movie) + if settings.general.getboolean('use_radarr'): + for movie in movies_list: + if os.path.exists(path_replace_movie(movie[0])) and int(movie[2]) < 120: + movies_to_upgrade.append(movie) providers_list = get_providers() providers_auth = get_providers_auth() @@ -806,36 +808,38 @@ def upgrade_subtitles(): count_episode_to_upgrade = len(episodes_to_upgrade) count_movie_to_upgrade = len(movies_to_upgrade) - for i, episode in enumerate(episodes_to_upgrade, 1): - if episode[1] in ast.literal_eval(str(episode[9])): - notifications.write(msg='Upgrading series subtitles : ' + str(i) + '/' + str(count_episode_to_upgrade), - queue='get_subtitle', duration='long') - result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])), - episode[3], providers_list, providers_auth, str(episode[4]), - episode[5], 'series', forced_minimum_score=int(episode[2]), is_upgrade=True) - if result is not None: - message = result[0] - path = result[1] - language_code = result[2] - provider = result[3] - score = result[4] - store_subtitles(path_replace(episode[0])) - history_log(3, episode[6], episode[7], message, path, language_code, provider, score) - send_notifications(episode[6], episode[7], message) - - for i, movie in enumerate(movies_to_upgrade, 1): - if movie[1] in ast.literal_eval(str(movie[8])): - notifications.write(msg='Upgrading movie subtitles : ' + str(i) + '/' + str(count_movie_to_upgrade), + if settings.general.getboolean('use_sonarr'): + for i, episode in enumerate(episodes_to_upgrade, 1): + if episode[1] in ast.literal_eval(str(episode[9])): + notifications.write(msg='Upgrading series subtitles : ' + str(i) + '/' + str(count_episode_to_upgrade), queue='get_subtitle', duration='long') - result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])), - movie[3], providers_list, providers_auth, str(movie[4]), - movie[5], 'movie', forced_minimum_score=int(movie[2]), is_upgrade=True) - if result is not None: - message = result[0] - path = result[1] - language_code = result[2] - provider = result[3] - score = result[4] - store_subtitles_movie(path_replace_movie(movie[0])) - history_log_movie(3, movie[6], message, path, language_code, provider, score) - send_notifications_movie(movie[6], message) + result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])), + episode[3], providers_list, providers_auth, str(episode[4]), + episode[5], 'series', forced_minimum_score=int(episode[2]), is_upgrade=True) + if result is not None: + message = result[0] + path = result[1] + language_code = result[2] + provider = result[3] + score = result[4] + store_subtitles(path_replace(episode[0])) + history_log(3, episode[6], episode[7], message, path, language_code, provider, score) + send_notifications(episode[6], episode[7], message) + + if settings.general.getboolean('use_radarr'): + for i, movie in enumerate(movies_to_upgrade, 1): + if movie[1] in ast.literal_eval(str(movie[8])): + notifications.write(msg='Upgrading movie subtitles : ' + str(i) + '/' + str(count_movie_to_upgrade), + queue='get_subtitle', duration='long') + result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])), + movie[3], providers_list, providers_auth, str(movie[4]), + movie[5], 'movie', forced_minimum_score=int(movie[2]), is_upgrade=True) + if result is not None: + message = result[0] + path = result[1] + language_code = result[2] + provider = result[3] + score = result[4] + store_subtitles_movie(path_replace_movie(movie[0])) + history_log_movie(3, movie[6], message, path, language_code, provider, score) + send_notifications_movie(movie[6], message) diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index 9856e57da..d0b07f467 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -109,7 +109,8 @@ if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles') -if settings.general.getboolean('upgrade_subs'): +if settings.general.getboolean('upgrade_subs') and (settings.general.getboolean('use_sonarr') or + settings.general.getboolean('use_radarr')): scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True, misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade previously downloaded subtitles')