首次提交

This commit is contained in:
2026-09-28 16:09:31 +08:00
commit 4a6839319a
71 changed files with 12144 additions and 0 deletions

96
tools/download_srt.py Normal file
View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
"""
从 数据.jsonl 中读取成功记录,将 MP4 和 SRT 文件下载到本地 ./成功/ 目录。
用法:python download_srt.py [数据.jsonl路径] [本地输出目录]
默认:python download_srt.py 数据.jsonl ./成功
"""
import json
import os
import subprocess
import sys
from config.config_utils import config
JSONL_PATH = sys.argv[1] if len(sys.argv) > 1 else "数据.jsonl"
OUTPUT_DIR = sys.argv[2] if len(sys.argv) > 2 else "./成功"
def download(coscli_path, cos_config_path, cos_src, local_path):
"""下载单个文件,返回是否成功"""
if os.path.exists(local_path):
return "skip"
cmd = [coscli_path, "-c", cos_config_path, "cp", cos_src, local_path]
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
return "ok" if result.returncode == 0 else result.stderr.strip()
def main():
if not os.path.exists(JSONL_PATH):
print(f"找不到文件: {JSONL_PATH}")
return
cfg = config.get_splitframe_config()
coscli_path = cfg.get('coscli_path', './coscli-linux-amd64')
cos_config_path = cfg.get('cosconfig_path', '.cos.yaml')
# 读取所有成功记录
records = []
with open(JSONL_PATH, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line:
continue
try:
rec = json.loads(line)
if rec.get('status') == 'success' and rec.get('srt_cos_path'):
records.append(rec)
except json.JSONDecodeError:
pass
records = records[:50]
total = len(records)
print(f"共找到 {total} 条成功记录,开始下载...")
os.makedirs(OUTPUT_DIR, exist_ok=True)
success = skip = failed = 0
for i, rec in enumerate(records, 1):
video_cos = rec.get('video_cos_path').replace(".mp4", ".mp3")
srt_cos = rec.get('srt_cos_path')
video_name = os.path.splitext(os.path.basename(video_cos))[0] if video_cos else None
print(f"[{i}/{total}] {video_name}")
# 下载 MP4
if video_cos:
local_mp4 = os.path.join(OUTPUT_DIR, os.path.basename(video_cos))
ret = download(coscli_path, cos_config_path, video_cos, local_mp4)
if ret == "ok":
success += 1
print(f" ✓ 视频: {os.path.basename(video_cos)}")
elif ret == "skip":
skip += 1
print(f" - 视频已存在,跳过")
else:
failed += 1
print(f" ✗ 视频下载失败: {ret}")
# 下载 SRT
if srt_cos:
local_srt = os.path.join(OUTPUT_DIR, os.path.basename(srt_cos))
ret = download(coscli_path, cos_config_path, srt_cos, local_srt)
if ret == "ok":
success += 1
print(f" ✓ 字幕: {os.path.basename(srt_cos)}")
elif ret == "skip":
skip += 1
print(f" - 字幕已存在,跳过")
else:
failed += 1
print(f" ✗ 字幕下载失败: {ret}")
print(f"\n完成 — 下载: {success} 失败: {failed} 跳过(已存在): {skip}")
print(f"文件保存在: {os.path.abspath(OUTPUT_DIR)}")
if __name__ == '__main__':
main()