config.py (1445B)
1 #!/usr/bin/python3 2 3 import datetime 4 from contextvars import ContextVar 5 6 import msgspec 7 8 9 class ChannelConfig(msgspec.Struct): 10 id: str 11 name: str | None = None 12 webdav_path: str | None = None 13 14 15 class TorrentConfig(msgspec.Struct): 16 trackers: list[list[str]] 17 comment: str | None = None 18 19 20 class QBittorrentConfig(msgspec.Struct): 21 host: str 22 username: str 23 password: str 24 start_paused: bool = True 25 26 # defaults to the directory containing the files 27 # override if acting on a remote 28 default_save_path: str | None = None 29 30 31 class WebDavConfig(msgspec.Struct): 32 base_url: str 33 username: str 34 password: str 35 36 37 class AutoUploadConfig(msgspec.Struct): 38 active: bool = False 39 40 41 class AppConfig(msgspec.Struct): 42 moombox_url: str 43 torrent: TorrentConfig 44 autoupload: AutoUploadConfig = msgspec.field(default_factory=AutoUploadConfig) 45 channels: list[ChannelConfig] = msgspec.field(name="channel", default_factory=list) 46 webdav: WebDavConfig | None = None 47 qbittorrent: QBittorrentConfig | None = None 48 max_visible_task_age: datetime.timedelta | None = None 49 50 def get_channel_config_by_id(self, channel_id: str | None) -> ChannelConfig | None: 51 if not channel_id: 52 return None 53 for channel in self.channels: 54 if channel.id == channel_id: 55 return channel 56 return None 57 58 59 config_ctx: ContextVar[AppConfig] = ContextVar("config")