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: for item in data:
# Mark episode as upgradable or not # 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: 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}) if os.path.isfile(path_mappings.path_replace(item['subtitles_path'])):
else: item.update({"upgradable": True})
item.update({"upgradable": False})
# Parse language # Parse language
if item['language'] and item['language'] != 'None': if item['language'] and item['language'] != 'None':
@ -1437,12 +1437,8 @@ class HistorySeries(Resource):
# Provide mapped path # Provide mapped path
mapped_path = path_mappings.path_replace(item['path']) mapped_path = path_mappings.path_replace(item['path'])
item.update({"mapped_path": mapped_path}) item.update({"mapped_path": mapped_path})
# Confirm if path exist
item.update({"exist": os.path.isfile(mapped_path)})
else: else:
item.update({"mapped_path": None}) item.update({"mapped_path": None})
item.update({"exist": False})
if item['subtitles_path']: if item['subtitles_path']:
# Provide mapped subtitles path # Provide mapped subtitles path
@ -1515,10 +1511,10 @@ class HistoryMovies(Resource):
for item in data: for item in data:
# Mark movies as upgradable or not # 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: 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}) if os.path.isfile(path_mappings.path_replace_movie(item['subtitles_path'])):
else: item.update({"upgradable": True})
item.update({"upgradable": False})
# Parse language # Parse language
if item['language'] and item['language'] != 'None': if item['language'] and item['language'] != 'None':
@ -1537,12 +1533,8 @@ class HistoryMovies(Resource):
# Provide mapped path # Provide mapped path
mapped_path = path_mappings.path_replace_movie(item['video_path']) mapped_path = path_mappings.path_replace_movie(item['video_path'])
item.update({"mapped_path": mapped_path}) item.update({"mapped_path": mapped_path})
# Confirm if path exist
item.update({"exist": os.path.isfile(mapped_path)})
else: else:
item.update({"mapped_path": None}) item.update({"mapped_path": None})
item.update({"exist": False})
if item['subtitles_path']: if item['subtitles_path']:
# Provide mapped 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_history.score, table_shows.tags, table_shows.profileId, "
"table_episodes.audio_language, table_episodes.scene_name, " "table_episodes.audio_language, table_episodes.scene_name, "
"table_episodes.title, table_episodes.sonarrSeriesId, " "table_episodes.title, table_episodes.sonarrSeriesId, "
"table_episodes.sonarrEpisodeId, MAX(table_history.timestamp) " "table_history.subtitles_path, table_episodes.sonarrEpisodeId, "
"as timestamp, table_episodes.monitored, table_shows.seriesType FROM " "MAX(table_history.timestamp) as timestamp, table_episodes.monitored, "
"table_history INNER JOIN table_shows on table_shows.sonarrSeriesId = " "table_shows.seriesType FROM table_history INNER JOIN table_shows on "
"table_history.sonarrSeriesId INNER JOIN table_episodes on " "table_shows.sonarrSeriesId = table_history.sonarrSeriesId INNER JOIN "
"table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId WHERE " "table_episodes on table_episodes.sonarrEpisodeId = "
"action IN (" + ','.join(map(str, query_actions)) + "table_history.sonarrEpisodeId WHERE action IN "
") AND timestamp > ? AND score is not null" + "(" + ','.join(map(str, query_actions)) + ") AND timestamp > ? AND "
get_exclusion_clause('series') + " GROUP BY " "score is not null" + get_exclusion_clause('series') + " GROUP BY "
"table_history.video_path, table_history.language", "table_history.video_path, table_history.language",
(minimum_timestamp,)) (minimum_timestamp,))
upgradable_episodes_not_perfect = [] upgradable_episodes_not_perfect = []
@ -1227,7 +1227,7 @@ def upgrade_subtitles():
episodes_to_upgrade = [] episodes_to_upgrade = []
for episode in upgradable_episodes_not_perfect: 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) episodes_to_upgrade.append(episode)
count_episode_to_upgrade = len(episodes_to_upgrade) count_episode_to_upgrade = len(episodes_to_upgrade)
@ -1235,12 +1235,12 @@ def upgrade_subtitles():
if settings.general.getboolean('use_radarr'): if settings.general.getboolean('use_radarr'):
upgradable_movies = database.execute("SELECT table_history_movie.video_path, table_history_movie.language, " upgradable_movies = database.execute("SELECT table_history_movie.video_path, table_history_movie.language, "
"table_history_movie.score, table_movies.profileId, " "table_history_movie.score, table_movies.profileId, "
"table_movies.audio_language, table_movies.sceneName, table_movies.title, " "table_history_movie.subtitles_path, table_movies.audio_language, "
"table_movies.radarrId, MAX(table_history_movie.timestamp) as timestamp, " "table_movies.sceneName, table_movies.title, table_movies.radarrId, "
"table_movies.tags, table_movies.monitored FROM table_history_movie INNER " "MAX(table_history_movie.timestamp) as timestamp, table_movies.tags, "
"JOIN table_movies on table_movies.radarrId = " "table_movies.monitored FROM table_history_movie INNER JOIN table_movies "
"table_history_movie.radarrId WHERE action IN (" + "on table_movies.radarrId = table_history_movie.radarrId WHERE action IN "
','.join(map(str, query_actions)) + ") AND timestamp > ? AND score " "(" + ','.join(map(str, query_actions)) + ") AND timestamp > ? AND score "
"is not null" + get_exclusion_clause('movie') + " GROUP BY " "is not null" + get_exclusion_clause('movie') + " GROUP BY "
"table_history_movie.video_path, table_history_movie.language", "table_history_movie.video_path, table_history_movie.language",
(minimum_timestamp,)) (minimum_timestamp,))
@ -1257,7 +1257,7 @@ def upgrade_subtitles():
movies_to_upgrade = [] movies_to_upgrade = []
for movie in upgradable_movies_not_perfect: 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) movies_to_upgrade.append(movie)
count_movie_to_upgrade = len(movies_to_upgrade) count_movie_to_upgrade = len(movies_to_upgrade)