DEV Community

RobustTrueTry
RobustTrueTry

Posted on

Why Most Internet Archive Videos Break in Your Player

The Internet Archive holds millions of video files you can stream for free. The catch: a large fraction of them will fail in a plain <video> tag or ffplay. Wrong MIME types, missing derivatives, files that are MP4 in name only.

By the end of this article you'll be able to query the Archive's metadata API in Python, identify which files actually play, and stream them without downloading anything.

The failure you will hit

Ask the metadata API for an item and you get a file list. It looks authoritative. It isn't.

A typical item lists an original upload (an AVI, a Flash FLV, a VOB ripped from a DVD) plus auto-generated derivatives. Sometimes the derivative is missing. Sometimes the original is listed as h.264 but is actually something else. Your player fetches the file, buffers for a while, and fails with a generic media error.

The Archive stores checksums and file sizes in metadata, but it does not guarantee a playable derivative exists. The burden of checking falls on you.

Query the metadata API

Every item has a metadata endpoint that returns JSON, no authentication required for public items:

import json
import urllib.request

def fetch_metadata(identifier: str) -> dict:
    url = f"https://archive.org/metadata/{identifier}"
    with urllib.request.urlopen(url, timeout=30) as resp:
        return json.load(resp)

meta = fetch_metadata("some_video_identifier")
for f in meta.get("files", []):
    print(f.get("name"), f.get("format"), f.get("length"))
Enter fullscreen mode Exit fullscreen mode

The files array is where the real work happens. Each entry carries a format string like h.264 or MPEG4, a length field, and sometimes a sha1. Treat all of them as claims, not facts.

Filter for files that actually play

Browsers reliably play H.264 MP4 and WebM. Filter on both the format string and the file extension, then verify size so you can skip zero-byte stubs:

PLAYABLE = {"h.264", "512kb/mpeg4", "mpeg4", "webm"}
OK_EXT = (".mp4", ".webm", ".ogv")

def playable_files(meta: dict) -> list[dict]:
    server = meta["server"]
    directory = meta["dir"]
    out = []
    for f in meta.get("files", []):
        name = f.get("name", "")
        if f.get("format", "").lower() not in PLAYABLE:
            continue
        if not name.lower().endswith(OK_EXT):
            continue
        size = int(f.get("size", 0) or 0)
        if size == 0:
            continue
        f["url"] = f"https://{server}{directory}/{urllib.request.quote(name)}"
        out.append(f)
    return out
Enter fullscreen mode Exit fullscreen mode

Two details matter here. The server and dir fields tell you where the item lives; the Archive moves items between nodes, so hardcoding ia*.us.archive.org breaks. And length in these entries is often a string like "1234.5" or "20:34", so parse defensively.

Probe the file before you trust it

Format strings still lie. If you need certainty, run ffprobe against the streamed URL. It reads only enough bytes to map the container, so you never download the whole file:

ffprobe -v error -select_streams v:0 \
  -show_entries stream=codec_name,width,height \
  -of json "https://archive.org/download/ID/file.mp4"
Enter fullscreen mode Exit fullscreen mode
import subprocess, json

def probe(url: str) -> dict | None:
    cmd = [
        "ffprobe", "-v", "error", "-select_streams", "v:0",
        "-show_entries", "stream=codec_name,width,height",
        "-of", "json", url,
    ]
    try:
        out = subprocess.run(cmd, capture_output=True, text=True,
                             timeout=30, check=True)
        streams = json.loads(out.stdout).get("streams", [])
        return streams[0] if streams else None
    except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
        return None
Enter fullscreen mode Exit fullscreen mode

If probe returns None, fall back to the next candidate file in the list. This one check is the difference between a playlist that plays end to end and one that stalls on every third item.

Stream without downloading

The Archive supports HTTP range requests on most files. That means you can point ffmpeg, VLC, or a plain <video> tag at the URL directly. For server-side playout, pipe ffprobe-verified URLs into ffmpeg:

ffmpeg -re -i "https://archive.org/download/ID/file.mp4" \
  -c:v libx264 -preset veryfast -f flv rtmp://localhost/live/stream
Enter fullscreen mode Exit fullscreen mode

The -re flag makes ffmpeg read at native frame rate, which is what you want for a live-style playout rather than burning through the file as fast as it can decode.

Tradeoffs worth knowing

Approach Tradeoff Use when
Trust format strings Fast, fails silently on bad files Browsing, tolerance for skips
ffprobe every file Reliable, adds a network round trip Playlists, automated playout
Download locally Bulletproof, slow and heavy Permanent collections

Other failure modes to plan for:

  • Some items are access-restricted or lending-only; the metadata call succeeds but the file returns a 403.
  • Derivatives lag behind new uploads, sometimes for days.
  • files can list hundreds of entries for multi-part items; sort by name to keep disc order.

Cache metadata responses. Items change rarely, and polite clients keep the Archive fast for everyone.

Key takeaways

  • The metadata API's format field is a claim; verify playability with ffprobe before adding a file to any playlist.
  • Build file URLs from the item's own server and dir fields, never a hardcoded host.
  • HTTP range requests let you stream and probe without downloading, which keeps checks cheap.
  • Handle 403s and missing derivatives explicitly; both are common and neither shows up in the file listing.

Source

Free alternative TV network built from the Internet Archive's forgotten videos -- the source project inspired this piece; I added the metadata API mechanics, playability filtering, and streaming failure modes it doesn't cover.

Support this work

These write-ups are researched and published with no paywall, sponsor, or tracking. If one saved you an afternoon, a small tip keeps them coming.

USDT, USDC or USDD ยท TRC-20 (Tron)

TFTNsfyomKrnUutRjBTGVULp19ByW29KbY
Enter fullscreen mode Exit fullscreen mode

Top comments (0)