Skip to content

Commit

Permalink
Fixed upgrade subtitles function that was trying to upgrade deleted e…
Browse files Browse the repository at this point in the history
…pisode/movie subtitles. #1759
  • Loading branch information
morpheus65535 committed Mar 15, 2022
1 parent 6fc4f13 commit f81972b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bazarr/api/episodes/history.py
Expand Up @@ -79,6 +79,7 @@ def get(self):
TableHistory.score,
TableShows.tags,
TableHistory.action,
TableHistory.video_path,
TableHistory.subtitles_path,
TableHistory.sonarrEpisodeId,
TableHistory.provider,
Expand All @@ -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']
Expand Down
6 changes: 4 additions & 2 deletions bazarr/api/movies/history.py
Expand Up @@ -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())\
Expand All @@ -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']
Expand Down
8 changes: 6 additions & 2 deletions bazarr/get_subtitle/upgrade.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f81972b

Please sign in to comment.