Require per-video folders without hard-padding duration, weave food/life/YT-money into SRT, enforce 3 AI thumbnail variants, and validate A/B/C covers. Co-authored-by: Cursor <cursoragent@cursor.com>
144 lines
4.3 KiB
Python
144 lines
4.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Validate YT deliverables in a batch root (SRT / covers A/B/C / titles).
|
|
|
|
Usage:
|
|
python validate_deliverables.py
|
|
python validate_deliverables.py "D:\\MyBatch"
|
|
|
|
Exit code 0 = all OK; 1 = problems found.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
COVER_NAMES = ("YT_COVER.jpg", "YT_COVER_B.jpg", "YT_COVER_C.jpg")
|
|
|
|
|
|
def to_sec(ts: str) -> float:
|
|
h, m, rest = ts.split(":")
|
|
s, ms = rest.split(",")
|
|
return int(h) * 3600 + int(m) * 60 + int(s) + int(ms) / 1000
|
|
|
|
|
|
def check_srt(path: Path) -> list[str]:
|
|
errs = []
|
|
text = path.read_text(encoding="utf-8", errors="replace")
|
|
if not text.strip():
|
|
return ["SRT empty"]
|
|
blocks = re.split(r"\n\s*\n", text.strip())
|
|
prev_end = None
|
|
cues = 0
|
|
for b in blocks:
|
|
lines = [ln for ln in b.splitlines() if ln.strip() != ""]
|
|
if len(lines) < 3:
|
|
continue
|
|
cues += 1
|
|
m = re.match(r"(\d{2}:\d{2}:\d{2},\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2},\d{3})", lines[1])
|
|
if not m:
|
|
errs.append(f"bad timing line: {lines[1][:40]}")
|
|
continue
|
|
start, end = to_sec(m.group(1)), to_sec(m.group(2))
|
|
if end <= start:
|
|
errs.append(f"end<=start cue#{cues}")
|
|
if prev_end is not None and start + 1e-6 < prev_end:
|
|
errs.append(f"overlap before cue#{cues}")
|
|
prev_end = end
|
|
body = lines[2:]
|
|
if len(body) != 1:
|
|
errs.append(f"multiline cue#{cues} lines={len(body)}")
|
|
elif "\n" in body[0]:
|
|
errs.append(f"newline in cue#{cues}")
|
|
if cues < 8:
|
|
errs.append(f"too few cues ({cues}) — consider denser narration")
|
|
return errs
|
|
|
|
|
|
def check_cover(path: Path) -> list[str]:
|
|
errs = []
|
|
try:
|
|
im = Image.open(path)
|
|
w, h = im.size
|
|
if (w, h) != (1280, 720):
|
|
errs.append(f"{path.name} size {w}x{h} (want 1280x720)")
|
|
except Exception as e:
|
|
errs.append(f"{path.name} unreadable: {e}")
|
|
return errs
|
|
|
|
|
|
def check_titles(path: Path) -> list[str]:
|
|
errs = []
|
|
t = path.read_text(encoding="utf-8", errors="replace")
|
|
if "YOUTUBE TITLES" not in t.upper() and "=== YOUTUBE TITLES" not in t:
|
|
errs.append("titles missing TITLES section")
|
|
if t.count("\n") < 8:
|
|
errs.append("titles file looks too short")
|
|
up = t.upper()
|
|
for bad in ("FACE + FULL BODY", "CHINA GIRL"):
|
|
if bad in up:
|
|
errs.append(f"titles contain forbidden meta: {bad}")
|
|
return errs
|
|
|
|
|
|
def main() -> None:
|
|
root = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else Path.cwd().resolve()
|
|
folders = [
|
|
d
|
|
for d in sorted(root.iterdir(), key=lambda p: p.name.lower())
|
|
if d.is_dir()
|
|
and not d.name.startswith("_")
|
|
and not d.name.startswith(".")
|
|
and list(d.glob("*.mp4"))
|
|
]
|
|
if not folders:
|
|
print("No media folders found under", root)
|
|
sys.exit(1)
|
|
|
|
bad = 0
|
|
print(f"ROOT {root}")
|
|
for d in folders:
|
|
issues = []
|
|
srt = d / "YT_CAPTIONS_EN.srt"
|
|
titles = d / "YT_TITLES.txt"
|
|
if not srt.exists():
|
|
issues.append("missing YT_CAPTIONS_EN.srt")
|
|
else:
|
|
issues += [f"SRT: {e}" for e in check_srt(srt)]
|
|
|
|
# ≥3 A/B/C covers; accept legacy ALT as B if B missing
|
|
cover_a = d / "YT_COVER.jpg"
|
|
cover_b = d / "YT_COVER_B.jpg"
|
|
cover_c = d / "YT_COVER_C.jpg"
|
|
legacy_alt = d / "YT_COVER_ALT.jpg"
|
|
if not cover_b.exists() and legacy_alt.exists():
|
|
cover_b = legacy_alt
|
|
|
|
for label, path in (("A", cover_a), ("B", cover_b), ("C", cover_c)):
|
|
if not path.exists():
|
|
issues.append(f"missing cover {label} (need YT_COVER.jpg / _B / _C for A/B test)")
|
|
else:
|
|
issues += [f"COVER-{label}: {e}" for e in check_cover(path)]
|
|
|
|
if not titles.exists():
|
|
issues.append("missing YT_TITLES.txt")
|
|
else:
|
|
issues += [f"TITLES: {e}" for e in check_titles(titles)]
|
|
|
|
if issues:
|
|
bad += 1
|
|
print(f"FAIL {d.name}")
|
|
for e in issues:
|
|
print(f" - {e}")
|
|
else:
|
|
print(f"OK {d.name}")
|
|
|
|
print(f"\n{len(folders) - bad}/{len(folders)} folders OK")
|
|
sys.exit(1 if bad else 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|