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