No description
  • Python 39.9%
  • C# 31.2%
  • HTML 27.8%
  • Shell 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonas König 4a999677e0 Retry truncated responses and verbose downloads
- catch http.client.HTTPException so IncompleteRead/BadStatusLine retry
- capture yt-dlp stderr for retry classification in verbose mode
- print captured stderr when verbose
- bump plugin to 1.0.5.1
2026-10-21 17:43:47 +02:00
jellyfin Retry truncated responses and verbose downloads 2026-10-21 17:43:47 +02:00
.gitignore Add Jellyfin 12 plugin and multi-vendor hardware encoding 2026-10-21 13:23:42 +02:00
mediadl.py Retry truncated responses and verbose downloads 2026-10-21 17:43:47 +02:00
pyproject.toml Switch to uv-managed Python package 2026-10-20 19:20:36 +02:00
README.md Sanitize filenames and retry transient network failures 2026-10-21 17:43:02 +02:00
uv.lock Switch to uv-managed Python package 2026-10-20 19:20:36 +02:00

mediadl

Download an episode, a season, or a collection from the German/Austrian public mediatheks and mux it into one MKV containing:

  • best available video, encoded to H.265/HEVC 10-bit (visually lossless CRF 18)
  • all audio tracks the source exposes (German, original version, audio description, ...)
  • all subtitle tracks, converted to SRT
  • chapters, language tags, and track titles

Supported providers: ARD Mediathek, ZDF Mediathek, ORF ON. Other sites supported by yt-dlp also work for single videos and playlists.

Requirements

  • Python 3.10+
  • uv for the Python environment
  • ffmpeg and ffprobe installed as system packages, on PATH

mediadl only manages its Python dependency (yt-dlp) through uv. It does not download or bundle ffmpeg.

# Debian/Ubuntu
sudo apt install ffmpeg

# Arch
sudo pacman -S ffmpeg

# macOS
brew install ffmpeg

Install

uv sync
uv run mediadl --help

Optional global command:

uv tool install .
mediadl --help

Jellyfin plugin

Jellyfin 12 plugin: add the repository URL from jellyfin/manifest.json under Dashboard > Plugins > Repositories, install MediathekDL, and run a library/plugin restart. It adds a MediathekDL tab to the main menu drawer with a clean tabbed UI. No manual Python, uv, or ffmpeg installation is needed: the plugin downloads its runtime on first use and uses Jellyfin's ffmpeg.

The plugin exposes every CLI option in the dashboard: URLs, destination, quality, codec, encoder, CRF/preset, hardware quality, audio/subtitle selection, lossless, re-encode, cookies, section/limit, and dry run. It bundles the Python project and runs it through uv.

See jellyfin/README.md for prerequisites, hosting the manifest, and hardware encoding details.

Usage

# one episode
uv run mediadl 'https://on.orf.at/video/14338409'

# a whole ORF season (sendereihe = season/series page)
uv run mediadl 'https://on.orf.at/sendereihe/13899302/2hot2drive'

# an ARD season
uv run mediadl 'https://www.ardmediathek.de/serie/house-of-yang/staffel-1/Y3JpZDovL3N3ci5kZS9zZGIvc3RJZC8xOTIx/1'

# a ZDF season
uv run mediadl 'https://www.zdf.de/serien/doppelhaushaelfte-102?staffel=1'

# cap quality at 720p, choose a faster encoder preset, write to ./Serien
uv run mediadl -q 720 --preset medium -o ./Serien 'URL'

# Apple Silicon: force hardware HEVC and raise quality
uv run mediadl --encoder videotoolbox --vt-quality 70 'URL'

Some ORF titles are rights-restricted and their manifests contain only a 10-second placeholder. mediadl aborts that episode with an explicit error instead of saving a truncated file, and continues with the rest of a season.

Default output layout:

House of Yang/Season 01/House of Yang - S01E01 - Folge 1 Jessie [1080p].mkv

Important flags

Flag Meaning
-q best|worst|1080|720|540 quality cap; default best
-o DIR output directory
--crf 18 libx265 quality; lower = better/larger (software only)
--preset slow libx265 speed/efficiency preset (software only)
--encoder auto|libx265|videotoolbox|qsv|vaapi|amf|nvenc auto probes hardware (default)
--vt-quality 65 VideoToolbox quality 1-100, higher = better/larger
--hw-quality 22 QSV/VA-API/AMF/NVENC QP/CQ, lower = better/larger
--codec h265|copy re-encode to HEVC (default) or copy source codec
--lossless copy video; fails unless the source is already HEVC
--reencode re-encode even if the source is already HEVC
--audio all|first|deu audio-track selection
--subs all|none|deu subtitle selection
--overwrite replace existing files
--dry-run print format/track selection, download nothing
--list list resolved season entries
--section '*0-30' download only a section (testing)
--limit N process only the first N season entries
--cookies, --cookies-from-browser age/geo restricted content

Output names

File and folder names are sanitized before writing:

  • spaces become _
  • German umlauts and accents are transliterated (ä -> ae, é -> e)
  • other Unicode is removed or replaced
  • <>:"/\|?*, control characters, and repeated separators are replaced
  • names are capped at 160 characters and checked against Windows reserved names

Example: Tatort: Der Fall / Ümlaut becomes Tatort_Der_Fall_Uemlaut.

Retries

Transient network failures are retried automatically with backoff:

  • DNS failures, timeouts, connection resets, TLS/EOF errors
  • HTTP 429, 500, 502, 503, and 504
  • yt-dlp metadata and download failures
  • uv runtime download failures

Permanent failures such as 404, 403, DRM, and unsupported URLs are not retried. yt-dlp itself also retries fragments and continues partial downloads.

What the mediatheks provide

Measured against live content (October 2026):

Provider Video Audio Subtitles Notes
ORF ON HLS/DASH; 960x540 @ ~1.8 Mbit/s for most archive items, 720p @ ~3.2 Mbit/s, 1080p for some newer series one German AAC stereo track; some titles expose an extra Audiodeskription rendition VTT, SRT, TTML, SAMI, XML (VTT chosen) is_drm_protected is set on some films/sport; some manifests are 10 s "not available" placeholders
ARD up to 1920x1080 50 fps H.264 German AAC; audio description and original version are either extra HLS renditions or separate items TTML + VTT FSK-18 content may need cookies/login
ZDF 720p or 1080p H.264 separate AAC renditions for TV Ton and Audiodeskription XML/TTML + VTT, German and English some content is DRM-protected

ORF API responses also carry subtitle URLs in six formats; mediadl picks VTT and converts it to SRT for maximum player compatibility.

Hardware encoding

Software libx265 is CPU-only. mediadl probes real hardware encoders at startup and prints the resolved choice before any download:

encoder: hevc_videotoolbox (hardware, Apple VideoToolbox)
encoder: hevc_qsv (hardware, Intel Quick Sync)
encoder: hevc_vaapi (hardware, VA-API)
encoder: hevc_amf (hardware, AMD AMF)
encoder: hevc_nvenc (hardware, NVIDIA NVENC)
encoder: libx265 (software)
Platform Auto candidates
macOS Apple Silicon hevc_videotoolbox
Linux hevc_nvenc, hevc_qsv, hevc_vaapi
Windows hevc_nvenc, hevc_qsv, hevc_amf
Any, no working hardware libx265

auto runs a tiny test encode with each candidate and only selects one that actually works. Force a choice with --encoder libx265|videotoolbox|qsv|vaapi|amf|nvenc. --codec copy and --lossless skip encoding entirely.

Hardware quality controls:

  • VideoToolbox: --vt-quality 1-100, higher is better (default 65)
  • QSV / VA-API / AMF / NVENC: --hw-quality 0-51, lower is better (default 22)

--crf and --preset apply only to libx265. Hardware encoders are faster but less bit-efficient than libx265, so files are usually larger at the same perceived quality. Hardware encoding is still lossy; the only true-lossless path is --lossless on an already-HEVC source.

macOS notes: auto hardware selection applies only to native arm64 macOS. Intel macOS, or Python/ffmpeg under Rosetta, falls back to libx265; force --encoder videotoolbox only with a native arm64 ffmpeg. Use brew install ffmpeg and check:

ffmpeg -hide_banner -encoders | grep hevc_videotoolbox

If an automatic hardware encode fails, the tool deletes the partial output and retries once with libx265 when available. A forced hardware encoder never falls back.

Encoding: what "lossless" means here

H.264 → H.265 cannot be lossless. Audio is always stream-copied (zero loss), subtitles are only reformatted to SRT, and an already-HEVC source is stream-copied.

Software path (--encoder libx265):

  • x265, CRF 18, 10-bit (yuv420p10le), preset slow

Hardware path (when auto selects a hardware encoder):

  • hevc_videotoolbox, -q:v 65, 10-bit p010le / main10 when supported

--lossless enforces stream copy and refuses to re-encode an H.264 source. For software encoding, --crf 16 gives more headroom and --crf 20 smaller files.

Measured on the 4-core ARM machine used for development: a 20 s 1080p50 clip took 74 s with --preset slow and 24 s with --preset medium. A 45-minute 1080p episode therefore takes roughly 1.5 h (medium) to 2.8 h (slow). A full 11-minute 540p episode took 3m44s with --preset fast. Downloads are not the bottleneck; the software x265 encode is. On Apple Silicon the VideoToolbox path normally removes that bottleneck; actual speed depends on the Mac and source.

ORF sometimes returns a 10-second "video not available" manifest while the API still reports the full duration. mediadl discards candidates whose DASH fragments add up to less than 90% of the announced duration and, as a backstop, checks the downloaded video duration before muxing and tries the next candidate.

How it works

  1. Resolve collection pages:
    • ORF sendereihe/sammlung: parse the SSR HTML for /video/<id> links.
    • ARD serie/sendung/sammlung: yt-dlp playlist expansion.
    • ZDF serien?staffel=N: parse episode links, then filter by the season_number in each video's metadata.
  2. Extract metadata and formats with yt-dlp.
  3. Pick the best video under the quality cap, deduplicate audio renditions by language + kind, pick one subtitle per language.
  4. Download selected formats, extract each audio track, convert subtitles.
  5. Mux with ffmpeg: HEVC encode (or copy), -c:a copy, -c:s srt, chapters, per-track language/title metadata.

Limitations

  • DRM-protected titles are refused by yt-dlp. mediadl reports the error and continues with the rest of the season.
  • Geo-blocked content requires a suitable connection. ORF often serves a 10-second video not available placeholder; the tool detects it from the fragment metadata and from the downloaded duration, then aborts that episode rather than muxing a truncated file.
  • ARD sometimes publishes audio description or original version as separate items. For ARD season/series URLs mediadl discovers those siblings via the ARD API, pairs them by episode duration, and merges their audio and new subtitle languages into the main file. A single episode URL does not carry enough information to find its siblings, so only tracks present in that item are used.
  • ORF videos split into many segments without a combined version are skipped (rare; mostly live events).
  • Live streams are skipped.