mirror of
https://github.com/tubearchivist/jellyfin.git
synced 2025-01-15 13:20:13 +00:00
split get_config logic
This commit is contained in:
parent
3a13b6ab17
commit
3281532856
@ -2,27 +2,43 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from src.static_types import ConfigType
|
from src.static_types import ConfigType
|
||||||
|
|
||||||
|
|
||||||
def get_config() -> ConfigType:
|
def get_config() -> ConfigType:
|
||||||
"""get connection config"""
|
"""get connection config"""
|
||||||
|
config_content: ConfigType | Literal[False] = (
|
||||||
|
get_config_file() or get_config_env()
|
||||||
|
)
|
||||||
|
if not config_content:
|
||||||
|
raise ValueError("No config.json or environment variable found")
|
||||||
|
|
||||||
|
return config_content
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_file() -> ConfigType | Literal[False]:
|
||||||
|
"""read config file if available"""
|
||||||
if os.path.exists("config.json"):
|
if os.path.exists("config.json"):
|
||||||
print("config.json file found, skipping environment variables")
|
|
||||||
with open("config.json", "r", encoding="utf-8") as f:
|
with open("config.json", "r", encoding="utf-8") as f:
|
||||||
config_content: ConfigType = json.loads(f.read())
|
config_content: ConfigType = json.loads(f.read())
|
||||||
|
|
||||||
return config_content
|
return config_content
|
||||||
elif "TA_URL" in os.environ:
|
|
||||||
print("Environment variables found, continuing")
|
return False
|
||||||
data = {}
|
|
||||||
data['ta_video_path'] = os.getenv('TA_VIDEO_PATH', '/youtube')
|
|
||||||
data['ta_url'] = os.getenv('TA_URL')
|
def get_config_env() -> ConfigType | Literal[False]:
|
||||||
data['ta_token'] = os.getenv('TA_TOKEN')
|
"""read config from environment"""
|
||||||
data['jf_url'] = os.getenv('JF_URL')
|
if "TA_URL" in os.environ:
|
||||||
data['jf_token'] = os.getenv('JF_TOKEN')
|
config_content: ConfigType = {
|
||||||
config_content: ConfigType = json.loads(json.dumps(data))
|
"ta_video_path": "/youtube",
|
||||||
|
"ta_url": os.environ["TA_URL"],
|
||||||
|
"ta_token": os.environ["TA_TOKEN"],
|
||||||
|
"jf_url": os.environ["JF_URL"],
|
||||||
|
"jf_token": os.environ["JF_TOKEN"],
|
||||||
|
}
|
||||||
return config_content
|
return config_content
|
||||||
else:
|
|
||||||
raise ValueError("No config.json or environment variable found, exiting")
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user