4
1
Fork 1

Add config initializer

This commit is contained in:
trueold89 2024-05-04 04:09:42 +03:00
parent aeafc2db41
commit d4a46ca5ad
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
1 changed files with 33 additions and 0 deletions

33
Config.py Normal file
View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from json import load as jsonLoad
from TYPES import DirParserTypes, LogTypes
CFG_PATH = "config.json"
def loadCFG(config_path: str) -> dict:
with open(config_path, "r") as cfg:
return jsonLoad(cfg)
def loadParser(options: dict) -> tuple:
dirParser = None
parser_value = options["Main"]["DirParser"]
for av_parser in DirParserTypes:
if parser_value == av_parser.value:
dirParser = av_parser
if dirParser is None:
raise Exception(f"Directory parser '{parser_value}' not found")
else:
match dirParser:
case DirParserTypes.Jellyfin:
JellyfinConfig = {}
for i in options["JellyfinConfig"].keys():
JellyfinConfig[i] = options["JellyfinConfig"][i]
return dirParser, JellyfinConfig
configuration = loadCFG(CFG_PATH)
dirParser, JellyfinConfig = loadParser(configuration)
DBPath = configuration["Main"]["DBPath"]