From c8850509d747f53c9234c85768dd09cbdf7f9da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 29 Aug 2019 20:16:11 -0400 Subject: [PATCH] Continuing development. --- bazarr/get_subtitle.py | 29 ++++++++++++++++++++++++----- bazarr/main.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index be591b85c..783a89f5e 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -1051,12 +1051,33 @@ def upgrade_subtitles(): 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] + episodes_details_clause = [ + (TableHistory.action.in_(query_actions)) & + (TableHistory.score.is_null(False)) + ] + + if settings.sonarr.getboolean('only_monitored'): + episodes_details_clause.append( + (TableEpisodes.monitored == 'True') + ) + + movies_details_clause = [ + (TableHistoryMovie.action.in_(query_actions)) & + (TableHistoryMovie.score.is_null(False)) + ] + + if settings.radarr.getboolean('only_monitored'): + movies_details_clause.append( + (TableMovies.monitored == 'True') + ) + + if settings.general.getboolean('use_sonarr'): upgradable_episodes = TableHistory.select( TableHistory.video_path, @@ -1075,8 +1096,7 @@ def upgrade_subtitles(): ).join_from( TableHistory, TableEpisodes, JOIN.LEFT_OUTER ).where( - (TableHistory.action.in_(query_actions)) & - (TableHistory.score.is_null(False)) + reduce(operator.and_, episodes_details_clause) ).group_by( TableHistory.video_path, TableHistory.language @@ -1113,8 +1133,7 @@ def upgrade_subtitles(): ).join_from( TableHistoryMovie, TableMovies, JOIN.LEFT_OUTER ).where( - (TableHistoryMovie.action.in_(query_actions)) & - (TableHistoryMovie.score.is_null(False)) + reduce(operator.and_, movies_details_clause) ).group_by( TableHistoryMovie.video_path, TableHistoryMovie.language diff --git a/bazarr/main.py b/bazarr/main.py index 03d4f6616..13e4d4645 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1175,19 +1175,30 @@ def historyseries(): 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] - + + episodes_details_clause = [ + (TableHistory.action.in_(query_actions)) & + (TableHistory.score.is_null(False)) + ] + + if settings.sonarr.getboolean('only_monitored'): + episodes_details_clause.append( + (TableEpisodes.monitored == 'True') + ) + upgradable_episodes = TableHistory.select( TableHistory.video_path, fn.MAX(TableHistory.timestamp).alias('timestamp'), TableHistory.score + ).join_from( + TableHistory, TableEpisodes, JOIN.LEFT_OUTER ).where( - (TableHistory.action.in_(query_actions)) & - (TableHistory.score.is_null(False)) + reduce(operator.and_, episodes_details_clause) ).group_by( TableHistory.video_path, TableHistory.language @@ -1271,14 +1282,25 @@ def historymovies(): query_actions = [1, 2, 3] else: query_actions = [1, 3] - + + movies_details_clause = [ + (TableHistoryMovie.action.in_(query_actions)) & + (TableHistoryMovie.score.is_null(False)) + ] + + if settings.radarr.getboolean('only_monitored'): + movies_details_clause.append( + (TableMovies.monitored == 'True') + ) + upgradable_movies = TableHistoryMovie.select( TableHistoryMovie.video_path, fn.MAX(TableHistoryMovie.timestamp).alias('timestamp'), TableHistoryMovie.score + ).join_from( + TableHistoryMovie, TableMovies, JOIN.LEFT_OUTER ).where( - (TableHistoryMovie.action.in_(query_actions)) & - (TableHistoryMovie.score.is_null(False)) + reduce(operator.and_, movies_details_clause) ).group_by( TableHistoryMovie.video_path, TableHistoryMovie.language