From 55bf67950f59c6b5647dfc24602e96c6afa04b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 13 Dec 2019 07:00:38 -0500 Subject: [PATCH] Created path mapping dictionaries for faster conversion than reading config.ini every time. --- bazarr/helper.py | 16 ++++++++++++---- bazarr/init.py | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bazarr/helper.py b/bazarr/helper.py index 55e765fd3..feef91067 100644 --- a/bazarr/helper.py +++ b/bazarr/helper.py @@ -11,11 +11,19 @@ from bs4 import UnicodeDammit from config import settings +def create_path_mapping_dict(): + global path_mapping_series + path_mapping_series = ast.literal_eval(settings.general.path_mappings) + + global path_mapping_movies + path_mapping_movies = ast.literal_eval(settings.general.path_mappings_movie) + + def path_replace(path): if path is None: return None - for path_mapping in ast.literal_eval(settings.general.path_mappings): + for path_mapping in path_mapping_series: if path_mapping[0] == path_mapping[1]: continue if '' in path_mapping: @@ -34,7 +42,7 @@ def path_replace_reverse(path): if path is None: return None - for path_mapping in ast.literal_eval(settings.general.path_mappings): + for path_mapping in path_mapping_series: if path_mapping[0] == path_mapping[1]: continue if '' in path_mapping: @@ -53,7 +61,7 @@ def path_replace_movie(path): if path is None: return None - for path_mapping in ast.literal_eval(settings.general.path_mappings_movie): + for path_mapping in path_mapping_movies: if path_mapping[0] == path_mapping[1]: continue if '' in path_mapping: @@ -72,7 +80,7 @@ def path_replace_reverse_movie(path): if path is None: return None - for path_mapping in ast.literal_eval(settings.general.path_mappings_movie): + for path_mapping in path_mapping_movies: if path_mapping[0] == path_mapping[1]: continue if '' in path_mapping: diff --git a/bazarr/init.py b/bazarr/init.py index e913de9e4..81968eb98 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -9,6 +9,7 @@ from cork import Cork from config import settings from get_args import args from logger import configure_logging +from helper import create_path_mapping_dict from dogpile.cache.region import register_backend as register_cache_backend import subliminal @@ -130,3 +131,4 @@ def init_binaries(): init_binaries() +create_path_mapping_dict()