-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
69 lines (56 loc) · 2.01 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pydantic import BaseModel
import os
from typing import Optional
from enum import IntEnum
class Config(BaseModel):
class LiveConfig(BaseModel):
class DownloadConfig(BaseModel):
class DownloadType(IntEnum):
DEFAULT = 1
CUSTOM = 2
download_type: DownloadType = DownloadType.DEFAULT
custom_downloader: Optional[str] = None
download_format: str = '%title-%Y年%m月%d日-%H点%M分场'
download: DownloadConfig = DownloadConfig()
class MonitorLiveRoom(BaseModel):
class Quality(IntEnum):
FLUENT = 80
STANDARD = 150
HIGH = 400
SUPER = 10000
class AutoUpload(BaseModel):
enabled: bool = False
title: str = '【直播录制】%title-%Y年%m月%d日-%H点%M分场'
desc: str = '直播录制'
source: str = 'https://live.bilibili.com/'
tags: list[str] = ['直播录制']
tid: int = 27
cover_path: str = 'AUTO'
short_id: int = -1
auto_download: bool = False
auto_download_path: Optional[str]
auto_download_quality: Quality = Quality.SUPER
auto_upload: AutoUpload = AutoUpload()
transcode: bool = False
mid: int = 0
SESSDATA: Optional[str]
bili_jct: Optional[str]
DedeUserID: Optional[str]
DedeUserID__ckMd5: Optional[str]
refresh_token: Optional[str]
live_config: LiveConfig = LiveConfig()
access_token: Optional[str]
monitor_live_rooms: list[MonitorLiveRoom] = [
MonitorLiveRoom(auto_download_path=None)
]
if not os.path.exists('config'):
os.mkdir('config')
def get_config() -> Config:
if not os.path.exists('config/config.json'):
save_config(Config())
return Config()
config = Config.parse_file('config/config.json')
return config
def save_config(config: Config):
with open('config/config.json', 'w') as f:
f.write(config.json(indent=4, ensure_ascii=False))