Add dogpile.cache for ffprobe results to prevent repetitive disk IO.

pull/1396/head
morpheus65535 4 years ago
parent 81e6716d01
commit 54586fa30f

@ -108,6 +108,7 @@ def db_upgrade():
['table_episodes', 'audio_codec', 'text'], ['table_episodes', 'audio_codec', 'text'],
['table_episodes', 'episode_file_id', 'integer'], ['table_episodes', 'episode_file_id', 'integer'],
['table_episodes', 'audio_language', 'text'], ['table_episodes', 'audio_language', 'text'],
['table_episodes', 'file_size', 'integer', '0'],
['table_movies', 'sortTitle', 'text'], ['table_movies', 'sortTitle', 'text'],
['table_movies', 'year', 'text'], ['table_movies', 'year', 'text'],
['table_movies', 'alternativeTitles', 'text'], ['table_movies', 'alternativeTitles', 'text'],
@ -120,6 +121,7 @@ def db_upgrade():
['table_movies', 'movie_file_id', 'integer'], ['table_movies', 'movie_file_id', 'integer'],
['table_movies', 'tags', 'text', '[]'], ['table_movies', 'tags', 'text', '[]'],
['table_movies', 'profileId', 'integer'], ['table_movies', 'profileId', 'integer'],
['table_movies', 'file_size', 'integer', '0'],
['table_history', 'video_path', 'text'], ['table_history', 'video_path', 'text'],
['table_history', 'language', 'text'], ['table_history', 'language', 'text'],
['table_history', 'provider', 'text'], ['table_history', 'provider', 'text'],

@ -4,14 +4,20 @@ import enzyme
from enzyme.exceptions import MalformedMKVError from enzyme.exceptions import MalformedMKVError
import logging import logging
import os import os
import datetime
from knowit import api from knowit import api
from subliminal.cache import region
FFPROBE_CACHE_EXPIRATION_TIME = datetime.timedelta(weeks=2).total_seconds()
class EmbeddedSubsReader: class EmbeddedSubsReader:
def __init__(self): def __init__(self):
self.ffprobe = None self.ffprobe = None
def list_languages(self, file): @region.cache_on_arguments(expiration_time=FFPROBE_CACHE_EXPIRATION_TIME)
# file_size, episode_file_id and movie_file_id are used for cache identification. DO NOT REMOVE!
def list_languages(self, file, file_size, episode_file_id=None, movie_file_id=None):
from utils import get_binary from utils import get_binary
self.ffprobe = get_binary("ffprobe") self.ffprobe = get_binary("ffprobe")

@ -117,7 +117,8 @@ def sync_episodes():
'video_codec': videoCodec, 'video_codec': videoCodec,
'audio_codec': audioCodec, 'audio_codec': audioCodec,
'episode_file_id': episode['episodeFile']['id'], 'episode_file_id': episode['episodeFile']['id'],
'audio_language': str(audio_language)}) 'audio_language': str(audio_language),
'file_size': episode['episodeFile']['size']})
else: else:
episodes_to_add.append({'sonarrSeriesId': episode['seriesId'], episodes_to_add.append({'sonarrSeriesId': episode['seriesId'],
'sonarrEpisodeId': episode['id'], 'sonarrEpisodeId': episode['id'],
@ -132,7 +133,8 @@ def sync_episodes():
'video_codec': videoCodec, 'video_codec': videoCodec,
'audio_codec': audioCodec, 'audio_codec': audioCodec,
'episode_file_id': episode['episodeFile']['id'], 'episode_file_id': episode['episodeFile']['id'],
'audio_language': str(audio_language)}) 'audio_language': str(audio_language),
'file_size': episode['episodeFile']['size']})
# Remove old episodes from DB # Remove old episodes from DB
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
@ -148,7 +150,7 @@ def sync_episodes():
episode_in_db_list = [] episode_in_db_list = []
episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, " episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, "
"scene_name, monitored, format, resolution, video_codec, audio_codec, " "scene_name, monitored, format, resolution, video_codec, audio_codec, "
"episode_file_id, audio_language FROM table_episodes") "episode_file_id, audio_language, file_size FROM table_episodes")
for item in episodes_in_db: for item in episodes_in_db:
episode_in_db_list.append(item) episode_in_db_list.append(item)

@ -188,7 +188,8 @@ def update_movies():
'overview': overview, 'overview': overview,
'imdbId': imdbId, 'imdbId': imdbId,
'movie_file_id': int(movie['movieFile']['id']), 'movie_file_id': int(movie['movieFile']['id']),
'tags': str(tags)}) 'tags': str(tags),
'file_size': movie['movieFile']['size']})
else: else:
movies_to_add.append({'radarrId': int(movie["id"]), movies_to_add.append({'radarrId': int(movie["id"]),
'title': movie["title"], 'title': movie["title"],
@ -211,7 +212,8 @@ def update_movies():
'imdbId': imdbId, 'imdbId': imdbId,
'movie_file_id': int(movie['movieFile']['id']), 'movie_file_id': int(movie['movieFile']['id']),
'tags': str(tags), 'tags': str(tags),
'profileId': movie_default_profile}) 'profileId': movie_default_profile,
'file_size': movie['movieFile']['size']})
else: else:
logging.error( logging.error(
'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator +
@ -228,7 +230,7 @@ def update_movies():
movies_in_db = database.execute("SELECT radarrId, title, path, tmdbId, overview, poster, fanart, " movies_in_db = database.execute("SELECT radarrId, title, path, tmdbId, overview, poster, fanart, "
"audio_language, sceneName, monitored, sortTitle, year, " "audio_language, sceneName, monitored, sortTitle, year, "
"alternativeTitles, format, resolution, video_codec, audio_codec, imdbId," "alternativeTitles, format, resolution, video_codec, audio_codec, imdbId,"
"movie_file_id, tags FROM table_movies") "movie_file_id, tags, file_size FROM table_movies")
for item in movies_in_db: for item in movies_in_db:
movies_in_db_list.append(item) movies_in_db_list.append(item)

@ -5,6 +5,7 @@ import os
import logging import logging
import ast import ast
import re import re
import subliminal
from guess_language import guess_language from guess_language import guess_language
from subliminal_patch import core, search_external_subtitles from subliminal_patch import core, search_external_subtitles
from subzero.language import Language from subzero.language import Language
@ -31,7 +32,13 @@ def store_subtitles(original_path, reversed_path):
if settings.general.getboolean('use_embedded_subs'): if settings.general.getboolean('use_embedded_subs'):
logging.debug("BAZARR is trying to index embedded subtitles.") logging.debug("BAZARR is trying to index embedded subtitles.")
try: try:
subtitle_languages = embedded_subs_reader.list_languages(reversed_path) item = database.execute('SELECT file_size, episode_file_id FROM table_episodes '
'WHERE path = ?', (original_path,), only_one=True)
subtitle_languages = embedded_subs_reader.list_languages(reversed_path,
file_size=item['file_size'],
episode_file_id=item['episode_file_id'])
subliminal.region.backend.sync()
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 \
@ -145,7 +152,13 @@ def store_subtitles_movie(original_path, reversed_path):
if settings.general.getboolean('use_embedded_subs'): if settings.general.getboolean('use_embedded_subs'):
logging.debug("BAZARR is trying to index embedded subtitles.") logging.debug("BAZARR is trying to index embedded subtitles.")
try: try:
subtitle_languages = embedded_subs_reader.list_languages(reversed_path) item = database.execute('SELECT file_size, movie_file_id FROM table_movies '
'WHERE path = ?', (original_path,), only_one=True)
subtitle_languages = embedded_subs_reader.list_languages(reversed_path,
file_size=item['file_size'],
movie_file_id=item['movie_file_id'])
subliminal.region.backend.sync()
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 \

Loading…
Cancel
Save