# -*- coding: utf-8 -*-
"""单独下载并转写「一个人运营30多个矩阵」这条视频"""
import json, os, subprocess, sys

sys.stdout.reconfigure(encoding="utf-8")
ROOT = r"D:\Deepseek\juzhen2_top"
VID = os.path.join(ROOT, "videos")
os.makedirs(VID, exist_ok=True)
works = {w["id"]: w for w in json.load(open(os.path.join(ROOT, "_works.json"), encoding="utf-8"))}
target = [w for w in works.values() if "30多" in w["desc"]][0]
print("目标:", target["id"], target["desc"][:40], "时长", target["duration_ms"] // 1000, "s")

import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"
fp = os.path.join(VID, f"{target['created']}_{target['id']}.mp4")
if not os.path.exists(fp):
    r = requests.get(target["play"], headers={"User-Agent": UA, "Referer": "https://www.douyin.com/"}, timeout=60)
    open(fp, "wb").write(r.content)
print("下载完成", os.path.getsize(fp) // 1024, "KB")
