This commit is contained in:
2025-07-22 13:39:46 +08:00
parent dc94cc41c2
commit 0214a6069b
18 changed files with 69 additions and 1059 deletions

View File

@ -1,7 +1,7 @@
import streamlit as st
from pathlib import Path
from scripts.step1_notion_sync import create_project_from_page
from scripts.step6_assemble_video import run_step6_assemble_video
# from scripts_.step1_notion_sync import create_project_from_page
# from scripts_.step6_assemble_video import run_step6_assemble_video
from utils.paths import PROJECTS_DIR ,get_project_list
from utils import asset_manager
import requests
@ -79,8 +79,7 @@ def _execute_project_method(method_name: str, spinner_text: str):
return
with st.spinner(spinner_text):
success= method_to_call()
st.session_state.operation_status = {"type": "success" if success else "error"}
method_to_call()
# --- 所有後續的 Callback 現在都變得極其簡潔 ---
@ -144,31 +143,20 @@ def assemble_final_video(logo_video_name, open_video_name, end_video_name):
"message": error_message
}
def callback_run_step(step_function, source="unknown", **kwargs):
spinner_text = kwargs.pop("spinner_text", "正在處理中,請稍候...")
with st.spinner(spinner_text):
result = step_function(**kwargs)
if len(result) == 2: success, msg = result
elif len(result) == 3: success, msg, _ = result
else: success, msg = False, "步驟函式回傳格式不符!"
st.session_state.operation_status = {"success": success, "message": msg, "source": source}
if step_function == run_step6_assemble_video and success:
st.session_state.final_video_path = str(result[2])
st.session_state.show_video = True
def toggle_all_video_checkboxes(self, video_files):
def toggle_all_video_checkboxes( video_files):
"""【新】切換所有影片核取方塊的選取狀態。"""
select_all_state = st.session_state.get('select_all_videos', False)
for video_file in video_files:
st.session_state[f"delete_cb_{video_file.name}"] = select_all_state
def delete_selected_videos(self):
def delete_selected_videos():
"""【新】刪除在 UI 中選取的影片。"""
if not self.project:
if not st.session_state.project:
st.session_state.operation_status = {"type": "warning", "message": "請先選擇一個專案。"}
return
output_dir = self.project.paths["output"]
output_dir = st.session_state.project.paths["output"]
deleted_files_count = 0
errors = []
files_to_delete = [
@ -226,7 +214,7 @@ def callback_download_videos(paths: dict):
st.session_state.operation_status = {"success": False, "message": "尚未選擇任何影片。", "source": "download_videos"}
return
download_dir = paths["output"] / "test"
download_dir = paths["temp_video"]
download_dir.mkdir(parents=True, exist_ok=True)
# --- 循序命名邏輯 START ---
@ -252,7 +240,7 @@ def callback_download_videos(paths: dict):
original_path = Path(url)
# 使用循序命名
new_video_name = f"{counter}{original_path.suffix}"
new_video_name = f"{counter:02d}{original_path.suffix}"
save_path = download_dir / new_video_name
try: