From f81972b291b73f5771c40359f18d6470b23e2650 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Tue, 15 Mar 2022 16:14:38 -0400 Subject: [PATCH] Fixed upgrade subtitles function that was trying to upgrade deleted episode/movie subtitles. #1759 --- bazarr/api/episodes/history.py | 4 +++- bazarr/api/movies/history.py | 6 ++++-- bazarr/get_subtitle/upgrade.py | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bazarr/api/episodes/history.py b/bazarr/api/episodes/history.py index d6b77bb81..f0a83d397 100644 --- a/bazarr/api/episodes/history.py +++ b/bazarr/api/episodes/history.py @@ -79,6 +79,7 @@ def get(self): TableHistory.score, TableShows.tags, TableHistory.action, + TableHistory.video_path, TableHistory.subtitles_path, TableHistory.sonarrEpisodeId, TableHistory.provider, @@ -101,7 +102,8 @@ def get(self): if {"video_path": str(item['path']), "timestamp": float(item['timestamp']), "score": str(item['score']), "tags": str(item['tags']), "monitored": str(item['monitored']), "seriesType": str(item['seriesType'])} in upgradable_episodes_not_perfect: # noqa: E129 - if os.path.isfile(path_mappings.path_replace(item['subtitles_path'])): + if os.path.exists(path_mappings.path_replace(item['subtitles_path'])) and \ + os.path.exists(path_mappings.path_replace(item['video_path'])): item.update({"upgradable": True}) del item['path'] diff --git a/bazarr/api/movies/history.py b/bazarr/api/movies/history.py index 9f50d335e..8700b2e8e 100644 --- a/bazarr/api/movies/history.py +++ b/bazarr/api/movies/history.py @@ -79,7 +79,8 @@ def get(self): TableHistoryMovie.score, TableHistoryMovie.subs_id, TableHistoryMovie.provider, - TableHistoryMovie.subtitles_path)\ + TableHistoryMovie.subtitles_path, + TableHistoryMovie.video_path)\ .join(TableMovies, on=(TableHistoryMovie.radarrId == TableMovies.radarrId))\ .where(query_condition)\ .order_by(TableHistoryMovie.timestamp.desc())\ @@ -96,7 +97,8 @@ def get(self): item.update({"upgradable": False}) if {"video_path": str(item['path']), "timestamp": float(item['timestamp']), "score": str(item['score']), "tags": str(item['tags']), "monitored": str(item['monitored'])} in upgradable_movies_not_perfect: # noqa: E129 - if os.path.isfile(path_mappings.path_replace_movie(item['subtitles_path'])): + if os.path.exists(path_mappings.path_replace_movie(item['subtitles_path'])) and \ + os.path.exists(path_mappings.path_replace_movie(item['video_path'])): item.update({"upgradable": True}) del item['path'] diff --git a/bazarr/get_subtitle/upgrade.py b/bazarr/get_subtitle/upgrade.py index c1df93a8d..f6d3da6ab 100644 --- a/bazarr/get_subtitle/upgrade.py +++ b/bazarr/get_subtitle/upgrade.py @@ -73,7 +73,9 @@ def upgrade_subtitles(): episodes_to_upgrade = [] for episode in upgradable_episodes_not_perfect: - if os.path.exists(path_mappings.path_replace(episode['subtitles_path'])) and int(episode['score']) < 357: + if os.path.exists(path_mappings.path_replace(episode['subtitles_path'])) and \ + os.path.exists(path_mappings.path_replace(episode['video_path'])) and \ + int(episode['score']) < 357: episodes_to_upgrade.append(episode) count_episode_to_upgrade = len(episodes_to_upgrade) @@ -114,7 +116,9 @@ def upgrade_subtitles(): movies_to_upgrade = [] for movie in upgradable_movies_not_perfect: - if os.path.exists(path_mappings.path_replace_movie(movie['subtitles_path'])) and int(movie['score']) < 117: + if os.path.exists(path_mappings.path_replace_movie(movie['subtitles_path'])) and \ + os.path.exists(path_mappings.path_replace_movie(movie['video_path'])) and \ + int(movie['score']) < 117: movies_to_upgrade.append(movie) count_movie_to_upgrade = len(movies_to_upgrade)