This commit is contained in:
CommanderRedYT 2023-12-21 06:29:43 +01:00
parent a4b5081c7a
commit fccf9c865a
No known key found for this signature in database
GPG Key ID: 572F157519DC8A5E
4 changed files with 19 additions and 10 deletions

View File

@ -29,6 +29,12 @@ def get_config_file() -> ConfigType | Literal[False]:
return 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]: def get_config_env() -> ConfigType | Literal[False]:
"""read config from environment""" """read config from environment"""
if "TA_URL" in os.environ: if "TA_URL" in os.environ:
@ -38,7 +44,9 @@ def get_config_env() -> ConfigType | Literal[False]:
"ta_token": os.environ["TA_TOKEN"], "ta_token": os.environ["TA_TOKEN"],
"jf_url": os.environ["JF_URL"], "jf_url": os.environ["JF_URL"],
"jf_token": os.environ["JF_TOKEN"], "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 return config_content

View File

@ -9,7 +9,13 @@ from src.static_types import ConfigType, TAChannel, TAVideo
CONFIG: ConfigType = get_config() CONFIG: ConfigType = get_config()
TIMEOUT = 60 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: class Jellyfin:

View File

@ -22,15 +22,10 @@ class Library:
"""get collection id for youtube folder""" """get collection id for youtube folder"""
path: str = "Items?Recursive=true&includeItemTypes=Folder" path: str = "Items?Recursive=true&includeItemTypes=Folder"
folders: dict = Jellyfin().get(path) folders: dict = Jellyfin().get(path)
folder_name: str | None = get_config()["jf_folder"] folder_name: str = get_config()["jf_folder"]
if not folder_name or len(folder_name) < 1:
folder_name = "youtube"
else:
folder_name = folder_name.lower()
for folder in folders["Items"]: for folder in folders["Items"]:
if folder.get("Name").lower() == folder_name: if folder.get("Name").lower() == folder_name.lower():
return folder.get("Id") return folder.get("Id")
raise ValueError("youtube folder not found") raise ValueError("youtube folder not found")

View File

@ -11,7 +11,7 @@ class ConfigType(TypedDict):
ta_token: str ta_token: str
jf_url: str jf_url: str
jf_token: str jf_token: str
jf_folder: str | None jf_folder: str
class TAChannel(TypedDict): class TAChannel(TypedDict):