You've already forked Douyin_Web_Live
架构修改,删除Edge浏览器支持,配置可以自己保存
This commit is contained in:
@ -0,0 +1 @@
|
||||
from .manager import ConfigManager
|
@ -1,9 +0,0 @@
|
||||
from pathlib import Path
|
||||
from ruamel import yaml
|
||||
|
||||
def config():
|
||||
settings_file = str(Path(__file__).parent.absolute()) + '/settings.yml'
|
||||
|
||||
with open(settings_file, 'r') as f:
|
||||
return yaml.load(f, Loader=yaml.UnsafeLoader)
|
||||
|
77
config/manager.py
Normal file
77
config/manager.py
Normal file
@ -0,0 +1,77 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
from common import Singleton
|
||||
|
||||
_log = logging.getLogger("ConfigManager")
|
||||
|
||||
|
||||
class ConfigManager(metaclass=Singleton):
|
||||
"""默认配置"""
|
||||
_default_config = {
|
||||
"mitm": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
},
|
||||
"webdriver": {
|
||||
"headless": False,
|
||||
"use": "chrome",
|
||||
"chrome": {
|
||||
"bin": "chromedriver",
|
||||
"no_sandbox": True
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"use": [],
|
||||
"xml": {
|
||||
"save_path": "./",
|
||||
"file_pattern": "{room_id}_{ts}.xml"
|
||||
},
|
||||
"debug": {
|
||||
"save_path": "./debug",
|
||||
"known": False
|
||||
},
|
||||
},
|
||||
"douyin": {
|
||||
"rooms": [],
|
||||
"users": [],
|
||||
},
|
||||
}
|
||||
"""配置文件路径"""
|
||||
_config_file: "os.PathLike[str] || str"
|
||||
"""当前实例中,配置文件内容"""
|
||||
_current_config: "dict" = {}
|
||||
|
||||
def __init__(self, config_file="settings.yml"):
|
||||
_log.debug("配置文件路径:%s", config_file)
|
||||
self._config_file = config_file
|
||||
if not os.path.exists(config_file):
|
||||
_log.warning("配置文件不存在,写入初始化配置")
|
||||
self._current_config = self._default_config
|
||||
self._write_config()
|
||||
else:
|
||||
self._read_config()
|
||||
|
||||
def _read_config(self):
|
||||
_log.debug("读取文件%s的配置内容", self._config_file)
|
||||
with open(self._config_file, "r", encoding="UTF8") as _f:
|
||||
yaml = YAML(typ="unsafe", pure=True)
|
||||
self._current_config = yaml.load(_f)
|
||||
_log.debug("读取文件%s的配置内容完毕", self._config_file)
|
||||
|
||||
def _write_config(self):
|
||||
_log.debug("向文件%s写入配置", self._config_file)
|
||||
with open(self._config_file, "w", encoding="UTF8") as _f:
|
||||
_log.debug("配置内容:", self._current_config)
|
||||
yaml = YAML(typ="unsafe", pure=True)
|
||||
yaml.dump(self._current_config, _f)
|
||||
_log.debug("向文件%s写入配置完毕", self._config_file)
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
return self._current_config
|
||||
|
||||
def get(self, key: str, default: str = None):
|
||||
...
|
@ -1,35 +0,0 @@
|
||||
mitm:
|
||||
host: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
webdriver:
|
||||
headless: False
|
||||
use: edge
|
||||
edge:
|
||||
bin: msedgedriver.exe
|
||||
chrome:
|
||||
bin: chromedriver
|
||||
no_sandbox: True
|
||||
|
||||
output:
|
||||
use:
|
||||
- print
|
||||
- xml
|
||||
- debug
|
||||
xml:
|
||||
save_path: "./"
|
||||
file_pattern: "{room_id}_{ts}.xml"
|
||||
debug:
|
||||
save_path:
|
||||
error: "./error"
|
||||
unknown: "./debug"
|
||||
known: False
|
||||
|
||||
live:
|
||||
rooms:
|
||||
- ""
|
||||
users:
|
||||
- ""
|
||||
|
||||
api:
|
||||
userinfo: 'https://live.douyin.com/webcast/user/?aid=6383&target_uid='
|
Reference in New Issue
Block a user