Fix for deleted subtitles getting upgraded even if they aren't there anymore.

This commit is contained in:
morpheus65535 2021-02-05 17:40:19 -05:00
parent 2aed0a2dc7
commit e20bbbe2af
2 changed files with 22 additions and 30 deletions

View File

@ -1414,10 +1414,10 @@ class HistorySeries(Resource):
for item in data:
# Mark episode as upgradable or not
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']), "seriesType": str(item['seriesType'])} in upgradable_episodes_not_perfect:
item.update({"upgradable": True})
else:
item.update({"upgradable": False})
if os.path.isfile(path_mappings.path_replace(item['subtitles_path'])):
item.update({"upgradable": True})
# Parse language
if item['language'] and item['language'] != 'None':
@ -1437,12 +1437,8 @@ class HistorySeries(Resource):
# Provide mapped path
mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
item.update({"exist": os.path.isfile(mapped_path)})
else:
item.update({"mapped_path": None})
item.update({"exist": False})
if item['subtitles_path']:
# Provide mapped subtitles path
@ -1515,10 +1511,10 @@ class HistoryMovies(Resource):
for item in data:
# Mark movies as upgradable or not
item.update({"upgradable": False})
if {"video_path": str(item['video_path']), "timestamp": float(item['timestamp']), "score": str(item['score']), "tags": str(item['tags']), "monitored": str(item['monitored'])} in upgradable_movies_not_perfect:
item.update({"upgradable": True})
else:
item.update({"upgradable": False})
if os.path.isfile(path_mappings.path_replace_movie(item['subtitles_path'])):
item.update({"upgradable": True})
# Parse language
if item['language'] and item['language'] != 'None':
@ -1537,12 +1533,8 @@ class HistoryMovies(Resource):
# Provide mapped path
mapped_path = path_mappings.path_replace_movie(item['video_path'])
item.update({"mapped_path": mapped_path})
# Confirm if path exist
item.update({"exist": os.path.isfile(mapped_path)})
else:
item.update({"mapped_path": None})
item.update({"exist": False})
if item['subtitles_path']:
# Provide mapped subtitles path

View File

@ -1204,14 +1204,14 @@ def upgrade_subtitles():
"table_history.score, table_shows.tags, table_shows.profileId, "
"table_episodes.audio_language, table_episodes.scene_name, "
"table_episodes.title, table_episodes.sonarrSeriesId, "
"table_episodes.sonarrEpisodeId, MAX(table_history.timestamp) "
"as timestamp, table_episodes.monitored, table_shows.seriesType 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 IN (" + ','.join(map(str, query_actions)) +
") AND timestamp > ? AND score is not null" +
get_exclusion_clause('series') + " GROUP BY "
"table_history.subtitles_path, table_episodes.sonarrEpisodeId, "
"MAX(table_history.timestamp) as timestamp, table_episodes.monitored, "
"table_shows.seriesType 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 IN "
"(" + ','.join(map(str, query_actions)) + ") AND timestamp > ? AND "
"score is not null" + get_exclusion_clause('series') + " GROUP BY "
"table_history.video_path, table_history.language",
(minimum_timestamp,))
upgradable_episodes_not_perfect = []
@ -1227,7 +1227,7 @@ def upgrade_subtitles():
episodes_to_upgrade = []
for episode in upgradable_episodes_not_perfect:
if os.path.exists(path_mappings.path_replace(episode['video_path'])) and int(episode['score']) < 357:
if os.path.exists(path_mappings.path_replace(episode['subtitles_path'])) and int(episode['score']) < 357:
episodes_to_upgrade.append(episode)
count_episode_to_upgrade = len(episodes_to_upgrade)
@ -1235,12 +1235,12 @@ def upgrade_subtitles():
if settings.general.getboolean('use_radarr'):
upgradable_movies = database.execute("SELECT table_history_movie.video_path, table_history_movie.language, "
"table_history_movie.score, table_movies.profileId, "
"table_movies.audio_language, table_movies.sceneName, table_movies.title, "
"table_movies.radarrId, MAX(table_history_movie.timestamp) as timestamp, "
"table_movies.tags, table_movies.monitored FROM table_history_movie INNER "
"JOIN table_movies on table_movies.radarrId = "
"table_history_movie.radarrId WHERE action IN (" +
','.join(map(str, query_actions)) + ") AND timestamp > ? AND score "
"table_history_movie.subtitles_path, table_movies.audio_language, "
"table_movies.sceneName, table_movies.title, table_movies.radarrId, "
"MAX(table_history_movie.timestamp) as timestamp, table_movies.tags, "
"table_movies.monitored FROM table_history_movie INNER JOIN table_movies "
"on table_movies.radarrId = table_history_movie.radarrId WHERE action IN "
"(" + ','.join(map(str, query_actions)) + ") AND timestamp > ? AND score "
"is not null" + get_exclusion_clause('movie') + " GROUP BY "
"table_history_movie.video_path, table_history_movie.language",
(minimum_timestamp,))
@ -1257,7 +1257,7 @@ def upgrade_subtitles():
movies_to_upgrade = []
for movie in upgradable_movies_not_perfect:
if os.path.exists(path_mappings.path_replace_movie(movie['video_path'])) and int(movie['score']) < 117:
if os.path.exists(path_mappings.path_replace_movie(movie['subtitles_path'])) and int(movie['score']) < 117:
movies_to_upgrade.append(movie)
count_movie_to_upgrade = len(movies_to_upgrade)