2022-10-29 23:55:22 +02:00
|
|
|
import json
|
2021-07-30 11:48:32 +02:00
|
|
|
import os
|
2022-10-29 23:55:22 +02:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from typing import Literal
|
2021-07-30 11:48:32 +02:00
|
|
|
|
|
|
|
|
2021-08-01 17:02:15 +02:00
|
|
|
@dataclass
|
|
|
|
class Configuration:
|
2022-10-29 23:55:22 +02:00
|
|
|
username: str
|
|
|
|
password: str
|
|
|
|
api_url: str = 'https://ytrssil.theedgeofrage.com'
|
|
|
|
max_res: Literal['480', '720', '1080', '1440', '2160'] = '1440'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mpv_options(self) -> list[str]:
|
|
|
|
return [
|
|
|
|
'--no-terminal',
|
|
|
|
f'--ytdl-format=bestvideo[height<=?{self.max_res}]+bestaudio/best',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def load_config() -> Configuration:
|
|
|
|
config_prefix: str
|
|
|
|
try:
|
|
|
|
config_prefix = os.environ['XDG_CONFIG_HOME']
|
|
|
|
except KeyError:
|
|
|
|
config_prefix = os.path.expanduser('~/.config')
|
2021-08-01 17:02:15 +02:00
|
|
|
|
2022-10-29 23:55:22 +02:00
|
|
|
config_path: str = os.path.join(config_prefix, 'ytrssil', 'config.json')
|
|
|
|
with open(config_path) as f:
|
|
|
|
config_data = json.load(f)
|
2021-08-01 17:02:15 +02:00
|
|
|
|
2022-10-29 23:55:22 +02:00
|
|
|
return Configuration(**config_data)
|