diff --git a/bazarr/config.py b/bazarr/config.py index 87bd91119..3b23f829e 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -39,7 +39,8 @@ defaults = { 'subfolder': 'current', 'subfolder_custom': '', 'upgrade_subs': 'True', - 'days_to_upgrade_subs': '7' + 'days_to_upgrade_subs': '7', + 'upgrade_manual': 'True' }, 'auth': { 'type': 'None', diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index a24d9ce7d..17f29d6e9 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -111,7 +111,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName, else: hi = False language_set = set() - + original_language = language if not isinstance(language, types.ListType): language = [language] @@ -184,9 +184,9 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName, saved_any = True for subtitle in saved_subtitles: downloaded_provider = subtitle.provider_name - downloaded_language = language_from_alpha3(subtitle.language.alpha3) - downloaded_language_code2 = alpha2_from_alpha3(subtitle.language.alpha3) - downloaded_language_code3 = subtitle.language.alpha3 + downloaded_language = language_from_alpha3(original_language) + downloaded_language_code2 = alpha2_from_alpha3(original_language) + downloaded_language_code3 = original_language downloaded_path = subtitle.storage_path logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path) if video.used_scene_name: @@ -715,24 +715,32 @@ def upgrade_subtitles(): minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) - datetime(1970, 1, 1)).total_seconds() + if settings.general.getboolean('upgrade_manual'): + query_actions = [1, 2, 3] + else: + query_actions = [1, 3] + db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() episodes_list = c.execute("""SELECT table_history.video_path, table_history.language, table_history.score, table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.title, table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId, - MAX(table_history.timestamp) + MAX(table_history.timestamp), table_shows.languages FROM table_history INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId - WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360" + WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND + score is not null AND score < "360" GROUP BY table_history.video_path, table_history.language""", (minimum_timestamp,)).fetchall() movies_list = c.execute("""SELECT table_history_movie.video_path, table_history_movie.language, table_history_movie.score, table_movies.hearing_impaired, table_movies.sceneName, - table_movies.title, table_movies.radarrId, MAX(table_history_movie.timestamp) + table_movies.title, table_movies.radarrId, MAX(table_history_movie.timestamp), + table_movies.languages FROM table_history_movie INNER JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId - WHERE action = 1 AND timestamp > ? AND score is not null AND score < "120" + WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND + score is not null AND score < "120" GROUP BY table_history_movie.video_path, table_history_movie.language""", (minimum_timestamp,)).fetchall() db.close() @@ -751,35 +759,37 @@ def upgrade_subtitles(): providers_auth = get_providers_auth() for episode in episodes_to_upgrade: - notifications.write( - msg='Searching to upgrade ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' + - path_replace(episode[0]), queue='get_subtitle') - 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])) - 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(1, episode[6], episode[7], message, path, language_code, provider, score) - send_notifications(episode[6], episode[7], message) + if episode[1] in ast.literal_eval(str(episode[9])): + notifications.write( + msg='Searching to upgrade ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' + + path_replace(episode[0]), queue='get_subtitle') + 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])) + 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 movie in movies_to_upgrade: - notifications.write( - msg='Searching to upgrade ' + str(language_from_alpha2(movie[1])) + ' subtitles for this movie: ' + - path_replace_movie(movie[0]), queue='get_subtitle') - 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])) - 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(1, movie[6], message, path, language_code, provider, score) - send_notifications_movie(movie[6], message) + if movie[1] in ast.literal_eval(str(movie[8])): + notifications.write( + msg='Searching to upgrade ' + str(language_from_alpha2(movie[1])) + ' subtitles for this movie: ' + + path_replace_movie(movie[0]), queue='get_subtitle') + 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])) + 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/main.py b/bazarr/main.py index 73a7e26fa..52835c96b 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -284,6 +284,11 @@ def save_wizard(): else: settings_upgrade_subs = 'True' settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs') + settings_upgrade_manual = request.forms.get('settings_upgrade_manual') + if settings_upgrade_manual is None: + settings_upgrade_manual = 'False' + else: + settings_upgrade_manual = 'True' settings.general.ip = text_type(settings_general_ip) settings.general.port = text_type(settings_general_port) @@ -298,6 +303,7 @@ def save_wizard(): settings.general.use_embedded_subs = text_type(settings_general_embedded) settings.general.upgrade_subs = text_type(settings_upgrade_subs) settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs) + settings.general.upgrade_manual = text_type(settings_upgrade_manual) settings_sonarr_ip = request.forms.get('settings_sonarr_ip') settings_sonarr_port = request.forms.get('settings_sonarr_port') @@ -959,14 +965,35 @@ def historyseries(): stats = [len(today), len(thisweek), len(thisyear), total] c.execute( - "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?", + "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId, table_episodes.path, table_shows.languages, table_history.language FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() + + upgradable_episodes = [] + if settings.general.getboolean('upgrade_subs'): + days_to_upgrade_subs = settings.general.days_to_upgrade_subs + minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) - + datetime(1970, 1, 1)).total_seconds() + + if settings.general.getboolean('upgrade_manual'): + query_actions = [1, 2, 3] + else: + query_actions = [1, 3] + + upgradable_episodes = c.execute("""SELECT table_history.video_path, MAX(table_history.timestamp) + FROM table_history + WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > + ? AND score is not null AND score < "360" + GROUP BY table_history.video_path, table_history.language""", + (minimum_timestamp,)).fetchall() + c.close() + data = reversed(sorted(data, key=operator.itemgetter(4))) + return template('historyseries', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, - current_port=settings.general.port) + current_port=settings.general.port, upgradable_episodes=upgradable_episodes) @route(base_url + 'historymovies') @@ -1002,14 +1029,33 @@ def historymovies(): stats = [len(today), len(thisweek), len(thisyear), total] c.execute( - "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?", + "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId, table_history_movie.video_path, table_movies.languages, table_history_movie.language FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() + + upgradable_movies = [] + if settings.general.getboolean('upgrade_subs'): + days_to_upgrade_subs = settings.general.days_to_upgrade_subs + minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) - + datetime(1970, 1, 1)).total_seconds() + + if settings.general.getboolean('upgrade_manual'): + query_actions = [1, 2, 3] + else: + query_actions = [1, 3] + + upgradable_movies = c.execute("""SELECT video_path, MAX(timestamp) + FROM table_history_movie + WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp + > ? AND score is not null AND score < "120" + GROUP BY video_path, language""", + (minimum_timestamp,)).fetchall() + c.close() data = reversed(sorted(data, key=operator.itemgetter(2))) return template('historymovies', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, - current_port=settings.general.port) + current_port=settings.general.port, upgradable_movies=upgradable_movies) @route(base_url + 'wanted') @@ -1201,6 +1247,11 @@ def save_settings(): else: settings_upgrade_subs = 'True' settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs') + settings_upgrade_manual = request.forms.get('settings_upgrade_manual') + if settings_upgrade_manual is None: + settings_upgrade_manual = 'False' + else: + settings_upgrade_manual = 'True' before = (unicode(settings.general.ip), int(settings.general.port), unicode(settings.general.base_url), unicode(settings.general.path_mappings), unicode(settings.general.getboolean('use_sonarr')), @@ -1230,6 +1281,7 @@ def save_settings(): settings.general.subfolder_custom = text_type(settings_subfolder_custom) settings.general.upgrade_subs = text_type(settings_upgrade_subs) settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs) + settings.general.upgrade_manual = text_type(settings_upgrade_manual) settings.general.minimum_score_movie = text_type(settings_general_minimum_score_movies) settings.general.use_embedded_subs = text_type(settings_general_embedded) settings.general.adaptive_searching = text_type(settings_general_adaptive_searching) @@ -1759,7 +1811,7 @@ def manual_get_subtitle(): language_code = result[2] provider = result[3] score = result[4] - history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) + history_log(2, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) send_notifications(sonarrSeriesId, sonarrEpisodeId, message) store_subtitles(unicode(episodePath)) list_missing_subtitles(sonarrSeriesId) @@ -1848,7 +1900,7 @@ def manual_get_subtitle_movie(): language_code = result[2] provider = result[3] score = result[4] - history_log_movie(1, radarrId, message, path, language_code, provider, score) + history_log_movie(2, radarrId, message, path, language_code, provider, score) send_notifications_movie(radarrId, message) store_subtitles_movie(unicode(moviePath)) list_missing_subtitles_movies(radarrId) diff --git a/views/historymovies.tpl b/views/historymovies.tpl index baad469e4..01895b78e 100644 --- a/views/historymovies.tpl +++ b/views/historymovies.tpl @@ -52,6 +52,7 @@ + %import ast %import time %import pretty %for row in rows: @@ -65,6 +66,14 @@
+ %elif row[0] == 2: +
+ +
+ %elif row[0] == 3: +
+ +
%end @@ -75,7 +84,20 @@ {{pretty.date(int(row[2]))}} - {{row[3]}} + + % upgradable_criteria = (row[5], row[2]) + % if upgradable_criteria in upgradable_movies: + % if row[7] in ast.literal_eval(str(row[6])): +
+ {{row[3]}} +
+ % else: + {{row[3]}} + % end + % else: + {{row[3]}} + %end + %end diff --git a/views/historyseries.tpl b/views/historyseries.tpl index f29fea046..442793717 100644 --- a/views/historyseries.tpl +++ b/views/historyseries.tpl @@ -54,6 +54,7 @@ + %import ast %import time %import pretty %for row in rows: @@ -67,6 +68,14 @@
+ %elif row[0] == 2: +
+ +
+ %elif row[0] == 3: +
+ +
%end @@ -90,7 +99,20 @@ {{pretty.date(int(row[4]))}} - {{row[5]}} + + % upgradable_criteria = (row[7], row[4]) + % if upgradable_criteria in upgradable_episodes: + % if row[9] in ast.literal_eval(str(row[8])): +
+ {{row[5]}} +
+ % else: + {{row[5]}} + % end + % else: + {{row[5]}} + %end + %end diff --git a/views/settings.tpl b/views/settings.tpl index 93bd1810e..b8693264c 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -1137,6 +1137,27 @@ +
+
+
+ +
+
+
+ + +
+
+ + +
+
@@ -2067,6 +2088,12 @@ $("#settings_upgrade_subs").checkbox('uncheck'); } + if ($('#settings_upgrade_manual').data("upgrade-manual") === "True") { + $("#settings_upgrade_manual").checkbox('check'); + } else { + $("#settings_upgrade_manual").checkbox('uncheck'); + } + if ($('#settings_embedded').data("embedded") === "True") { $("#settings_embedded").checkbox('check'); } else {