From fccf9c865a51d247381859d0ac17ac13046b91db Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 21 Dec 2023 06:29:43 +0100 Subject: [PATCH] Fixes --- app/src/config.py | 10 +++++++++- app/src/connect.py | 8 +++++++- app/src/series.py | 9 ++------- app/src/static_types.py | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/config.py b/app/src/config.py index 58b428a..1fbaffd 100644 --- a/app/src/config.py +++ b/app/src/config.py @@ -29,6 +29,12 @@ def get_config_file() -> ConfigType | Literal[False]: return False +def get_variable_or_default(variable: str, default: str) -> str: + if not variable or len(variable) < 1: + return default + return variable + + def get_config_env() -> ConfigType | Literal[False]: """read config from environment""" if "TA_URL" in os.environ: @@ -38,7 +44,9 @@ def get_config_env() -> ConfigType | Literal[False]: "ta_token": os.environ["TA_TOKEN"], "jf_url": os.environ["JF_URL"], "jf_token": os.environ["JF_TOKEN"], - "jf_folder": os.environ['JF_FOLDER'] + "jf_folder": get_variable_or_default( + os.environ["JF_FOLDER"], "youtube" + ), } return config_content diff --git a/app/src/connect.py b/app/src/connect.py index 4478f5e..8d18541 100644 --- a/app/src/connect.py +++ b/app/src/connect.py @@ -9,7 +9,13 @@ from src.static_types import ConfigType, TAChannel, TAVideo CONFIG: ConfigType = get_config() TIMEOUT = 60 -EXPECTED_ENV = {"ta_url", "ta_token", "jf_url", "jf_token", "ta_video_path"} # js_folder is optional +EXPECTED_ENV = { + "ta_url", + "ta_token", + "jf_url", + "jf_token", + "ta_video_path", +} # jf_folder is optional class Jellyfin: diff --git a/app/src/series.py b/app/src/series.py index 82f55e8..ad884dd 100644 --- a/app/src/series.py +++ b/app/src/series.py @@ -22,15 +22,10 @@ class Library: """get collection id for youtube folder""" path: str = "Items?Recursive=true&includeItemTypes=Folder" folders: dict = Jellyfin().get(path) - folder_name: str | None = get_config()["jf_folder"] - - if not folder_name or len(folder_name) < 1: - folder_name = "youtube" - else: - folder_name = folder_name.lower() + folder_name: str = get_config()["jf_folder"] for folder in folders["Items"]: - if folder.get("Name").lower() == folder_name: + if folder.get("Name").lower() == folder_name.lower(): return folder.get("Id") raise ValueError("youtube folder not found") diff --git a/app/src/static_types.py b/app/src/static_types.py index 1c2d62a..ecf7fee 100644 --- a/app/src/static_types.py +++ b/app/src/static_types.py @@ -11,7 +11,7 @@ class ConfigType(TypedDict): ta_token: str jf_url: str jf_token: str - jf_folder: str | None + jf_folder: str class TAChannel(TypedDict):