From ce01c110be33817f841be560c67dbdde4b7cf5b8 Mon Sep 17 00:00:00 2001 From: linyq Date: Thu, 8 May 2025 00:13:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=89=AA=E8=BE=91=E5=8A=9F=E8=83=BD=E5=92=8C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA-=20=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E6=8E=89=E9=83=A8=E5=88=86=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA=EF=BC=8C=E5=87=8F=E5=B0=91=E5=86=97=E4=BD=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20-=20=E4=BF=AE=E6=94=B9=E8=A7=86=E9=A2=91=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=20ID=20=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F=20-=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E9=A2=91=E8=B7=AF=E5=BE=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91=20-=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E5=AF=BC=E5=85=A5=20-=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BC=82=E5=B8=B8=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E9=AB=98=E9=94=99=E8=AF=AF=E6=8E=92=E6=9F=A5?= =?UTF-8?q?=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/material.py | 6 +++--- app/services/video_service.py | 2 -- app/services/voice.py | 9 +++++++-- app/utils/utils.py | 2 +- webui/components/review_settings.py | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/services/material.py b/app/services/material.py index b3ce063..c048a92 100644 --- a/app/services/material.py +++ b/app/services/material.py @@ -446,7 +446,7 @@ def save_clip_video(timestamp: str, origin_video: str, save_dir: str = "") -> st ] # 执行FFmpeg命令 - logger.info(f"裁剪视频片段: {timestamp} -> {ffmpeg_start_time}到{ffmpeg_end_time}") + # logger.info(f"裁剪视频片段: {timestamp} -> {ffmpeg_start_time}到{ffmpeg_end_time}") # logger.debug(f"执行命令: {' '.join(ffmpeg_cmd)}") process = subprocess.run( @@ -478,7 +478,7 @@ def save_clip_video(timestamp: str, origin_video: str, save_dir: str = "") -> st if os.path.exists(video_path): os.remove(video_path) return '' - + except Exception as e: logger.error(f"视频剪辑过程中发生错误: \n{str(traceback.format_exc())}") if os.path.exists(video_path): @@ -505,7 +505,6 @@ def clip_videos(task_id: str, timestamp_terms: List[str], origin_video: str, pro try: saved_video_path = save_clip_video(timestamp=item, origin_video=origin_video, save_dir=material_directory) if saved_video_path: - logger.info(f"video saved: {saved_video_path}") video_paths.update({index+1:saved_video_path}) # 更新进度 @@ -516,6 +515,7 @@ def clip_videos(task_id: str, timestamp_terms: List[str], origin_video: str, pro return {} logger.success(f"裁剪 {len(video_paths)} videos") + # logger.debug(json.dumps(video_paths, indent=4, ensure_ascii=False)) return video_paths diff --git a/app/services/video_service.py b/app/services/video_service.py index 2a0a9a6..1b2ddf0 100644 --- a/app/services/video_service.py +++ b/app/services/video_service.py @@ -4,8 +4,6 @@ from loguru import logger from typing import Dict, List, Optional, Tuple from app.services import material -from app.models.schema import VideoClipParams -from app.utils import utils class VideoService: diff --git a/app/services/voice.py b/app/services/voice.py index 48197a8..31f6d66 100644 --- a/app/services/voice.py +++ b/app/services/voice.py @@ -1197,11 +1197,14 @@ def azure_tts_v2(text: str, voice_name: str, voice_file: str) -> Union[SubMaker, def _format_text(text: str) -> str: - # text = text.replace("\n", " ") + text = text.replace("\n", " ") + text = text.replace("\"", " ") text = text.replace("[", " ") text = text.replace("]", " ") text = text.replace("(", " ") text = text.replace(")", " ") + text = text.replace(")", " ") + text = text.replace("(", " ") text = text.replace("{", " ") text = text.replace("}", " ") text = text.strip() @@ -1394,8 +1397,10 @@ def create_subtitle(sub_maker: submaker.SubMaker, text: str, subtitle_file: str) logger.error(f"failed, error: {str(e)}") os.remove(subtitle_file) else: - logger.warning( + logger.error( f"字幕创建失败, 字幕长度: {len(sub_items)}, script_lines len: {len(script_lines)}" + f"\nsub_items:{json.dumps(sub_items, indent=4, ensure_ascii=False)}" + f"\nscript_lines:{json.dumps(script_lines, indent=4, ensure_ascii=False)}" ) except Exception as e: diff --git a/app/utils/utils.py b/app/utils/utils.py index 49d44be..e80cd87 100644 --- a/app/utils/utils.py +++ b/app/utils/utils.py @@ -506,7 +506,7 @@ def cut_video(params, progress_callback=None): st.session_state['subclip_videos'] = subclip_videos for i, video_script in enumerate(video_script_list): try: - video_script['path'] = subclip_videos[video_script['timestamp']] + video_script['path'] = subclip_videos[i+1] except KeyError as err: logger.error(f"裁剪视频失败: {err}") diff --git a/webui/components/review_settings.py b/webui/components/review_settings.py index 932ec9b..c4f3bce 100644 --- a/webui/components/review_settings.py +++ b/webui/components/review_settings.py @@ -33,7 +33,7 @@ def render_video_item(tr, video_list, subclip_videos, index): video_script = video_list[index] # 显示时间戳 - timestamp = video_script.get('timestamp', '') + timestamp = video_script.get('_id', '') st.text_area( tr("Timestamp"), value=timestamp,