# -*- coding: utf-8 -*-
"""找出「一个人运营30多个矩阵」那条视频，并抽取其评论 + 全库商投/佣金评论"""
import glob, json, os, re, sys

sys.stdout.reconfigure(encoding="utf-8")
ROOT = r"D:\Deepseek\juzhen2_top"
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"] or "三十" in w["desc"]]
print("目标视频:", [(w["id"], w["desc"][:40], w["comment"]) for w in target])

if target:
    tid = target[0]["id"]
    fp = os.path.join(ROOT, "comments", tid + ".json")
    if os.path.exists(fp):
        j = json.load(open(fp, encoding="utf-8"))
        print(f"\n=== 该视频评论（{len(j.get('comments', []))} 条，按赞 Top 15）===")
        for c in sorted(j.get("comments", []), key=lambda x: -(x.get("digg") or 0))[:15]:
            print(f"[{c.get('digg') or 0}] {(c.get('text') or '')[:110]}")

print("\n=== 全库提商投/佣金/投流的评论 ===")
pat = re.compile(r"商投|投流|佣金|商家投")
n = 0
for fp in glob.glob(os.path.join(ROOT, "comments", "*.json")):
    j = json.load(open(fp, encoding="utf-8"))
    for c in j.get("comments", []):
        t = (c.get("text") or "").strip()
        if t and pat.search(t):
            print(f"[{c.get('digg') or 0}] {t[:110]}")
            n += 1
            if n >= 20:
                break
    if n >= 20:
        break
