Skip to content

Instantly share code, notes, and snippets.

@alexishida
Last active February 27, 2023 00:19
Show Gist options
  • Select an option

  • Save alexishida/54846900d1e72c40973b7ab11ec3cad9 to your computer and use it in GitHub Desktop.

Select an option

Save alexishida/54846900d1e72c40973b7ab11ec3cad9 to your computer and use it in GitHub Desktop.
Cheatsheets youtube-dl
# Alternative
https://github.com/yt-dlp/yt-dlp
yt-dlp
# To download and convert playlist or single video to mp3
youtube-dl https://www.youtube.com/playlist?list=PLCnhZiYtwHAWvzliEFqWl48QTysDGgdj1 -v --ignore-errors --extract-audio --audio-format mp3
# To list all available formats of a video:
youtube-dl -F example.com/watch?v=id
# To download a video in 720p MP4:
youtube-dl -f 22 example.com/watch?v=id
# To download a video in 720p MP4 or WebM or FLV:
youtube-dl -f 22/45/120
# To download video + audio merged
youtube-dl -f bestvideo+bestaudio/best,bestaudio example.com/watch?v=id
youtube-dl -f ("bestvideo[width>=1920]"/bestvideo)+bestaudio/best example.com/watch?v=id
youtube-dl -f 'bestvideo+bestaudio/bestvideo+bestaudio' --merge-output-format mp4 'youtube_URL'
youtube-dl -f 137+140 "http://www.youtube.com/watch?v=id"
youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4 example.com/watch?v=id
# To download a video to /$uploader/$date/$title.$ext:
youtube-dl -o '%(uploader)s/%(date)s/%(title)s.%(ext)s' example.com/watch?v=id
# To download a video playlist starting from a certain video:
youtube-dl --playlist-start 5 example.com/watch?v=id&list=listid
# To simulate a download with youtube-dl:
youtube-dl -s example.com/watch?v=id
# To download audio in mp3 format with best quality available
youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 example.com/watch?v=id
# Extract audio from video (https://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs)
ffmpeg -i video.mp4 -f mp3 -ab 128000 -vn music.mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 128k -f mp3 sound.mp3
# Execute from docker
docker run -it --rm -v /storage/youtube-dl:/app -v /etc/locale.gen:/etc/locale.gen -v /etc/localtime:/etc/localtime:ro python:latest /bin/bash
PATH="/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/bin"
cd /app/videos
# For all video formats see
# http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment