Initial commit: sanitize repository for remote push

This commit is contained in:
theshy
2026-03-21 01:36:28 +08:00
commit 3925cb508f
21 changed files with 3357 additions and 0 deletions

96
start_all.py Normal file
View File

@ -0,0 +1,96 @@
import subprocess
import time
import sys
import os
from pathlib import Path
from logger import get_system_logger
# ==========================================
# 配置区:确保脚本文件名与你本地一致
# ==========================================
SCRIPTS = [
"monitor.py", # 1. 监控 stage触发视频转录 (调用 video2srt.py)
"monitorSrt.py", # 2. 监控 session触发 Codex 歌词识别
"monitorSongs.py", # 3. 监控 session触发 FFmpeg 视频切片
"upload.py", # 4. 监控 session触发 biliup 自动投稿
"session_top_comment.py", # 5. 监控 session触发 B 站评论置顶
"add_to_collection.py", # 5. 新增:监控 session触发合集归档 <--- 添加这一行
]
# Python 解释器路径 (通常直接用 sys.executable)
PYTHON_EXE = sys.executable
# 初始化日志
logger = get_system_logger('start_all')
# ==========================================
def start_pipeline():
processes = []
logger.info("="*50)
logger.info("直播切片 & 自动投稿全自动流水线")
logger.info("="*50)
logger.info(f"启动时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
logger.info(f"当前路径: {os.getcwd()}")
logger.info(f"Python: {PYTHON_EXE}")
# 检查所有脚本是否存在
for script in SCRIPTS:
if not Path(script).exists():
logger.error(f"找不到脚本 {script},请确保它们在同一目录下")
print(f"[X] 错误: 找不到脚本 {script},请确保它们在同一目录下。")
return
# 逐一启动
for script in SCRIPTS:
logger.info(f"正在启动模块: {script}")
try:
# 使用 subprocess.Popen 异步启动
# creationflags=subprocess.CREATE_NEW_CONSOLE 可以让每个脚本在独立窗口运行(仅限 Windows
# 如果你希望所有日志都在这一个窗口显示,去掉 creationflags
p = subprocess.Popen(
[PYTHON_EXE, script],
creationflags=subprocess.CREATE_NEW_CONSOLE if os.name == 'nt' else 0
)
processes.append((script, p))
logger.info(f"模块已启动: {script} (PID: {p.pid})")
time.sleep(1) # 稍微错开启动时间,防止瞬间抢占 IO
except Exception as e:
logger.error(f"启动 {script} 失败: {e}")
print(f"[X] 启动 {script} 失败: {e}")
logger.info("")
logger.info("="*50)
logger.info("所有监控模块已启动!")
logger.info("请勿关闭此主窗口,除非你想停止整个流水线")
logger.info("="*50)
print("\n" + "="*50)
print("[√] 所有监控模块已启动!")
print("[!] 请勿关闭此主窗口,除非你想停止整个流水线。")
print("[!] 详细日志请查看 ./logs/system/ 目录")
print("="*50)
try:
# 循环检查子进程状态
while True:
for name, p in processes:
if p.poll() is not None:
logger.warning(f"模块 {name} 已意外停止 (Exit Code: {p.poll()})")
print(f"\n[⚠️] 警告: 模块 {name} 已意外停止 (Exit Code: {p.poll()})")
# 这里可以加入自动重启逻辑
time.sleep(10)
except KeyboardInterrupt:
logger.info("接收到停止信号,正在关闭所有监控模块...")
print("\n[*] 正在关闭所有监控模块...")
for name, p in processes:
p.terminate()
logger.info(f"模块已终止: {name}")
logger.info("已安全退出")
print("[√] 已安全退出。")
if __name__ == "__main__":
start_all_dir = Path(__file__).parent
os.chdir(start_all_dir) # 确保工作路径正确
start_pipeline()