-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
80 lines (72 loc) · 2.34 KB
/
config.py
File metadata and controls
80 lines (72 loc) · 2.34 KB
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
70
71
72
73
74
75
76
77
78
79
80
"""
配置管理模块 - 统一管理所有配置项
"""
from dataclasses import dataclass
from typing import List, Dict, Any
import os
@dataclass
class AudioProcessingConfig:
"""音频处理配置"""
MAX_FILE_SIZE_MB: int = 25
MIN_FILE_SIZE_BYTES: int = 100
CONVERSION_TIMEOUT_SECONDS: int = 60
RETRY_COUNT: int = 2
RETRY_DELAY_SECONDS: float = 1.0
SUPPORTED_FORMATS: List[str] = None
def __post_init__(self):
if self.SUPPORTED_FORMATS is None:
self.SUPPORTED_FORMATS = [
'flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga',
'oga', 'ogg', 'wav', 'webm'
]
@dataclass
class TempFileConfig:
"""临时文件配置"""
TEMP_DIR_NAME: str = "astrbot_voice_temp"
AUTO_CLEANUP: bool = True
MAX_TEMP_FILES: int = 100
CLEANUP_INTERVAL_MINUTES: int = 30
@dataclass
class FFmpegConfig:
"""FFmpeg配置"""
SEARCH_CACHE_TIMEOUT_SECONDS: int = 3600 # 1小时缓存
CONVERSION_TIMEOUT_SECONDS: int = 20 # 转换超时时间
RETRY_COUNT: int = 2 # 重试次数
RETRY_DELAY_SECONDS: float = 1.0 # 重试延迟
COMMON_PATHS: List[str] = None
def __post_init__(self):
if self.COMMON_PATHS is None:
if os.name == 'nt': # Windows
self.COMMON_PATHS = [
r'C:\ffmpeg\bin\ffmpeg.exe',
r'C:\Program Files\FFmpeg\bin\ffmpeg.exe',
os.path.expanduser(r'~\scoop\apps\ffmpeg\current\bin\ffmpeg.exe'),
]
else: # Unix/Linux/Mac
self.COMMON_PATHS = [
'/usr/bin/ffmpeg',
'/usr/local/bin/ffmpeg',
'/opt/homebrew/bin/ffmpeg',
]
@dataclass
class LoggingConfig:
"""日志配置"""
ENABLE_DEBUG: bool = False
ENABLE_PERFORMANCE_LOGGING: bool = True
LOG_CONVERSION_DETAILS: bool = True
@dataclass
class PluginConfig:
"""插件总配置"""
audio: AudioProcessingConfig
temp_file: TempFileConfig
ffmpeg: FFmpegConfig
logging: LoggingConfig
@classmethod
def create_default(cls) -> 'PluginConfig':
"""创建默认配置"""
return cls(
audio=AudioProcessingConfig(),
temp_file=TempFileConfig(),
ffmpeg=FFmpegConfig(),
logging=LoggingConfig()
)