fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -74,7 +74,7 @@ class VideoInfo:
transcript_id: str = ""
status: str = "pending"
error_message: str = ""
metadata: dict = None
metadata: dict | None = None
def __post_init__(self) -> None:
if self.metadata is None:
@@ -97,7 +97,7 @@ class VideoProcessingResult:
class MultimodalProcessor:
"""多模态处理器 - 处理视频文件"""
def __init__(self, temp_dir: str = None, frame_interval: int = 5) -> None:
def __init__(self, temp_dir: str | None = None, frame_interval: int = 5) -> None:
"""
初始化多模态处理器
@@ -130,10 +130,12 @@ class MultimodalProcessor:
if FFMPEG_AVAILABLE:
probe = ffmpeg.probe(video_path)
video_stream = next(
(s for s in probe["streams"] if s["codec_type"] == "video"), None,
(s for s in probe["streams"] if s["codec_type"] == "video"),
None,
)
audio_stream = next(
(s for s in probe["streams"] if s["codec_type"] == "audio"), None,
(s for s in probe["streams"] if s["codec_type"] == "audio"),
None,
)
if video_stream:
@@ -165,9 +167,9 @@ class MultimodalProcessor:
return {
"duration": float(data["format"].get("duration", 0)),
"width": int(data["streams"][0].get("width", 0)) if data["streams"] else 0,
"height": int(data["streams"][0].get("height", 0))
if data["streams"]
else 0,
"height": (
int(data["streams"][0].get("height", 0)) if data["streams"] else 0
),
"fps": 30.0, # 默认值
"has_audio": len(data["streams"]) > 1,
"bitrate": int(data["format"].get("bit_rate", 0)),
@@ -177,7 +179,7 @@ class MultimodalProcessor:
return {"duration": 0, "width": 0, "height": 0, "fps": 0, "has_audio": False, "bitrate": 0}
def extract_audio(self, video_path: str, output_path: str = None) -> str:
def extract_audio(self, video_path: str, output_path: str | None = None) -> str:
"""
从视频中提取音频
@@ -223,7 +225,9 @@ class MultimodalProcessor:
print(f"Error extracting audio: {e}")
raise
def extract_keyframes(self, video_path: str, video_id: str, interval: int = None) -> list[str]:
def extract_keyframes(
self, video_path: str, video_id: str, interval: int | None = None
) -> list[str]:
"""
从视频中提取关键帧
@@ -260,7 +264,8 @@ class MultimodalProcessor:
if frame_number % frame_interval_frames == 0:
timestamp = frame_number / fps
frame_path = os.path.join(
video_frames_dir, f"frame_{frame_number:06d}_{timestamp:.2f}.jpg",
video_frames_dir,
f"frame_{frame_number:06d}_{timestamp:.2f}.jpg",
)
cv2.imwrite(frame_path, frame)
frame_paths.append(frame_path)
@@ -333,7 +338,11 @@ class MultimodalProcessor:
return "", 0.0
def process_video(
self, video_data: bytes, filename: str, project_id: str, video_id: str = None,
self,
video_data: bytes,
filename: str,
project_id: str,
video_id: str | None = None,
) -> VideoProcessingResult:
"""
处理视频文件提取音频、关键帧、OCR
@@ -426,7 +435,7 @@ class MultimodalProcessor:
error_message=str(e),
)
def cleanup(self, video_id: str = None) -> None:
def cleanup(self, video_id: str | None = None) -> None:
"""
清理临时文件
@@ -457,7 +466,9 @@ class MultimodalProcessor:
_multimodal_processor = None
def get_multimodal_processor(temp_dir: str = None, frame_interval: int = 5) -> MultimodalProcessor:
def get_multimodal_processor(
temp_dir: str | None = None, frame_interval: int = 5
) -> MultimodalProcessor:
"""获取多模态处理器单例"""
global _multimodal_processor
if _multimodal_processor is None: