---
type: "Source File"
title: "\"\"\"Seed YouTube videos via home1 Whisper proxy + MiniMax scoring.\"\"\""
description: "\"\"\"Seed YouTube videos via home1 Whisper proxy + MiniMax scoring.\"\"\" import os import sys import json import re import sqlite3 import requests from datetime import datetime sys.path.insert(0, os.path.dirname(__file__))."
resource: "https://uk.copecheck.com"
tags: ["copecheck", "uk", "source-file", "py"]
timestamp: "2026-05-09T09:00:38Z"
site: "uk"
source_path: "copecheck-uk/seed_yt_final.py"
---

# """Seed YouTube videos via home1 Whisper proxy + MiniMax scoring."""

Source path: `copecheck-uk/seed_yt_final.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-05-09T09:00:38Z`

```py
"""Seed YouTube videos via home1 Whisper proxy + MiniMax scoring."""
import os
import sys
import json
import re
import sqlite3
import requests
from datetime import datetime

sys.path.insert(0, os.path.dirname(__file__))
os.chdir(os.path.dirname(__file__))
from dotenv import load_dotenv
load_dotenv()

[redacted secret-like line]
MINIMAX_URL = "https://api.minimax.io/v1/chat/completions"
PROXY_URL = "http://100.126.77.97:5050"
DB_PATH = os.path.join(os.path.dirname(__file__), "data", "copecheck_uk.db")

VIDEOS = [
    "QUQsMZIAgls",  # Gary Stevenson
    "Ds3R8AckpXs",  # Owen Jones
    "Fn9A9o8HGjM",  # Tom Harwood
    "37HGgQWtIvU",  # Aaron Bastani
    "XV_B96fAzKs",  # Steven Bartlett
]

SYSTEM_PROMPT = """You are the UK Oracle of Obsolescence — a forensic analyst of British political and economic cope.

Score this YouTube video transcript for COPE content. Cope is defined as: deflection, scapegoating, denial of structural problems, magical thinking about solutions, or any rhetorical strategy that avoids confronting uncomfortable economic/political realities.

Analyse the transcript and return a JSON object with:
- cope_score: float 0-100 (0 = brutally honest, 100 = weapons-grade cope)
- summary: 2-3 sentence summary of the cope (or honesty) in this video. Sardonic, punchy tone.
- scapegoats: comma-separated list of who/what gets blamed
- cope_mechanisms: comma-separated list of specific cope techniques used
- key_quotes: list of 3-5 most cope-laden (or most honest) quotes from the transcript

Return ONLY valid JSON, no markdown formatting."""


def get_video_info(video_id):
    try:
        url = f"https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v={video_id}&format=json"
        resp = requests.get(url, timeout=10)
        if resp.status_code == 200:
            data = resp.json()
            return {"title": data.get("title", "Unknown"), "channel": data.get("author_name", "Unknown")}
    except Exception:
        pass
    return {"title": "Unknown", "channel": "Unknown"}


def get_transcript_whisper(video_id):
    """Get transcript via home1 Whisper proxy."""
    try:
        resp = requests.get(f"{PROXY_URL}/whisper/{video_id}", timeout=600)
        if resp.status_code == 200:
            data = resp.json()
            if data.get("ok"):
                print(f"  Whisper: {data.get('language')} ({data.get('language_prob')}) {data.get('length')} chars")
                return data["transcript"]
            else:
                print(f"  Whisper failed: {data.get('error','')[:100]}")
        else:
            print(f"  Proxy HTTP {resp.status_code}")
    except requests.Timeout:
        print(f"  Proxy timed out (10 min)")
    except Exception as e:
        print(f"  Proxy error: {e}")
    return None


def score_with_minimax(transcript, title, channel):
    user_prompt = f'VIDEO: "{title}" by {channel}\n\nTRANSCRIPT:\n{transcript[:15000]}'
    try:
        resp = requests.post(MINIMAX_URL, headers={
[redacted secret-like line]
            "Content-Type": "application/json"
        }, json={
            "model": "minimax-m2.7",
            "messages": [
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": user_prompt}
            ],
[redacted secret-like line]
        }, timeout=90)
        if resp.status_code != 200:
            print(f"  MiniMax error: {resp.status_code}")
            return None
        text = resp.json()["choices"][0]["message"]["content"].strip()
        # Strip think tags
        think_match = re.search(r'</think>', text)
        if think_match:
            text = text[think_match.end():].strip()
        if text.startswith("```"):
            text = re.sub(r"^```(?:json)?\n?", "", text)
            text = re.sub(r"\n?```$", "", text)
        json_match = re.search(r'\{[\s\S]*\}', text)
        if not json_match:
            print(f"  No JSON in response: {text[:200]}")
            return None
        return json.loads(json_match.group())
    except Exception as e:
        print(f"  MiniMax error: {e}")
        return None


if __name__ == "__main__":
    conn = sqlite3.connect(DB_PATH)
    conn.execute("""CREATE TABLE IF NOT EXISTS youtube_videos (
        video_id TEXT PRIMARY KEY, title TEXT, channel TEXT, url TEXT,
        transcript_length INTEGER, cope_score REAL,
        cope_summary TEXT, scapegoats TEXT,
        cope_mechanisms TEXT, key_quotes TEXT,
        submitted_by TEXT DEFAULT 'system',
        status TEXT DEFAULT 'pending', scored_at TEXT
    )""")
    conn.commit()

    for vid in VIDEOS:
        existing = conn.execute("SELECT video_id FROM youtube_videos WHERE video_id=?", (vid,)).fetchone()
        if existing:
            print(f"\n=== {vid}: already scored, skip ===")
            continue

        print(f"\n=== Scoring {vid} ===")
        info = get_video_info(vid)
        print(f"  Title: {info['title']}")
        print(f"  Channel: {info['channel']}")

        transcript = get_transcript_whisper(vid)
        if not transcript:
            print(f"  SKIP: no transcript")
            continue

        result = score_with_minimax(transcript, info["title"], info["channel"])
        if not result:
            print(f"  SKIP: scoring failed")
            continue

        print(f"  Cope score: {result.get('cope_score')}")
        print(f"  Summary: {result.get('summary','')[:150]}")

        conn.execute("""INSERT OR REPLACE INTO youtube_videos
            (video_id, title, channel, url, transcript_length, cope_score,
             cope_summary, scapegoats, cope_mechanisms, key_quotes,
             submitted_by, status, scored_at)
            VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)""", (
            vid, info["title"], info["channel"],
            f"https://www.youtube.com/watch?v={vid}",
            len(transcript), result.get("cope_score", 0),
            result.get("summary", ""), result.get("scapegoats", ""),
            result.get("cope_mechanisms", ""),
            json.dumps(result.get("key_quotes", [])),
            "system", "scored", datetime.utcnow().isoformat()
        ))
        conn.commit()
        print(f"  SAVED!")

    conn.close()
    print("\nDone!")
```
