Fixed scan disk function to not use cached ffprobe result and force a refresh of the cache. #1434

pull/1439/head
morpheus65535 3 years ago
parent a39a9e8bd5
commit a3d0e1d192

@ -24,8 +24,8 @@ def _handle_alpha3(detected_language: dict):
return alpha3 return alpha3
def embedded_subs_reader(file, file_size, episode_file_id=None, movie_file_id=None): def embedded_subs_reader(file, file_size, episode_file_id=None, movie_file_id=None, use_cache=True):
data = parse_video_metadata(file, file_size, episode_file_id, movie_file_id) data = parse_video_metadata(file, file_size, episode_file_id, movie_file_id, use_cache=use_cache)
subtitles_list = [] subtitles_list = []
if data["ffprobe"] and "subtitle" in data["ffprobe"]: if data["ffprobe"] and "subtitle" in data["ffprobe"]:
@ -64,7 +64,7 @@ def embedded_subs_reader(file, file_size, episode_file_id=None, movie_file_id=No
return subtitles_list return subtitles_list
def parse_video_metadata(file, file_size, episode_file_id=None, movie_file_id=None): def parse_video_metadata(file, file_size, episode_file_id=None, movie_file_id=None, use_cache=True):
# Define default data keys value # Define default data keys value
data = { data = {
"ffprobe": {}, "ffprobe": {},
@ -73,32 +73,33 @@ def parse_video_metadata(file, file_size, episode_file_id=None, movie_file_id=No
"file_size": file_size, "file_size": file_size,
} }
# Get the actual cache value form database if use_cache:
if episode_file_id: # Get the actual cache value form database
cache_key = TableEpisodes.select(TableEpisodes.ffprobe_cache)\ if episode_file_id:
.where((TableEpisodes.episode_file_id == episode_file_id) and cache_key = TableEpisodes.select(TableEpisodes.ffprobe_cache)\
(TableEpisodes.file_size == file_size))\ .where((TableEpisodes.episode_file_id == episode_file_id) and
.dicts()\ (TableEpisodes.file_size == file_size))\
.get() .dicts()\
elif movie_file_id: .get()
cache_key = TableMovies.select(TableMovies.ffprobe_cache)\ elif movie_file_id:
.where(TableMovies.movie_file_id == movie_file_id and cache_key = TableMovies.select(TableMovies.ffprobe_cache)\
TableMovies.file_size == file_size)\ .where(TableMovies.movie_file_id == movie_file_id and
.dicts()\ TableMovies.file_size == file_size)\
.get() .dicts()\
else: .get()
cache_key = None else:
cache_key = None
# check if we have a value for that cache key
try: # check if we have a value for that cache key
# Unpickle ffprobe cache try:
cached_value = pickle.loads(cache_key['ffprobe_cache']) # Unpickle ffprobe cache
except: cached_value = pickle.loads(cache_key['ffprobe_cache'])
pass except:
else: pass
# Check if file size and file id matches and if so, we return the cached value else:
if cached_value['file_size'] == file_size and cached_value['file_id'] in [episode_file_id, movie_file_id]: # Check if file size and file id matches and if so, we return the cached value
return cached_value if cached_value['file_size'] == file_size and cached_value['file_id'] in [episode_file_id, movie_file_id]:
return cached_value
# if not, we retrieve the metadata from the file # if not, we retrieve the metadata from the file
from utils import get_binary from utils import get_binary

@ -26,7 +26,7 @@ global hi_regex
hi_regex = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?<!{\\an\d})') hi_regex = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?<!{\\an\d})')
def store_subtitles(original_path, reversed_path): def store_subtitles(original_path, reversed_path, use_cache=True):
logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path) logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path)
actual_subtitles = [] actual_subtitles = []
if os.path.exists(reversed_path): if os.path.exists(reversed_path):
@ -39,7 +39,8 @@ def store_subtitles(original_path, reversed_path):
.get() .get()
subtitle_languages = embedded_subs_reader(reversed_path, subtitle_languages = embedded_subs_reader(reversed_path,
file_size=item['file_size'], file_size=item['file_size'],
episode_file_id=item['episode_file_id']) episode_file_id=item['episode_file_id'],
use_cache=use_cache)
for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages: for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages:
try: try:
if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \ if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \
@ -121,7 +122,7 @@ def store_subtitles(original_path, reversed_path):
return actual_subtitles return actual_subtitles
def store_subtitles_movie(original_path, reversed_path): def store_subtitles_movie(original_path, reversed_path, use_cache=True):
logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path) logging.debug('BAZARR started subtitles indexing for this file: ' + reversed_path)
actual_subtitles = [] actual_subtitles = []
if os.path.exists(reversed_path): if os.path.exists(reversed_path):
@ -134,7 +135,8 @@ def store_subtitles_movie(original_path, reversed_path):
.get() .get()
subtitle_languages = embedded_subs_reader(reversed_path, subtitle_languages = embedded_subs_reader(reversed_path,
file_size=item['file_size'], file_size=item['file_size'],
movie_file_id=item['movie_file_id']) movie_file_id=item['movie_file_id'],
use_cache=use_cache)
for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages: for subtitle_language, subtitle_forced, subtitle_hi, subtitle_codec in subtitle_languages:
try: try:
if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \ if (settings.general.getboolean("ignore_pgs_subs") and subtitle_codec.lower() == "pgs") or \
@ -499,7 +501,7 @@ def series_scan_subtitles(no):
for episode in episodes: for episode in episodes:
sleep() sleep()
store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) store_subtitles(episode['path'], path_mappings.path_replace(episode['path']), use_cache=False)
def movies_scan_subtitles(no): def movies_scan_subtitles(no):
@ -510,7 +512,7 @@ def movies_scan_subtitles(no):
for movie in movies: for movie in movies:
sleep() sleep()
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']), use_cache=False)
def get_external_subtitles_path(file, subtitle): def get_external_subtitles_path(file, subtitle):

Loading…
Cancel
Save