videoSummary/app/config.py
2025-12-02 18:54:14 +08:00

106 lines
2.9 KiB
Python

"""
Configuration management
Primary configuration source: config.yaml
"""
import yaml
from pathlib import Path
class Config:
"""Application configuration
All configuration is read from config.yaml file.
"""
def __init__(self):
"""Load configuration from config.yaml"""
config_path = Path(__file__).parent.parent / 'config.yaml'
# Load config.yaml
if not config_path.exists():
raise FileNotFoundError(f"Configuration file not found: {config_path}")
with open(config_path, 'r', encoding='utf-8') as f:
self._config = yaml.safe_load(f)
@property
def server_host(self):
"""Get server host"""
return self._config['server']['host']
@property
def server_port(self):
"""Get server port"""
return self._config['server']['port']
@property
def server_mode(self):
"""Get server mode"""
return self._config['server']['mode']
@property
def mongodb_uri(self):
"""Get MongoDB URI"""
return self._config['mongodb']['uri']
@property
def mongodb_database(self):
"""Get MongoDB database name"""
return self._config['mongodb']['database']
@property
def mongodb_max_pool_size(self):
"""Get MongoDB max pool size"""
return self._config['mongodb'].get('max_pool_size', 100)
@property
def mongodb_min_pool_size(self):
"""Get MongoDB min pool size"""
return self._config['mongodb'].get('min_pool_size', 10)
@property
def dashscope_api_key(self):
"""Get DashScope API key"""
return self._config['dashscope']['api_key']
@property
def dashscope_model(self):
"""Get DashScope model name"""
return self._config['dashscope']['model']
@property
def dashscope_fps(self):
"""Get DashScope fps parameter"""
return self._config['dashscope'].get('fps', 2)
@property
def log_level(self):
"""Get log level"""
return self._config['log']['level']
@property
def log_format(self):
"""Get log format"""
return self._config['log']['format']
@property
def log_output(self):
"""Get log output"""
return self._config['log']['output']
@property
def upload_folder(self):
"""Get upload folder path"""
return Path(__file__).parent.parent / 'uploads'
@property
def max_upload_size(self):
"""Get max upload file size in bytes (default: 500MB)"""
return self._config.get('upload', {}).get('max_size', 500 * 1024 * 1024)
@property
def allowed_extensions(self):
"""Get allowed file extensions"""
return self._config.get('upload', {}).get('allowed_extensions',
['mp4', 'avi', 'mov', 'mkv', 'wmv', 'flv', 'webm'])