45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
import yaml
|
|
from utils.logger import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
ALERT_PUSH_URL = ""
|
|
HLS_ROOT_PATH = ""
|
|
|
|
HLS_SEGMENT_PATTERN = "segment_%09d.ts" # TS文件命名模式
|
|
|
|
# 视频剪辑配置
|
|
VIDEO_CLIP_OUTPUT_DIR = ""
|
|
VIDEO_CLIP_DURATION_SECONDS = 30
|
|
VIDEO_CLIP_RETENTION_SECONDS = 3600
|
|
VIDEO_CLIP_DEFAULT_SEGMENT_DURATION = 2
|
|
|
|
|
|
def init_config(config_path: str = "config.yaml"):
|
|
"""
|
|
从配置文件初始化全局配置
|
|
|
|
Args:
|
|
config_path: 配置文件路径,默认为 config.yaml
|
|
"""
|
|
global ALERT_PUSH_URL, HLS_ROOT_PATH
|
|
global VIDEO_CLIP_OUTPUT_DIR, VIDEO_CLIP_DURATION_SECONDS, VIDEO_CLIP_RETENTION_SECONDS, VIDEO_CLIP_DEFAULT_SEGMENT_DURATION
|
|
|
|
try:
|
|
with open(config_path, "r", encoding="utf-8") as f:
|
|
cfg = yaml.safe_load(f)
|
|
|
|
ALERT_PUSH_URL = cfg.get("alert_push_url", "")
|
|
# HLS_ROOT_PATH = cfg.get("hls_root_path", "")
|
|
|
|
# 视频剪辑配置
|
|
VIDEO_CLIP_OUTPUT_DIR = cfg.get("video_clip_output_dir", "")
|
|
VIDEO_CLIP_DURATION_SECONDS = cfg.get("video_clip_duration_seconds", 30)
|
|
VIDEO_CLIP_RETENTION_SECONDS = cfg.get("video_clip_retention_seconds", 3600)
|
|
VIDEO_CLIP_DEFAULT_SEGMENT_DURATION = cfg.get("video_clip_default_segment_duration", 2)
|
|
|
|
logger.info(f"[INFO] Config initialized from {config_path}, alert_push_url={ALERT_PUSH_URL}")
|
|
|
|
except Exception as e:
|
|
logger.error(f"[ERROR] Failed to load config from {config_path}: {e}") |