import json, subprocess, re data = json.load(open("/home/hermes/syslog/drafts/scot-hermes-playbook/research/video-verification.json")) have = {r["videoId"] for r in data} extra = [] for v in ["8GjyOQy19so", "zwqhemjHq3E"]: if v in have: continue url = f"https://www.youtube.com/watch?v={v}" oe = subprocess.run(["curl", "-s", f"https://www.youtube.com/oembed?url={url}&format=json"], capture_output=True, text=True, timeout=30) try: oej = json.loads(oe.stdout) o = {"status": "PASS", "title": oej.get("title"), "author": oej.get("author_name")} except Exception: o = {"status": "FAIL", "raw": oe.stdout[:200]} wp = subprocess.run(["curl", "-s", "-L", url, "-H", "User-Agent: Mozilla/5.0 (Windows NT 10.0) Chrome/124.0", "-H", "Accept-Language: en-US"], capture_output=True, text=True, timeout=30) html = wp.stdout pub = re.search(r'"publishDate":"([\d\-T:Z]+)"', html) dur = re.search(r'"lengthSeconds":"(\d+)"', html) views = re.search(r'"viewCount":"(\d+)"', html) rec = {"videoId": v, "oembed": o, "publishDate": pub.group(1) if pub else None, "lengthSeconds": int(dur.group(1)) if dur else None, "views": int(views.group(1)) if views else None} extra.append(rec) print(json.dumps(rec)) data.extend(extra) json.dump(data, open("/home/hermes/syslog/drafts/scot-hermes-playbook/research/video-verification.json", "w"), indent=2) print("total videos in ledger:", len(data))