diff --git a/apps/worker/video_processing/subtitle_render_engine.py b/apps/worker/video_processing/subtitle_render_engine.py index 1daac15a4..fab753953 100755 --- a/apps/worker/video_processing/subtitle_render_engine.py +++ b/apps/worker/video_processing/subtitle_render_engine.py @@ -171,9 +171,7 @@ class SubtitleRenderEngine: except (TypeError, ValueError): continue - def add_asr_timeline( - self, timeline: Any, style: SubtitleStyle | None = None - ) -> None: + def add_asr_timeline(self, timeline: Any, style: SubtitleStyle | None = None) -> None: """从 SubtitleTimeline 对象添加 ASR 字幕.""" if not timeline or not hasattr(timeline, "segments") or not timeline.segments: return @@ -254,9 +252,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text back_color = style.ass_background_color else: border_style = 1 - back_color = ( - style.ass_shadow_color if style.shadow_enabled else style.ass_font_color - ) + back_color = style.ass_shadow_color if style.shadow_enabled else style.ass_font_color outline_val = style.stroke_width if style.stroke_enabled else 0.0 shadow_val = style.shadow_offset_y if style.shadow_enabled else 0 @@ -289,10 +285,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text start_time = _format_ass_time(max(0, seg.start)) end_time = _format_ass_time(max(seg.start + 0.1, seg.end)) - return ( - f"Dialogue: 0,{start_time},{end_time},{seg.style_name},,0,0,0,," - f"{effect_tags}{safe_text}" - ) + return f"Dialogue: 0,{start_time},{end_time},{seg.style_name},,0,0,0,," f"{effect_tags}{safe_text}" @property def has_subtitles(self) -> bool: @@ -340,10 +333,7 @@ def build_subtitles_from_plan( style_dict = title_cfg.get("style") or {} style = SubtitleStyle.from_dict(style_dict) # 标题默认样式:顶部、大字号、粗体 - if ( - style.position == DEFAULT_POSITION - and style.font_size == DEFAULT_FONT_SIZE - ): + if style.position == DEFAULT_POSITION and style.font_size == DEFAULT_FONT_SIZE: style.position = "top_center" style.font_size = 48 style.bold = True @@ -419,9 +409,7 @@ def build_subtitle_filter( # - Windows 路径的 \ → / # - 冒号 : → \: # - 单引号 ' → '\'' - safe_path = ( - ass_path_str.replace("\\", "/").replace(":", "\\:").replace("'", "'\\''") - ) + safe_path = ass_path_str.replace("\\", "/").replace(":", "\\:").replace("'", "'\\''") return f"{video_input_label}subtitles='{safe_path}'[{output_label}]" @@ -461,6 +449,4 @@ def _validate_subtitle_path(subtitle_path: str, work_dir: Path) -> None: resolved_path.relative_to(resolved_work_dir) except ValueError as _e: if not is_in_allowed_dirs(resolved_path): - raise PathSecurityError( - f"字幕路径不在允许目录内: {subtitle_path[:80]}" - ) from _e + raise PathSecurityError(f"字幕路径不在允许目录内: {subtitle_path[:80]}") from _e