Sign inSign up

haven/yt-dlp

By haven

•Updated 4 months ago

yt-dlp image and script wrapper to download youtube content for local consumption

Image
0

1.3K

haven/yt-dlp repository overview

⁠haven/yt-dlp

Containerized yt-dlp⁠ with aria2 acceleration and an opinionated wrapper script at /opt/scripts/yt-dlp.sh⁠.

Defaults favour playlist/file mode using /media/channel_list.txt and run in foreground for logs.

⁠Quick start (playlist mode – default)
  1. Create a host directory (i.e. /path/on/host) and a channel_list.txt file with one URL per line:

    https://www.youtube.com/@royalsociety/videos
    https://www.youtube.com/@GreatBigStory/videos
    
  2. Generate cookies.txt (on a laptop or desktop with a browser logged into youtube):

    yt-dlp --cookies-from-browser brave --cookies cookies.txt
    

    Copy cookies.txt to your '/path/on/host' folder.

  3. Run the container and mount your directory to /media:

    docker run --rm -it \
      -v /path/on/host:/media \
      haven/yt-dlp:latest
    

This will run /opt/scripts/yt-dlp.sh --foreground by default and read URLs from /media/channel_list.txt. By default it downloads items from the last 7 days; see env vars below to change this.

If you get 403 returns when downloading you likely need to re-generate the cookies.txt and try again.

⁠One-shot mode (single URL)

Pass a URL via --input-source and enable --oneshot (downloads all unless you also set a date filter):

docker run --rm -it \
  -v /path/on/host:/media \
  haven/yt-dlp:latest \
  --oneshot --input-source "https://www.youtube.com/@royalsociety/videos"
⁠Environment variables (overrides)

All key runtime settings can be overridden via Docker env vars or CLI parameters:

Environment VariableCLI ParameterDefault ValueExample ValuesDescription
YTDLP_DOWNLOAD_DIR--dir/media/srv/youtube, /downloadsDownload directory inside the container
YTDLP_INPUT_SOURCE--input-source${YTDLP_DOWNLOAD_DIR}/channel_list.txt/media/my_channels.txt, https://youtube.com/@user/videosFile path or direct URL
YTDLP_DAYS--days714, 30, 1Number of days to look back for downloads
YTDLP_ONESHOT--oneshotfalsetrue, falseEnable one-shot URL mode (bypasses file reading)
YTDLP_SUBTITLE_LANGS--subtitle-langsenen,es, en,de,frComma-separated subtitle languages
YTDLP_MIN_FREE_SPACE--min-free-space510, 20Minimum free space required (GB)
YTDLP_CODEC--codecmp4mp4, vp9, av1Video codec preference with intelligent fallbacks
YTDLP_FOREGROUND--foregroundfalsetrue, falseConsole logging vs. log file (container CMD uses --foreground)
YTDLP_DEBUG--debugfalsetrue, falseEnable verbose yt-dlp output
YTDLP_DRY_RUN--dry-runfalsetrue, falseSimulate downloads without downloading
YTDLP_USER_AGENT(built-in)Chrome UA"Mozilla/5.0..."Custom User-Agent string
YTDLP_PLAYLIST_END(built-in)105, 25, 50Limit playlist items processed
YTDLP_DOWNLOADER_ARGS(built-in)aria2c:-c -j 3 -s 3 -x 3 -k 1M...aria2c:-j 5 -x 5aria2c tuning parameters
YTDLP_FORCE_IPV4(built-in)truetrue, falseForce IPv4 connections

Examples:

docker run --rm -it \
  -v /srv/youtube:/media \
  -e YTDLP_DAYS=14 \
  -e YTDLP_CODEC=vp9 \
  -e YTDLP_SUBTITLE_LANGS="en,es" \
  haven/yt-dlp:latest

AV1 example (CPU encode, WebM output):

docker run --rm -it \
  -v /srv/youtube:/media \
  -e YTDLP_CODEC=av1 \
  haven/yt-dlp:latest
⁠Choosing a codec (MP4/H.264 vs VP9 vs AV1)

You can select the preferred codec via --codec {mp4|vp9|av1} or -e YTDLP_CODEC=.... The script will fall back smartly when the exact choice is not available.

OptionContainerVideo codecAudio (typical)HW decode support4K readinessCompression efficiencyCPU decode costCompatibilityWhen to choose
mp4MP4H.264 (x264)AAC (m4a)Excellent (nearly universal)GoodLowest of the threeLowestExcellent (devices, TVs, editors)Max compatibility, easiest playback/editing
vp9WebMVP9OpusGood on modern hardware (newer CPUs/GPUs)Very good~30–50% better than H.264MediumGood on modern players/browsersBalance of quality and size, modern playback
av1WebMAV1 (SVT-AV1 encode, dav1d decode)OpusLimited to newest GPUs/SoCs; software decode heavyExcellent (4K/8K)Best (often 20–30% better than VP9)HighBest on latest players/browsersArchival or bandwidth-sensitive use, modern environments

Notes:

  • The image enables software H.264 encoding (x264) and AV1 encoding (SVT-AV1). VP9 is available (libvpx) if needed, but default output is MP4/H.264 unless --codec is set.
  • Hardware acceleration is not enabled in this image; all encoding/decoding is CPU-only.
  • YouTube doesn’t serve MP3; typical audio is AAC (MP4) or Opus (WebM). No MP3 encoder is included.
⁠Volumes and permissions
  • The image declares VOLUME ["/media"]. Mount your host directory there.

  • Container runs as user 1000:1000 by default. Ensure the mounted host directory is writable by this UID/GID, or override at runtime:

    docker run --rm -it \
      --user $(id -u):$(id -g) \
      -v /path/on/host:/media \
      haven/yt-dlp:latest
    
⁠Volumes and permissions
  • The image declares VOLUME ["/media"]. Mount your host directory there.

  • Container runs as user 1000:1000 by default. Ensure the mounted host directory is writable by this UID/GID, or override at runtime:

    docker run --rm -it \
      --user $(id -u):$(id -g) \
      -v /path/on/host:/media \
      haven/yt-dlp:latest
    
⁠Cookies support (optional)

If a cookies.txt file exists at ${YTDLP_DOWNLOAD_DIR}/cookies.txt (default /media/cookies.txt), it will be used automatically. This is useful for authenticated or age-restricted content.

⁠Output layout

Files are written under ${YTDLP_DOWNLOAD_DIR} into folders by uploader and playlist, with metadata, description, info JSON, and embedded thumbnails/subtitles by default.

⁠Timezone
  • Date filtering (via YTDLP_DAYS) uses the container timezone. Set it explicitly if you need a specific zone:

    docker run --rm -it \
      -e TZ=Europe/London \
      -v /path/on/host:/media \
      haven/yt-dlp:latest
    
⁠Notes
  • By default the script filters to the last YTDLP_DAYS days in playlist mode. Set a different value with -e YTDLP_DAYS=30 or disable date filtering by using --oneshot for direct URLs.
  • The image includes a healthcheck that validates the presence of /opt/scripts/yt-dlp.sh, yt-dlp on PATH, and writa bility of /media.

Last Build⁠

Tag summary

Content type

Image

Digest

sha256:5dffcc5f1…

Size

188.9 MB

Last updated

4 months ago

docker pull haven/yt-dlp