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>
612 lines
20 KiB
Python
612 lines
20 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""≥3 A/B/C covers + OpenCV EDSR x2 photographic super-res (CPU)."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import traceback
|
|
from pathlib import Path
|
|
|
|
import cv2
|
|
import numpy as np
|
|
from PIL import Image, ImageDraw, ImageEnhance, ImageFont
|
|
|
|
try:
|
|
from cv2 import dnn_superres
|
|
except ImportError:
|
|
dnn_superres = None # type: ignore
|
|
|
|
ROOT = Path(__file__).resolve().parent
|
|
W, H = 1280, 720
|
|
EDSR = Path(r"c:\Users\Administrator\Desktop\youtube-skill\tools\opencv_sr\EDSR_x2.pb")
|
|
FSRCNN = Path(r"c:\Users\Administrator\Desktop\youtube-skill\tools\opencv_sr\FSRCNN_x2.pb")
|
|
|
|
_SR = None
|
|
|
|
|
|
def get_sr():
|
|
global _SR
|
|
if _SR is not None:
|
|
return _SR
|
|
if dnn_superres is None:
|
|
_SR = False
|
|
return _SR
|
|
sr = dnn_superres.DnnSuperResImpl_create()
|
|
if EDSR.exists():
|
|
sr.readModel(str(EDSR))
|
|
sr.setModel("edsr", 2)
|
|
print("SR model: EDSR_x2")
|
|
elif FSRCNN.exists():
|
|
sr.readModel(str(FSRCNN))
|
|
sr.setModel("fsrcnn", 2)
|
|
print("SR model: FSRCNN_x2")
|
|
else:
|
|
print("SR model missing — Lanczos only")
|
|
_SR = False
|
|
return _SR
|
|
_SR = sr
|
|
return _SR
|
|
|
|
|
|
def imwrite_u(path: Path, bgr: np.ndarray, q: int = 96) -> None:
|
|
ok, buf = cv2.imencode(".jpg", bgr, [int(cv2.IMWRITE_JPEG_QUALITY), q])
|
|
path.write_bytes(buf.tobytes())
|
|
|
|
|
|
def find_folder(*tokens: str) -> Path | None:
|
|
for d in ROOT.iterdir():
|
|
if d.is_dir() and not d.name.startswith("_"):
|
|
names = " ".join(p.name for p in d.glob("*.mp4"))
|
|
if any(t in names for t in tokens):
|
|
return d
|
|
return None
|
|
|
|
|
|
def sharpness(bgr: np.ndarray) -> float:
|
|
g = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
|
|
h, w = g.shape
|
|
roi = g[int(h * 0.12) : int(h * 0.88), int(w * 0.12) : int(w * 0.88)]
|
|
return float(cv2.Laplacian(roi, cv2.CV_64F).var())
|
|
|
|
|
|
def brightness(bgr: np.ndarray) -> float:
|
|
return float(cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY).mean())
|
|
|
|
|
|
def grab_at(path: Path, t: float) -> np.ndarray | None:
|
|
cap = cv2.VideoCapture(str(path))
|
|
if not cap.isOpened():
|
|
return None
|
|
cap.set(cv2.CAP_PROP_POS_MSEC, max(0.0, t) * 1000)
|
|
ok, frame = cap.read()
|
|
cap.release()
|
|
return frame if ok else None
|
|
|
|
|
|
def resolve_clip(folder: Path, clip: str) -> Path | None:
|
|
path = folder / clip
|
|
if path.exists():
|
|
return path
|
|
key = clip.replace(".mp4", "")
|
|
hits = [p for p in folder.glob("*.mp4") if key in p.name]
|
|
return hits[0] if hits else None
|
|
|
|
|
|
def best_frames(
|
|
folder: Path,
|
|
clip_hints: list[str],
|
|
times: list[float],
|
|
top_k: int = 3,
|
|
min_bright: float = 32.0,
|
|
min_sharp: float = 35.0,
|
|
) -> list[np.ndarray]:
|
|
clips: list[Path] = []
|
|
for h in clip_hints:
|
|
p = resolve_clip(folder, h)
|
|
if p and p not in clips:
|
|
clips.append(p)
|
|
if not clips:
|
|
clips = sorted(folder.glob("*.mp4"))
|
|
|
|
scored: list[tuple[float, np.ndarray]] = []
|
|
for path in clips:
|
|
cap = cv2.VideoCapture(str(path))
|
|
if not cap.isOpened():
|
|
continue
|
|
fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
|
n = cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0
|
|
dur = n / fps if fps > 0 else 0
|
|
for t in times:
|
|
if dur > 1 and t >= dur - 0.4:
|
|
continue
|
|
cap.set(cv2.CAP_PROP_POS_MSEC, t * 1000)
|
|
ok, frame = cap.read()
|
|
if not ok or frame is None:
|
|
continue
|
|
b = brightness(frame)
|
|
if b < min_bright:
|
|
continue
|
|
s = sharpness(frame)
|
|
if s < min_sharp:
|
|
continue
|
|
score = s * (0.85 + 0.15 * min(b, 140) / 140)
|
|
scored.append((score, frame))
|
|
cap.release()
|
|
|
|
if not scored:
|
|
for path in clips[:2]:
|
|
for t in [1.0, 3.0, 5.0, 8.0, 12.0]:
|
|
f = grab_at(path, t)
|
|
if f is not None:
|
|
scored.append((1.0, f))
|
|
if not scored:
|
|
return []
|
|
|
|
scored.sort(key=lambda x: x[0], reverse=True)
|
|
# diversify: skip near-duplicate sharpness neighbors by taking spaced picks
|
|
picks: list[np.ndarray] = []
|
|
for _, fr in scored:
|
|
picks.append(fr)
|
|
if len(picks) >= top_k:
|
|
break
|
|
while len(picks) < top_k:
|
|
picks.append(picks[-1])
|
|
return picks
|
|
|
|
|
|
def photo_grade(bgr: np.ndarray) -> np.ndarray:
|
|
out = bgr.astype(np.float32)
|
|
out = (out - 128.0) * 1.05 + 128.0 + 3.0
|
|
out = np.clip(out, 0, 255).astype(np.uint8)
|
|
hsv = cv2.cvtColor(out, cv2.COLOR_BGR2HSV).astype(np.float32)
|
|
hsv[:, :, 1] = np.clip(hsv[:, :, 1] * 1.05, 0, 255)
|
|
return cv2.cvtColor(hsv.astype(np.uint8), cv2.COLOR_HSV2BGR)
|
|
|
|
|
|
def super_res(bgr: np.ndarray, max_in: int = 960) -> np.ndarray:
|
|
"""Photographic x2 super-res (EDSR) then keep manageable size."""
|
|
src = photo_grade(bgr)
|
|
h, w = src.shape[:2]
|
|
if max(h, w) > max_in:
|
|
s = max_in / max(h, w)
|
|
src = cv2.resize(src, (int(w * s), int(h * s)), interpolation=cv2.INTER_AREA)
|
|
|
|
sr = get_sr()
|
|
if sr is False or sr is None:
|
|
return cv2.resize(src, (src.shape[1] * 2, src.shape[0] * 2), interpolation=cv2.INTER_LANCZOS4)
|
|
|
|
try:
|
|
up = sr.upsample(src)
|
|
except Exception as e:
|
|
print("SR upsample fail:", e)
|
|
return cv2.resize(src, (src.shape[1] * 2, src.shape[0] * 2), interpolation=cv2.INTER_LANCZOS4)
|
|
return up
|
|
|
|
|
|
def to_pil(bgr: np.ndarray) -> Image.Image:
|
|
return Image.fromarray(cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB))
|
|
|
|
|
|
def crop_rel(bgr: np.ndarray, x0, y0, x1, y1) -> np.ndarray:
|
|
h, w = bgr.shape[:2]
|
|
a, b0 = int(x0 * w), int(y0 * h)
|
|
c, d = int(x1 * w), int(y1 * h)
|
|
return bgr[max(0, b0) : min(h, d), max(0, a) : min(w, c)].copy()
|
|
|
|
|
|
def fit_pil(img: Image.Image, tw: int, th: int, focus=(0.5, 0.38)) -> Image.Image:
|
|
iw, ih = img.size
|
|
scale = max(tw / iw, th / ih)
|
|
nw, nh = int(iw * scale + 0.5), int(ih * scale + 0.5)
|
|
img = img.resize((nw, nh), Image.Resampling.LANCZOS)
|
|
cx, cy = int(nw * focus[0]), int(nh * focus[1])
|
|
left = max(0, min(cx - tw // 2, nw - tw))
|
|
top = max(0, min(cy - th // 2, nh - th))
|
|
return img.crop((left, top, left + tw, top + th))
|
|
|
|
|
|
def find_font(size: int):
|
|
for p in [
|
|
r"C:\Windows\Fonts\impact.ttf",
|
|
r"C:\Windows\Fonts\arialbd.ttf",
|
|
r"C:\Windows\Fonts\seguibl.ttf",
|
|
r"C:\Windows\Fonts\arial.ttf",
|
|
]:
|
|
if os.path.exists(p):
|
|
try:
|
|
return ImageFont.truetype(p, size)
|
|
except OSError:
|
|
pass
|
|
return ImageFont.load_default()
|
|
|
|
|
|
def stroke_text(draw, xy, text, font, fill, stroke=(0, 0, 0), sw=5):
|
|
x, y = xy
|
|
for dx in range(-sw, sw + 1):
|
|
for dy in range(-sw, sw + 1):
|
|
if (dx or dy) and dx * dx + dy * dy <= sw * sw:
|
|
draw.text((x + dx, y + dy), text, font=font, fill=stroke)
|
|
draw.text((x, y), text, font=font, fill=fill)
|
|
|
|
|
|
def left_shade(img: Image.Image, width=620, max_a=155) -> Image.Image:
|
|
img = img.convert("RGBA")
|
|
sh = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(sh)
|
|
for i in range(width):
|
|
a = int(max_a * (1 - i / width) ** 1.2)
|
|
d.line([(i, 0), (i, H)], fill=(0, 0, 0, a))
|
|
for j in range(90):
|
|
a = int(50 * (1 - j / 90))
|
|
d.line([(0, H - 1 - j), (W, H - 1 - j)], fill=(0, 0, 0, a))
|
|
return Image.alpha_composite(img, sh)
|
|
|
|
|
|
def paste_soft(canvas: Image.Image, sub: Image.Image, x: int, y: int, fade=48) -> Image.Image:
|
|
canvas = canvas.convert("RGBA")
|
|
sub = sub.convert("RGBA")
|
|
mask = Image.new("L", sub.size, 255)
|
|
md = ImageDraw.Draw(mask)
|
|
for i in range(fade):
|
|
md.line([(i, 0), (i, sub.size[1])], fill=int(255 * (i / max(fade, 1))))
|
|
sub.putalpha(mask)
|
|
canvas.alpha_composite(sub, (x, y))
|
|
return canvas
|
|
|
|
|
|
def paint_hooks(img: Image.Image, lines: list, left=44, top=150) -> Image.Image:
|
|
img = left_shade(img)
|
|
d = ImageDraw.Draw(img)
|
|
y = top
|
|
for i, (text, size, color) in enumerate(lines):
|
|
font = find_font(size)
|
|
stroke_text(d, (left, y), text, font, color, sw=max(5, size // 12))
|
|
bb = d.textbbox((0, 0), text, font=font)
|
|
y += (bb[3] - bb[1]) + (10 if i == 0 else 4)
|
|
d.rectangle([left, y + 10, left + 120, y + 16], fill=(255, 255, 255, 220))
|
|
return img.convert("RGB")
|
|
|
|
|
|
def save(img: Image.Image, folder: Path, name: str) -> None:
|
|
img = ImageEnhance.Contrast(img).enhance(1.03)
|
|
img = ImageEnhance.Sharpness(img).enhance(1.06)
|
|
arr = cv2.cvtColor(np.asarray(img.convert("RGB")), cv2.COLOR_RGB2BGR)
|
|
imwrite_u(folder / name, arr, 96)
|
|
|
|
|
|
def build(
|
|
bg_bgr: np.ndarray,
|
|
person_bgr: np.ndarray,
|
|
lines: list,
|
|
person_w=0.56,
|
|
focus=(0.55, 0.30),
|
|
bg_focus=(0.42, 0.40),
|
|
crop_person=(0.30, 0.02, 0.98, 0.98),
|
|
) -> Image.Image:
|
|
bg_up = super_res(bg_bgr, max_in=900)
|
|
pers = crop_rel(person_bgr, *crop_person)
|
|
if pers.size == 0:
|
|
pers = person_bgr
|
|
person_up = super_res(pers, max_in=850)
|
|
|
|
bg = ImageEnhance.Color(to_pil(bg_up)).enhance(1.06)
|
|
person = ImageEnhance.Color(to_pil(person_up)).enhance(1.05)
|
|
canvas = fit_pil(bg, W, H, focus=bg_focus)
|
|
panel = fit_pil(person, int(W * person_w), H, focus=focus)
|
|
canvas = paste_soft(canvas, panel, W - panel.size[0] + 4, 0, fade=48).convert("RGB")
|
|
return paint_hooks(canvas, lines)
|
|
|
|
|
|
def save_abc(folder: Path, variants: list[tuple[str, Image.Image]]) -> None:
|
|
"""variants: [(YT_COVER.jpg, img), (YT_COVER_B.jpg, img), (YT_COVER_C.jpg, img)]"""
|
|
for name, img in variants:
|
|
save(img, folder, name)
|
|
# legacy alias
|
|
b = folder / "YT_COVER_B.jpg"
|
|
if b.exists():
|
|
shutil.copy2(b, folder / "YT_COVER_ALT.jpg")
|
|
|
|
|
|
T_NIGHT = [1.5, 3, 5, 7, 9, 12, 15, 18, 22, 28, 35, 42, 50, 60, 75, 90, 110]
|
|
T_DAY = [2, 4, 6, 8, 10, 14, 18, 24, 30, 40, 50, 65, 80, 100, 120]
|
|
|
|
|
|
def do_pack(
|
|
folder: Path,
|
|
clips: list[str],
|
|
times: list[float],
|
|
variants_spec: list[dict],
|
|
min_bright=32.0,
|
|
min_sharp=35.0,
|
|
) -> None:
|
|
frames = best_frames(folder, clips, times, top_k=max(3, len(variants_spec)), min_bright=min_bright, min_sharp=min_sharp)
|
|
outs = []
|
|
for i, spec in enumerate(variants_spec):
|
|
bg = frames[min(i, len(frames) - 1)]
|
|
person = frames[min(spec.get("person_idx", i), len(frames) - 1)]
|
|
img = build(
|
|
bg,
|
|
person,
|
|
spec["lines"],
|
|
person_w=spec.get("person_w", 0.56),
|
|
focus=spec.get("focus", (0.55, 0.30)),
|
|
bg_focus=spec.get("bg_focus", (0.42, 0.40)),
|
|
crop_person=spec.get("crop_person", (0.30, 0.02, 0.98, 0.98)),
|
|
)
|
|
outs.append((spec["name"], img))
|
|
save_abc(folder, outs)
|
|
|
|
|
|
def do_01(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261019_092345.mp4", "VID_20261019_091912.mp4", "VID_20261019_091618.mp4"],
|
|
T_NIGHT,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("NIGHT", 82, (255, 255, 255)), ("SCOOTER POV", 68, (255, 230, 80)), ("China After Dark", 34, (120, 220, 255))],
|
|
"crop_person": (0.28, 0.05, 0.95, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("ALONE", 82, (255, 255, 255)), ("IN CHINA", 74, (255, 230, 80)), ("Ride = Content", 34, (140, 255, 230))],
|
|
"crop_person": (0.15, 0.08, 0.80, 0.98),
|
|
"focus": (0.45, 0.40),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("THIS RIDE", 74, (255, 255, 255)), ("PAYS RENT", 74, (255, 90, 130)), ("YT Night Hustle", 34, (255, 230, 80))],
|
|
"crop_person": (0.35, 0.10, 0.98, 0.98),
|
|
"focus": (0.60, 0.35),
|
|
},
|
|
],
|
|
min_bright=22,
|
|
min_sharp=25,
|
|
)
|
|
|
|
|
|
def do_02(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
[
|
|
"VID_20261019_092727_0_2400x1344_ISO4037.mp4",
|
|
"VID_20261019_093126_0_2400x1344_ISO3720.mp4",
|
|
],
|
|
T_NIGHT,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("CROSSWALK", 74, (255, 255, 255)), ("AT NIGHT", 74, (255, 230, 80)), ("Real China Ride", 34, (140, 255, 230))],
|
|
"crop_person": (0.22, 0.05, 0.88, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("GREEN LIGHT", 70, (120, 255, 160)), ("GO", 90, (255, 255, 255)), ("Scooter City", 34, (255, 230, 80))],
|
|
"crop_person": (0.30, 0.08, 0.95, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("8 MIN", 86, (255, 255, 255)), ("NIGHT POV", 70, (255, 230, 80)), ("No Tourist Filter", 32, (255, 140, 180))],
|
|
"crop_person": (0.18, 0.10, 0.75, 0.98),
|
|
"focus": (0.40, 0.38),
|
|
},
|
|
],
|
|
min_bright=25,
|
|
min_sharp=30,
|
|
)
|
|
|
|
|
|
def do_03(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261020_034223.mp4", "VID_20261020_060822.mp4"],
|
|
T_DAY + T_NIGHT,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("DAWN", 86, (255, 255, 255)), ("CITY RIDE", 72, (255, 230, 80)), ("Before the Rush", 34, (255, 170, 200))],
|
|
"crop_person": (0.35, 0.02, 0.98, 0.95),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("MORNING", 78, (255, 255, 255)), ("CHINA", 78, (255, 230, 80)), ("Shop Signs Glow", 34, (140, 255, 230))],
|
|
"crop_person": (0.20, 0.05, 0.85, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("SCOUT", 82, (255, 255, 255)), ("FOOD STREETS", 64, (255, 90, 130)), ("Creator Habit", 34, (255, 230, 80))],
|
|
"crop_person": (0.40, 0.08, 0.98, 0.98),
|
|
},
|
|
],
|
|
min_bright=30,
|
|
min_sharp=45,
|
|
)
|
|
|
|
|
|
def do_04(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
[
|
|
"VID_20261020_230243.mp4",
|
|
"VID_20261020_201413.mp4",
|
|
"VID_20261020_214204_0_2400x1344_ISO100.mp4",
|
|
],
|
|
T_DAY,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("REAL CHINA", 74, (255, 255, 255)), ("DAY WALK", 74, (255, 230, 80)), ("Scooters + Shops", 34, (140, 255, 230))],
|
|
"person_w": 0.52,
|
|
"crop_person": (0.02, 0.02, 0.55, 0.98),
|
|
"focus": (0.40, 0.30),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("11 MIN", 86, (255, 255, 255)), ("STREET POV", 70, (255, 230, 80)), ("No Tourist Edit", 34, (140, 255, 230))],
|
|
"crop_person": (0.40, 0.05, 0.98, 0.98),
|
|
"focus": (0.55, 0.38),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("CITYWALK", 78, (255, 255, 255)), ("BEAUTY", 78, (255, 140, 180)), ("Life in China", 34, (255, 230, 80))],
|
|
"crop_person": (0.10, 0.05, 0.70, 0.98),
|
|
"focus": (0.45, 0.32),
|
|
},
|
|
],
|
|
min_bright=40,
|
|
min_sharp=55,
|
|
)
|
|
|
|
|
|
def do_05(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261021_044213.mp4", "VID_20261021_043500.mp4", "VID_20261021_044043.mp4"],
|
|
T_DAY,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("FOOD STREET", 72, (255, 255, 255)), ("NEON SNACKS", 68, (255, 90, 130)), ("Beef Noodles Ahead", 32, (255, 230, 80))],
|
|
"crop_person": (0.32, 0.02, 0.88, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("BEEF", 86, (255, 255, 255)), ("NOODLES", 78, (255, 230, 80)), ("Local Lunch Sign", 34, (140, 255, 230))],
|
|
"crop_person": (0.40, 0.05, 0.95, 0.90),
|
|
"focus": (0.55, 0.25),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("SHE WALKED", 74, (255, 255, 255)), ("THE FOOD LANE", 64, (255, 140, 180)), ("Citywalk Hunger", 34, (255, 230, 80))],
|
|
"crop_person": (0.28, 0.02, 0.80, 0.98),
|
|
"focus": (0.48, 0.28),
|
|
},
|
|
],
|
|
min_bright=35,
|
|
min_sharp=45,
|
|
)
|
|
|
|
|
|
def do_06(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261021_051155.mp4", "VID_20261021_051605.mp4", "VID_20261021_050159.mp4"],
|
|
T_DAY,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("CANTEEN", 82, (255, 255, 255)), ("LIFE", 86, (255, 230, 80)), ("Real China Lunch", 34, (160, 255, 240))],
|
|
"crop_person": (0.22, 0.02, 0.85, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("TRAY", 86, (255, 255, 255)), ("ECONOMY", 74, (255, 230, 80)), ("Creator Budget", 34, (255, 140, 180))],
|
|
"crop_person": (0.05, 0.10, 0.70, 0.95),
|
|
"focus": (0.40, 0.40),
|
|
"bg_focus": (0.35, 0.45),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("STAFF", 82, (255, 255, 255)), ("CANTEEN", 78, (255, 230, 80)), ("Alone Lunch POV", 34, (140, 255, 230))],
|
|
"crop_person": (0.30, 0.02, 0.90, 0.98),
|
|
"focus": (0.50, 0.28),
|
|
},
|
|
],
|
|
min_bright=45,
|
|
min_sharp=60,
|
|
)
|
|
|
|
|
|
def do_07(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261021_230159.mp4", "VID_20261021_230951.mp4", "VID_20261021_054147.mp4"],
|
|
T_NIGHT + T_DAY,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("UNDER $2", 86, (255, 230, 80)), ("FRIED RICE", 72, (255, 255, 255)), ("Night Cheap Eats", 34, (255, 140, 180))],
|
|
"crop_person": (0.18, 0.02, 0.88, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("WOK", 90, (255, 255, 255)), ("MASTER", 78, (255, 230, 80)), ("Menu Under $3", 34, (140, 255, 230))],
|
|
"crop_person": (0.25, 0.05, 0.85, 0.95),
|
|
"focus": (0.48, 0.30),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("NIGHT", 82, (255, 255, 255)), ("SMILES", 82, (255, 140, 180)), ("Street + Bowl", 34, (255, 230, 80))],
|
|
"crop_person": (0.20, 0.02, 0.90, 0.98),
|
|
"focus": (0.50, 0.28),
|
|
},
|
|
],
|
|
min_bright=35,
|
|
min_sharp=45,
|
|
)
|
|
|
|
|
|
def do_08(folder: Path) -> None:
|
|
do_pack(
|
|
folder,
|
|
["VID_20261022_052232.mp4", "VID_20261022_045948.mp4", "VID_20261022_231736.mp4"],
|
|
T_NIGHT + T_DAY,
|
|
[
|
|
{
|
|
"name": "YT_COVER.jpg",
|
|
"lines": [("MALATANG", 82, (255, 55, 80)), ("NIGHT", 82, (255, 255, 255)), ("Steam + Neon", 34, (255, 230, 80))],
|
|
"crop_person": (0.30, 0.02, 0.98, 0.98),
|
|
},
|
|
{
|
|
"name": "YT_COVER_B.jpg",
|
|
"lines": [("DAY→NIGHT", 70, (255, 255, 255)), ("FOOD LOOP", 70, (255, 230, 80)), ("Canteen to Market", 32, (140, 255, 230))],
|
|
"crop_person": (0.15, 0.05, 0.80, 0.98),
|
|
"focus": (0.45, 0.35),
|
|
},
|
|
{
|
|
"name": "YT_COVER_C.jpg",
|
|
"lines": [("SPICY", 86, (255, 55, 80)), ("STEAM", 86, (255, 255, 255)), ("Click for Chaos", 34, (255, 230, 80))],
|
|
"crop_person": (0.35, 0.05, 0.98, 0.95),
|
|
"focus": (0.58, 0.32),
|
|
},
|
|
],
|
|
min_bright=30,
|
|
min_sharp=40,
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
get_sr()
|
|
jobs = [
|
|
(("091618", "092345"), do_01, "01"),
|
|
(("092727", "093126"), do_02, "02"),
|
|
(("034223", "060822"), do_03, "03"),
|
|
(("194952", "201413"), do_04, "04"),
|
|
(("043500", "044213"), do_05, "05"),
|
|
(("050159", "051605"), do_06, "06"),
|
|
(("054147", "230159"), do_07, "07"),
|
|
(("045948", "052232"), do_08, "08"),
|
|
]
|
|
out = ROOT / "_cover_out"
|
|
out.mkdir(exist_ok=True)
|
|
for tokens, fn, label in jobs:
|
|
folder = find_folder(*tokens)
|
|
if not folder:
|
|
print("MISS", label)
|
|
continue
|
|
try:
|
|
print(f"... {label} {folder.name}")
|
|
fn(folder)
|
|
for name in ("YT_COVER.jpg", "YT_COVER_B.jpg", "YT_COVER_C.jpg"):
|
|
src = folder / name
|
|
shutil.copy2(src, out / f"{label}_{name}")
|
|
print(f" {name} {src.stat().st_size}")
|
|
except Exception as e:
|
|
print("FAIL", label, e)
|
|
traceback.print_exc()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|