Files
MajorWiki/03-opensource/media-creative/yt-dlp.md
MajorLinux 31d0a9806d wiki: add yt-dlp article to media-creative section
Cover installation, Plex-optimized format selection, playlist
downloading, config file, and background session usage. Cross-reference
existing JS challenge troubleshooting article.

Article count: 32 → 33. Open source section: 5 → 6.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 00:33:58 -04:00

3.0 KiB

yt-dlp — Video Downloading

What It Is

yt-dlp is a feature-rich command-line video downloader, forked from youtube-dl with active maintenance and significantly better performance. It supports YouTube, Twitch, and hundreds of other sites.


Installation

Fedora

sudo dnf install yt-dlp
# or latest via pip:
sudo pip install yt-dlp --break-system-packages

Update

sudo pip install -U yt-dlp --break-system-packages
# or if installed as standalone binary:
yt-dlp -U

Keep it current — YouTube pushes extractor changes frequently and old versions break.


Basic Usage

# Download a single video (best quality)
yt-dlp https://www.youtube.com/watch?v=VIDEO_ID

# Download to a specific directory with title as filename
yt-dlp -o "/path/to/output/%(title)s.%(ext)s" URL

Plex-Optimized Download

For Plex direct play, you want H.264 video in an MP4 container with embedded subtitles:

yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' \
  --merge-output-format mp4 \
  -o "/plex/plex/%(title)s.%(ext)s" \
  --write-auto-subs --embed-subs \
  URL
  • -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/...' — prefer MP4 video + M4A audio; fall back to best available
  • --merge-output-format mp4 — merge streams into MP4 container (requires ffmpeg)
  • --write-auto-subs --embed-subs — download auto-generated subtitles and bake them in

Playlists and Channels

# Download a full playlist
yt-dlp -o "%(playlist_index)s - %(title)s.%(ext)s" PLAYLIST_URL

# Download only videos not already present
yt-dlp --download-archive archive.txt PLAYLIST_URL

--download-archive maintains a file of completed video IDs — re-running the command skips already-downloaded videos automatically.


Format Selection

# List all available formats for a video
yt-dlp --list-formats URL

# Download best video + best audio, merge to mp4
yt-dlp -f 'bestvideo+bestaudio' --merge-output-format mp4 URL

# Download audio only (MP3)
yt-dlp -x --audio-format mp3 URL

Config File

Persist your preferred flags so you don't repeat them every command:

mkdir -p ~/.config/yt-dlp
cat > ~/.config/yt-dlp/config << 'EOF'
-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio
--merge-output-format mp4
--write-auto-subs
--embed-subs
--remote-components ejs:github
EOF

After this, a bare yt-dlp URL uses all your preferred settings automatically.


Running Long Downloads in the Background

For large downloads or playlists, run inside screen or tmux so they survive SSH disconnects:

screen -dmS yt-download bash -c \
  "yt-dlp -o '/plex/plex/%(title)s.%(ext)s' PLAYLIST_URL 2>&1 | tee ~/yt-download.log"

# Check progress
screen -r yt-download
# or
tail -f ~/yt-download.log

Troubleshooting

For YouTube JS challenge errors, missing formats, and n-challenge failures on Fedora — see yt-dlp YouTube JS Challenge Fix.


Tags

#yt-dlp #youtube #video #plex #linux #media #dev-tools