37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
import json, os, sys
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from qcloud_cos import CosConfig, CosS3Client
|
|
from config.config_utils import config
|
|
|
|
cos = config.get_cos_config()
|
|
client = CosS3Client(CosConfig(Region=cos["region"], SecretId=cos["secret_id"],
|
|
SecretKey=cos["secret_key"]))
|
|
bucket = cos["bucket"]
|
|
|
|
rows = []
|
|
for line in open("数据.jsonl", encoding="utf-8"):
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
try:
|
|
r = json.loads(line)
|
|
except Exception:
|
|
continue
|
|
if r.get("status") == "success" and r.get("srt_cos_path"):
|
|
rows.append(r)
|
|
recent = rows[-15:]
|
|
|
|
os.makedirs("srt_check", exist_ok=True)
|
|
ok = 0
|
|
for r in recent:
|
|
p = r["srt_cos_path"]
|
|
key = p.split("://", 1)[1].split("/", 1)[1] # 去掉 cos://bucket/
|
|
name = os.path.basename(key)
|
|
try:
|
|
client.download_file(Bucket=bucket, Key=key, DestFilePath=os.path.join("srt_check", name))
|
|
ok += 1
|
|
except Exception as e:
|
|
print("下载失败", name, e)
|
|
print(f"下载成功 {ok}/{len(recent)} → srt_check/")
|