Fetch title, thumbnail, and channel

The transcript gives us text. The UI also needs a title, a channel name, and a thumbnail to render a decent video card. YouTube exposes all of this through a free oEmbed endpoint that does not require an API key.

metadata.py
python
import requests


def fetch_metadata(video_id: str) -> dict:
    """Fetch video metadata using YouTube oEmbed API."""
    oembed_url = (
        f"https://www.youtube.com/oembed?"
        f"url=https://www.youtube.com/watch?v={video_id}&format=json"
    )
    try:
        resp = requests.get(oembed_url, timeout=8)
        if resp.status_code == 200:
            data = resp.json()
            thumbnail = f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg"
            return {
                "title": data.get("title", "Unknown Title"),
                "author": data.get("author_name", "Unknown Channel"),
                "thumbnail_url": thumbnail,
                "video_id": video_id,
                "url": f"https://www.youtube.com/watch?v={video_id}",
            }
    except Exception:
        pass

    # Fallback: minimal info still useful for rendering
    return {
        "title": f"Video ({video_id})",
        "author": "Unknown",
        "thumbnail_url": f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg",
        "video_id": video_id,
        "url": f"https://www.youtube.com/watch?v={video_id}",
    }

oEmbed is a tiny open standard. One GET request, one JSON response, no auth. The thumbnail comes from a predictable img.youtube.com URL, so we build it by hand.

Quiz: Quiz

Loading practice…

Checkpoint: Ingestion checkpoint

Loading practice…