From 81e6716d017f75c500572b2037fb790a95b75063 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sun, 2 May 2021 17:06:50 -0400 Subject: [PATCH] Revert "Cache ffprobe results" This reverts commit dcbd7f00 --- bazarr/api.py | 16 ++--- bazarr/database.py | 4 -- bazarr/embedded_subs_reader.py | 26 +++----- bazarr/get_episodes.py | 82 ++++++++++++------------- bazarr/get_movies.py | 106 +++++++++++++++++---------------- bazarr/get_subtitle.py | 36 +++++------ bazarr/list_subtitles.py | 65 ++++++++++---------- bazarr/utils.py | 75 ++--------------------- 8 files changed, 162 insertions(+), 248 deletions(-) diff --git a/bazarr/api.py b/bazarr/api.py index 35545f5c4..d794c20a8 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -721,7 +721,7 @@ class EpisodesSubtitles(Resource): history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score, subs_id, subs_path) send_notifications(sonarrSeriesId, sonarrEpisodeId, message) - store_subtitles(path, episodePath, 'episode', sonarrEpisodeId) + store_subtitles(path, episodePath) else: event_stream(type='episode', action='update', series=int(sonarrSeriesId), episode=int(sonarrEpisodeId)) @@ -777,7 +777,7 @@ class EpisodesSubtitles(Resource): subtitles_path=subs_path) if not settings.general.getboolean('dont_notify_manual_actions'): send_notifications(sonarrSeriesId, sonarrEpisodeId, message) - store_subtitles(path, episodePath, 'episode', sonarrEpisodeId) + store_subtitles(path, episodePath) except OSError: pass @@ -927,7 +927,7 @@ class MoviesSubtitles(Resource): subs_path = result[7] history_log_movie(1, radarrId, message, path, language_code, provider, score, subs_id, subs_path) send_notifications_movie(radarrId, message) - store_subtitles_movie(path, moviePath, 'movie', radarrId) + store_subtitles_movie(path, moviePath) else: event_stream(type='movie', action='update', movie=int(radarrId)) except OSError: @@ -982,7 +982,7 @@ class MoviesSubtitles(Resource): history_log_movie(4, radarrId, message, path, language_code, provider, score, subtitles_path=subs_path) if not settings.general.getboolean('dont_notify_manual_actions'): send_notifications_movie(radarrId, message) - store_subtitles_movie(path, moviePath, 'movie', radarrId) + store_subtitles_movie(path, moviePath) except OSError: pass @@ -1109,7 +1109,7 @@ class ProviderMovies(Resource): history_log_movie(2, radarrId, message, path, language_code, provider, score, subs_id, subs_path) if not settings.general.getboolean('dont_notify_manual_actions'): send_notifications_movie(radarrId, message) - store_subtitles_movie(path, moviePath, 'movie', radarrId) + store_subtitles_movie(path, moviePath) except OSError: pass @@ -1192,7 +1192,7 @@ class ProviderEpisodes(Resource): subs_path) if not settings.general.getboolean('dont_notify_manual_actions'): send_notifications(sonarrSeriesId, sonarrEpisodeId, message) - store_subtitles(path, episodePath, 'episode', sonarrEpisodeId) + store_subtitles(path, episodePath) return result, 201 except OSError: pass @@ -1654,9 +1654,9 @@ class Subtitles(Resource): forced=forced, hi=hi) if result: if media_type == 'episode': - store_subtitles(path_mappings.path_replace_reverse(video_path), video_path, 'episode', id) + store_subtitles(path_mappings.path_replace_reverse(video_path), video_path) else: - store_subtitles_movie(path_mappings.path_replace_reverse_movie(video_path), video_path, 'movie', id) + store_subtitles_movie(path_mappings.path_replace_reverse_movie(video_path), video_path) return '', 200 else: return '', 404 diff --git a/bazarr/database.py b/bazarr/database.py index abfd3583b..992189e84 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -108,8 +108,6 @@ def db_upgrade(): ['table_episodes', 'audio_codec', 'text'], ['table_episodes', 'episode_file_id', 'integer'], ['table_episodes', 'audio_language', 'text'], - ['table_episodes', 'file_size', 'integer', '0'], - ['table_episodes', 'file_ffprobe', 'text'], ['table_movies', 'sortTitle', 'text'], ['table_movies', 'year', 'text'], ['table_movies', 'alternativeTitles', 'text'], @@ -122,8 +120,6 @@ def db_upgrade(): ['table_movies', 'movie_file_id', 'integer'], ['table_movies', 'tags', 'text', '[]'], ['table_movies', 'profileId', 'integer'], - ['table_movies', 'file_ffprobe', 'text'], - ['table_movies', 'file_size', 'integer', '0'], ['table_history', 'video_path', 'text'], ['table_history', 'language', 'text'], ['table_history', 'provider', 'text'], diff --git a/bazarr/embedded_subs_reader.py b/bazarr/embedded_subs_reader.py index 96250b0c6..fda402d4a 100644 --- a/bazarr/embedded_subs_reader.py +++ b/bazarr/embedded_subs_reader.py @@ -10,28 +10,21 @@ from knowit import api class EmbeddedSubsReader: def __init__(self): self.ffprobe = None - self.cache = None - self.data = None - - def list_languages(self, file, original_path, record_type=None, record_id=None): - from utils import get_binary, cache_get_ffprobe, cache_save_ffprobe - - self.cache = cache_get_ffprobe(original_path, record_type, record_id) - if self.cache['ffprobe'] is not None: - return self.cache['ffprobe'] - + + def list_languages(self, file): + from utils import get_binary self.ffprobe = get_binary("ffprobe") subtitles_list = [] if self.ffprobe: api.initialize({'provider': 'ffmpeg', 'ffmpeg': self.ffprobe}) - self.data = api.know(file) + data = api.know(file) traditional_chinese = ["cht", "tc", "traditional", "zht", "hant", "big5", u"繁", u"雙語"] brazilian_portuguese = ["pt-br", "pob", "pb", "brazilian", "brasil", "brazil"] - if 'subtitle' in self.data: - for detected_language in self.data['subtitle']: + if 'subtitle' in data: + for detected_language in data['subtitle']: if 'language' in detected_language: language = detected_language['language'].alpha3 if language == 'zho' and 'name' in detected_language: @@ -51,11 +44,11 @@ class EmbeddedSubsReader: if os.path.splitext(file)[1] == '.mkv': with open(file, 'rb') as f: try: - self.data = enzyme.MKV(f) + mkv = enzyme.MKV(f) except MalformedMKVError: logging.error('BAZARR cannot analyze this MKV with our built-in MKV parser, you should install ffmpeg: ' + file) else: - for subtitle_track in self.data.subtitle_tracks: + for subtitle_track in mkv.subtitle_tracks: hearing_impaired = False if subtitle_track.name: if 'sdh' in subtitle_track.name.lower(): @@ -63,9 +56,6 @@ class EmbeddedSubsReader: subtitles_list.append([subtitle_track.language, subtitle_track.forced, hearing_impaired, subtitle_track.codec_id]) - if self.cache['type'] and self.cache['id']: - cache_save_ffprobe(original_path, self.cache['type'], self.cache['id'], subtitles_list) - return subtitles_list diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index af1118279..0840715a1 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -4,7 +4,7 @@ import os import requests import logging from database import database, dict_converter, get_exclusion_clause -from utils import cache_is_valid + from config import settings, url_sonarr from helper import path_mappings from list_subtitles import store_subtitles, series_full_scan_subtitles @@ -22,9 +22,9 @@ def update_all_episodes(): def sync_episodes(): logging.debug('BAZARR Starting episodes sync from Sonarr.') apikey_sonarr = settings.sonarr.apikey - + # Get current episodes id in DB - current_episodes_db = database.execute("SELECT sonarrEpisodeId FROM table_episodes") + current_episodes_db = database.execute("SELECT sonarrEpisodeId, path, sonarrSeriesId FROM table_episodes") current_episodes_db_list = [x['sonarrEpisodeId'] for x in current_episodes_db] @@ -32,10 +32,10 @@ def sync_episodes(): episodes_to_update = [] episodes_to_add = [] altered_episodes = [] - + # Get sonarrId for each series from database seriesIdList = database.execute("SELECT sonarrSeriesId, title FROM table_shows") - + for i, seriesId in enumerate(seriesIdList): # Get episodes data for a series from Sonarr url_sonarr_api_episode = url_sonarr() + "/api/episode?seriesId=" + str(seriesId['sonarrSeriesId']) + "&apikey=" + apikey_sonarr @@ -66,11 +66,6 @@ def sync_episodes(): else: sceneName = None - if 'size' in episode['episodeFile']: - fileSize = int(episode['episodeFile']['size']) - else: - fileSize = 0 - try: format, resolution = episode['episodeFile']['quality']['quality']['name'].split('-') except: @@ -84,14 +79,12 @@ def sync_episodes(): if 'videoCodec' in episode['episodeFile']['mediaInfo']: videoCodec = episode['episodeFile']['mediaInfo']['videoCodec'] videoCodec = SonarrFormatVideoCodec(videoCodec) - else: - videoCodec = None + else: videoCodec = None if 'audioCodec' in episode['episodeFile']['mediaInfo']: audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] audioCodec = SonarrFormatAudioCodec(audioCodec) - else: - audioCodec = None + else: audioCodec = None else: videoCodec = None audioCodec = None @@ -109,35 +102,37 @@ def sync_episodes(): # Add episodes in sonarr to current episode list current_episodes_sonarr.append(episode['id']) - - info = { - 'sonarrSeriesId': episode['seriesId'], - 'sonarrEpisodeId': episode['id'], - 'title': episode['title'], - 'path': episode['episodeFile']['path'], - 'season': episode['seasonNumber'], - 'episode': episode['episodeNumber'], - 'scene_name': sceneName, - 'monitored': str(bool(episode['monitored'])), - 'format': format, - 'resolution': resolution, - 'video_codec': videoCodec, - 'audio_codec': audioCodec, - 'episode_file_id': episode['episodeFile']['id'], - 'audio_language': str(audio_language), - 'file_size': fileSize, - } - + if episode['id'] in current_episodes_db_list: - if not cache_is_valid(info['path'], info['file_size'], 'episode', info['sonarrEpisodeId']): - logging.debug('Path and/or Size is not the same. Invalidating ffprobe cache data for: [%s:%s, %s].', - 'episode', info['sonarrEpisodeId'], info['path']) - info.update({'file_ffprobe': None}) - - episodes_to_update.append(info) + episodes_to_update.append({'sonarrSeriesId': episode['seriesId'], + 'sonarrEpisodeId': episode['id'], + 'title': episode['title'], + 'path': episode['episodeFile']['path'], + 'season': episode['seasonNumber'], + 'episode': episode['episodeNumber'], + 'scene_name': sceneName, + 'monitored': str(bool(episode['monitored'])), + 'format': format, + 'resolution': resolution, + 'video_codec': videoCodec, + 'audio_codec': audioCodec, + 'episode_file_id': episode['episodeFile']['id'], + 'audio_language': str(audio_language)}) else: - info.update({'file_ffprobe': None}) - episodes_to_add.append(info) + episodes_to_add.append({'sonarrSeriesId': episode['seriesId'], + 'sonarrEpisodeId': episode['id'], + 'title': episode['title'], + 'path': episode['episodeFile']['path'], + 'season': episode['seasonNumber'], + 'episode': episode['episodeNumber'], + 'scene_name': sceneName, + 'monitored': str(bool(episode['monitored'])), + 'format': format, + 'resolution': resolution, + 'video_codec': videoCodec, + 'audio_codec': audioCodec, + 'episode_file_id': episode['episodeFile']['id'], + 'audio_language': str(audio_language)}) # Remove old episodes from DB removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) @@ -153,7 +148,7 @@ def sync_episodes(): episode_in_db_list = [] episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, " "scene_name, monitored, format, resolution, video_codec, audio_codec, " - "episode_file_id, audio_language, file_ffprobe FROM table_episodes") + "episode_file_id, audio_language FROM table_episodes") for item in episodes_in_db: episode_in_db_list.append(item) @@ -185,8 +180,7 @@ def sync_episodes(): # Store subtitles for added or modified episodes for i, altered_episode in enumerate(altered_episodes, 1): - store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1]), - 'episode', altered_episode[0]) + store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1])) logging.debug('BAZARR All episodes synced from Sonarr into database.') diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index b59da4a40..9ab7fd7d0 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -6,7 +6,7 @@ import logging from config import settings, url_radarr from helper import path_mappings -from utils import get_radarr_version, cache_is_valid +from utils import get_radarr_version from list_subtitles import store_subtitles_movie, movies_full_scan_subtitles from get_subtitle import movies_download_subtitles @@ -39,7 +39,7 @@ def update_movies(): else: audio_profiles = get_profile_list() tagsDict = get_tags() - + # Get movies data from radarr if radarr_version.startswith('0'): url_radarr_api_movies = url_radarr() + "/api/movie?apikey=" + apikey_radarr @@ -63,8 +63,8 @@ def update_movies(): return else: # Get current movies in DB - current_movies_db = database.execute("SELECT tmdbId FROM table_movies") - + current_movies_db = database.execute("SELECT tmdbId, path, radarrId FROM table_movies") + current_movies_db_list = [x['tmdbId'] for x in current_movies_db] current_movies_radarr = [] @@ -96,17 +96,12 @@ def update_movies(): fanart = movie['images'][1]['url'] except: fanart = "" - + if 'sceneName' in movie['movieFile']: sceneName = movie['movieFile']['sceneName'] else: sceneName = None - if 'size' in movie['movieFile']: - fileSize = movie['movieFile']['size'] - else: - fileSize = 0 - alternativeTitles = None if radarr_version.startswith('0'): if 'alternativeTitles' in movie: @@ -115,10 +110,8 @@ def update_movies(): if 'alternateTitles' in movie: alternativeTitles = str([item['title'] for item in movie['alternateTitles']]) - if 'imdbId' in movie: - imdbId = movie['imdbId'] - else: - imdbId = None + if 'imdbId' in movie: imdbId = movie['imdbId'] + else: imdbId = None try: format, resolution = movie['movieFile']['quality']['quality']['name'].split('-') @@ -174,43 +167,55 @@ def update_movies(): # Add movies in radarr to current movies list current_movies_radarr.append(str(movie['tmdbId'])) - - info = { - 'radarrId': int(movie['id']), - 'title': movie['title'], - 'path': movie['path'] + separator + movie['movieFile']['relativePath'], - 'tmdbId': str(movie['tmdbId']), - 'poster': poster, - 'fanart': fanart, - 'audio_language': str(audio_language), - 'sceneName': sceneName, - 'monitored': str(bool(movie['monitored'])), - 'year': str(movie['year']), - 'sortTitle': movie['sortTitle'], - 'alternativeTitles': alternativeTitles, - 'format': format, - 'resolution': resolution, - 'video_codec': videoCodec, - 'audio_codec': audioCodec, - 'overview': overview, - 'imdbId': imdbId, - 'movie_file_id': int(movie['movieFile']['id']), - 'tags': str(tags), - 'file_size': fileSize, - } - + if str(movie['tmdbId']) in current_movies_db_list: - if not cache_is_valid(info['path'], info['file_size'], 'movie', info['radarrId']): - logging.debug('Path and/or Size is not the same. Invalidating ffprobe cache data for: [%s:%s, %s].', - 'movie', info['radarrId'], info['path']) - info.update({'file_ffprobe': None}) - - movies_to_update.append(info) + movies_to_update.append({'radarrId': int(movie["id"]), + 'title': movie["title"], + 'path': movie["path"] + separator + movie['movieFile']['relativePath'], + 'tmdbId': str(movie["tmdbId"]), + 'poster': poster, + 'fanart': fanart, + 'audio_language': str(audio_language), + 'sceneName': sceneName, + 'monitored': str(bool(movie['monitored'])), + 'year': str(movie['year']), + 'sortTitle': movie['sortTitle'], + 'alternativeTitles': alternativeTitles, + 'format': format, + 'resolution': resolution, + 'video_codec': videoCodec, + 'audio_codec': audioCodec, + 'overview': overview, + 'imdbId': imdbId, + 'movie_file_id': int(movie['movieFile']['id']), + 'tags': str(tags)}) else: - info.update({'file_ffprobe': None, 'profileId': movie_default_profile}) - movies_to_add.append(info) + movies_to_add.append({'radarrId': int(movie["id"]), + 'title': movie["title"], + 'path': movie["path"] + separator + movie['movieFile']['relativePath'], + 'tmdbId': str(movie["tmdbId"]), + 'subtitles': '[]', + 'overview': overview, + 'poster': poster, + 'fanart': fanart, + 'audio_language': str(audio_language), + 'sceneName': sceneName, + 'monitored': str(bool(movie['monitored'])), + 'sortTitle': movie['sortTitle'], + 'year': str(movie['year']), + 'alternativeTitles': alternativeTitles, + 'format': format, + 'resolution': resolution, + 'video_codec': videoCodec, + 'audio_codec': audioCodec, + 'imdbId': imdbId, + 'movie_file_id': int(movie['movieFile']['id']), + 'tags': str(tags), + 'profileId': movie_default_profile}) else: - logging.error('BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + movie['movieFile']['relativePath']) + logging.error( + 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + + movie['movieFile']['relativePath']) # Remove old movies from DB removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr)) @@ -256,8 +261,7 @@ def update_movies(): # Store subtitles for added or modified movies for i, altered_movie in enumerate(altered_movies, 1): - store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1]), - 'movie', altered_movie[2]) + store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1])) logging.debug('BAZARR All movies synced from Radarr into database.') @@ -351,7 +355,7 @@ def RadarrFormatVideoCodec(videoFormat, videoCodecID, videoCodecLibrary): if videoCodecLibrary and videoCodecID and videoFormat == "MPEG-4 Visual": if videoCodecID.endswith("XVID") or videoCodecLibrary.startswith("XviD"): return "XviD" if videoCodecID.endswith("DIV3") or videoCodecID.endswith("DIVX") or videoCodecID.endswith( - "DX50") or videoCodecLibrary.startswith("DivX"): return "DivX" + "DX50") or videoCodecLibrary.startswith("DivX"): return "DivX" if videoFormat == "VC-1": return "VC1" if videoFormat == "WMV2": return "WMV" diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 6579e07e2..57e67e05e 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -248,7 +248,7 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro action = "downloaded" percent_score = round(subtitle.score * 100 / max_score, 2) message = downloaded_language + modifier_string + " subtitles " + action + " from " + \ - downloaded_provider + " with a score of " + str(percent_score) + "%." + downloaded_provider + " with a score of " + str(percent_score) + "%." if media_type == 'series': episode_metadata = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM " @@ -668,7 +668,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type sub = Subtitle( lang_obj, - mods=get_array_from(settings.general.subzero_mods) + mods = get_array_from(settings.general.subzero_mods) ) sub.content = subtitle.read() @@ -723,7 +723,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type sync_subtitles(video_path=path, srt_path=subtitle_path, srt_lang=uploaded_language_code2, media_type=media_type, percent_score=100, radarr_id=movie_metadata['radarrId']) - if use_postprocessing: + if use_postprocessing : command = pp_replace(postprocessing_cmd, path, subtitle_path, uploaded_language, uploaded_language_code2, uploaded_language_code3, audio_language, audio_language_code2, audio_language_code3, forced, 100, "1", "manual", series_id, episode_id) @@ -791,8 +791,7 @@ def series_download_subtitles(no): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles(episode['path'], path_mappings.path_replace(episode['path']), - 'episode', episode['sonarrEpisodeId']) + store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) history_log(1, no, episode['sonarrEpisodeId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications(no, episode['sonarrEpisodeId'], message) @@ -849,8 +848,7 @@ def episode_download_subtitles(no): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles(episode['path'], path_mappings.path_replace(episode['path']), - 'episode', episode['sonarrEpisodeId']) + store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) history_log(1, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message) @@ -910,8 +908,7 @@ def movies_download_subtitles(no): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']), - 'movie', movie['radarrId']) + store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) history_log_movie(1, no, message, path, language_code, provider, score, subs_id, subs_path) send_notifications_movie(no, message) else: @@ -981,8 +978,7 @@ def wanted_download_subtitles(path, l, count_episodes): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles(episode['path'], path_mappings.path_replace(episode['path']), - 'episode', episode['sonarrEpisodeId']) + store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) history_log(1, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message) @@ -1050,8 +1046,7 @@ def wanted_download_subtitles_movie(path, l, count_movies): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']), - 'movie', movie['radarrId']) + store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) history_log_movie(1, movie['radarrId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications_movie(movie['radarrId'], message) @@ -1245,8 +1240,8 @@ def upgrade_subtitles(): "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", + "score is not null" + get_exclusion_clause('series') + " GROUP BY " + "table_history.video_path, table_history.language", (minimum_timestamp,)) upgradable_episodes_not_perfect = [] for upgradable_episode in upgradable_episodes: @@ -1276,8 +1271,8 @@ def upgrade_subtitles(): "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", + "is not null" + get_exclusion_clause('movie') + " GROUP BY " + "table_history_movie.video_path, table_history_movie.language", (minimum_timestamp,)) upgradable_movies_not_perfect = [] for upgradable_movie in upgradable_movies: @@ -1352,8 +1347,7 @@ def upgrade_subtitles(): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles(episode['video_path'], path_mappings.path_replace(episode['video_path']), - 'episode', episode['sonarrEpisodeId']) + store_subtitles(episode['video_path'], path_mappings.path_replace(episode['video_path'])) history_log(3, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message) @@ -1412,8 +1406,8 @@ def upgrade_subtitles(): score = result[4] subs_id = result[6] subs_path = result[7] - store_subtitles_movie(movie['video_path'], path_mappings.path_replace_movie(movie['video_path']), - 'movie', movie['radarrId']) + store_subtitles_movie(movie['video_path'], + path_mappings.path_replace_movie(movie['video_path'])) history_log_movie(3, movie['radarrId'], message, path, language_code, provider, score, subs_id, subs_path) send_notifications_movie(movie['radarrId'], message) diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index eb0e7bf3f..ff0793173 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -24,14 +24,14 @@ global hi_regex hi_regex = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](? 1 * 1024 * 1024: + if os.path.getsize(subtitle_path) > 1*1024*1024: logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " + subtitle_path) continue @@ -548,10 +547,10 @@ def guess_external_subtitles(dest_folder, subtitles): try: text = text.decode('utf-8') detected_language = guess_language(text) - # add simplified and traditional chinese detection + #add simplified and traditional chinese detection if detected_language == 'zh': traditional_chinese_fuzzy = [u"繁", u"雙語"] - traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht", ".zh-hant", ".zhhant", ".zh_hant", ".hant", ".big5", ".traditional"] + traditional_chinese = [".cht", ".tc", ".zh-tw", ".zht",".zh-hant",".zhhant",".zh_hant",".hant", ".big5", ".traditional"] if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(traditional_chinese)) or (str(subtitle_path).lower())[:-5] in traditional_chinese_fuzzy: detected_language == 'zt' except UnicodeDecodeError: diff --git a/bazarr/utils.py b/bazarr/utils.py index bf93dc2e5..ede3cc2d1 100644 --- a/bazarr/utils.py +++ b/bazarr/utils.py @@ -291,7 +291,7 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat elif forced in [True, 'true', 'True']: language_log += ':forced' language_string += ' forced' - + result = language_string + " subtitles deleted from disk." if media_type == 'series': @@ -299,30 +299,26 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat os.remove(path_mappings.path_replace(subtitles_path)) except OSError: logging.exception('BAZARR cannot delete subtitles file: ' + subtitles_path) - store_subtitles(path_mappings.path_replace_reverse(media_path), media_path, - 'episode', sonarr_episode_id) + store_subtitles(path_mappings.path_replace_reverse(media_path), media_path) return False else: history_log(0, sonarr_series_id, sonarr_episode_id, result, language=language_log, video_path=path_mappings.path_replace_reverse(media_path), subtitles_path=path_mappings.path_replace_reverse(subtitles_path)) - store_subtitles(path_mappings.path_replace_reverse(media_path), media_path, - 'episode', sonarr_episode_id) + store_subtitles(path_mappings.path_replace_reverse(media_path), media_path) notify_sonarr(sonarr_series_id) else: try: os.remove(path_mappings.path_replace_movie(subtitles_path)) except OSError: logging.exception('BAZARR cannot delete subtitles file: ' + subtitles_path) - store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path, - 'movie', radarr_id) + store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path) return False else: history_log_movie(0, radarr_id, result, language=language_log, video_path=path_mappings.path_replace_reverse_movie(media_path), subtitles_path=path_mappings.path_replace_reverse_movie(subtitles_path)) - store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path, - 'movie', radarr_id) + store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path) notify_radarr(radarr_id) return True @@ -403,66 +399,7 @@ def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi): return dest_srt_file - def check_credentials(user, pw): username = settings.auth.username password = settings.auth.password - return hashlib.md5(pw.encode('utf-8')).hexdigest() == password and user == username - - -def cache_get_ffprobe(path, record_type=None, record_id=None): - record = { - 'id': record_id, - 'type': record_type, - 'ffprobe': None - } - - if record_type == 'episode': - item = database.execute("SELECT sonarrEpisodeId, file_ffprobe FROM table_episodes WHERE sonarrEpisodeId = ? AND path = ?", - (record_id, path,), only_one=True) - if item: - record.update({'id': item['sonarrEpisodeId'], 'type': 'episode'}) - - if item['file_ffprobe'] is not None: - record.update({'ffprobe': json.loads(item['file_ffprobe'])}) - logging.debug('Returning cached results for: [%s:%s, %s]. (%s)', record['type'], record['id'], path, record['ffprobe']) - - return record - - if record_type == 'movie': - item = database.execute("SELECT radarrId, file_ffprobe FROM table_movies WHERE radarrId = ? AND path = ?", - (record_id, path,), only_one=True) - if item: - record.update({'id': item['radarrId'], 'type': 'movie'}) - - if item['file_ffprobe'] is not None: - record.update({'ffprobe': json.loads(item['file_ffprobe'])}) - logging.debug('Returning cached results for: [%s:%s, %s]. (%s)', record['type'], record['id'], path, record['ffprobe']) - - return record - - -def cache_save_ffprobe(path, record_type, record_id, ffprobe): - if record_type == 'movie': - database.execute("UPDATE table_movies SET file_ffprobe = ? WHERE path = ? AND radarrId = ?", - (json.dumps(ffprobe), path, record_id)) - - if record_type == 'episode': - database.execute("UPDATE table_episodes SET file_ffprobe = ? WHERE path = ? AND sonarrEpisodeId = ?", - (json.dumps(ffprobe), path, record_id)) - - logging.debug('Saving ffprobe records [%s:%s, %s]. (%s)', record_type, record_id, path, ffprobe) - - -def cache_is_valid(path, file_size, record_type, record_id): - if record_type == 'movie': - item = database.execute("SELECT path, file_size FROM table_movies WHERE radarrId = ?", - (record_id,), only_one=True) - else: - item = database.execute("SELECT path, file_size FROM table_episodes WHERE sonarrEpisodeId = ?", - (record_id,), only_one=True) - - if item: - return str(item['path']) == str(path) and int(item['file_size']) == int(file_size) - - return False + return hashlib.md5(pw.encode('utf-8')).hexdigest() == password and user == username \ No newline at end of file