2024-05-03 19:57:20 +03:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
|
|
|
|
self.host = os.getenv('HOST') or '0.0.0.0'
|
|
|
|
self.port = int(os.getenv('PORT') or 4009)
|
2024-05-04 09:27:57 +03:00
|
|
|
|
|
|
|
# This directory will be searched for <site>.txt (e.g. yandex.txt)
|
|
|
|
# Cookies are in Netscape CSV format, see yt-dlp docs
|
2024-05-03 19:57:20 +03:00
|
|
|
self.cookies_dir = Path(os.getenv('COOKIES_DIR') or 'cookies')
|
|
|
|
|
2024-05-04 09:27:57 +03:00
|
|
|
self.tmpl = os.path.join(
|
2024-05-24 20:28:32 +03:00
|
|
|
# 1. `artists.0` instead of `artist`, because the latter can contain "feat. ..."
|
|
|
|
# 2. as for %(field)S, see https://git.dc09.ru/DarkCat09/musicdlp/issues/3#issuecomment-210
|
|
|
|
os.getenv('ALBUM_PATH_TMPL') or 'music/%(artists.0)S/%(album)S',
|
|
|
|
os.getenv('TRACK_FILE_TMPL') or '%(track)S.%(ext)s',
|
2024-05-04 09:27:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
# Proxy URL for yt_proxied downloader (can be used for geo-restricted content)
|
2024-05-28 08:09:59 +03:00
|
|
|
self.yt_proxy = os.getenv('YT_PROXY') or None
|
2024-05-04 09:27:57 +03:00
|
|
|
|
2024-05-28 10:10:50 +03:00
|
|
|
# Proxy for soundcloud
|
|
|
|
self.sc_proxy = os.getenv('SC_PROXY') or None
|
|
|
|
|
2024-05-09 17:05:39 +03:00
|
|
|
self.save_lyrics = _parse_bool(os.getenv('SAVE_LYRICS'), True)
|
|
|
|
self.save_cover = _parse_bool(os.getenv('SAVE_COVER'), True)
|
|
|
|
|
2024-05-03 19:57:20 +03:00
|
|
|
|
|
|
|
_config: Config | None = None
|
|
|
|
|
|
|
|
|
|
|
|
def get() -> Config:
|
|
|
|
global _config
|
|
|
|
if _config is None:
|
|
|
|
_config = Config()
|
|
|
|
return _config
|
2024-05-09 17:05:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
def _parse_bool(val: str | None, default: bool) -> bool:
|
|
|
|
if val is None:
|
|
|
|
return default
|
|
|
|
if val in {'false', 'off', 'no', '0'}:
|
|
|
|
return False
|
|
|
|
return bool(val)
|