Skip to content

Instantly share code, notes, and snippets.

@ibuys
Forked from harishkannarao/youtube-dl.md
Created October 22, 2020 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibuys/7e5615720851999a1265f14ee6e071b6 to your computer and use it in GitHub Desktop.
Save ibuys/7e5615720851999a1265f14ee6e071b6 to your computer and use it in GitHub Desktop.
youtube-dl

youtube-dl

youtube-dl is an opensource command line tool to download video or audio from online video streaming services.

Videos downloaded in mkv or webm extensions can be played by VLC Media player in all major devices and operating systems including iPhone, Android devices.

Tool website: https://youtube-dl.org/

This gist shows the example commands to use the tool and doesn't support or encourage piracy or violation of copyrights of the online streaming service or the author of the content

Installing youtube-dl:

Mac OS:

brew install youtube-dl

brew install ffmpeg

Ubuntu/Debian:

sudo apt-get install youtube-dl -y

sudo apt-get install ffmpeg -y

Windows:

choco install youtube-dl

choco install ffmpeg

Upgrade existing youtube-dl installations:

Mac OS:

brew upgrade youtube-dl

brew upgrade ffmpeg

Ubuntu/Debian:

sudo apt-get install --only-upgrade youtube-dl -y

sudo apt-get install --only-upgrade ffmpeg -y

Windows:

choco upgrade youtube-dl

choco upgrade ffmpeg

Check version:

youtube-dl --version

ffmpeg

The following commands are tested with:

  • youtube-dl version 2018.11.07
  • ffmpeg version 4.1

Examples

Download videos from playlist

youtube-dl --yes-playlist --ignore-errors --continue --no-overwrites --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Explanation of params:

  • --yes-playlist -> Download multiple videos if the url is a playlist
  • --ignore-errors -> Ignore errors like geo resitriction of a video or deleted video in a playlist and continue with rest of the playlist
  • --continue -> Resume if any of the video is partially downloaded in the local file system
  • --no-overwrites -> If a file is already downloaded in local file system, then skip the download
  • --output "~/Downloads/%(title)s.%(ext)s -> Specify the download directory with filename and extension extracted from the video
  • "{URL}" -> URL of the video or playlist

Download only audio as mp3 from playlist

Use --extract-audio --audio-format mp3 --format 'bestaudio' to extract only the audio information and store as mp3 file

youtube-dl --yes-playlist --ignore-errors --continue --no-overwrites --extract-audio --audio-format mp3 --format 'bestaudio' --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Download single video with default video and audio quality:

youtube-dl --ignore-errors --continue --no-overwrites --output "~/Downloads/%(title)s.%(ext)s" "{URL}" 

Download single video with best video and audio quality:

Use --format 'bestvideo+bestaudio' to download the video with best quality of audio and video

youtube-dl --ignore-errors --continue --no-overwrites --format 'bestvideo+bestaudio' --output "~/Downloads/%(title)s.%(ext)s" "{URL}" 

Download single video and encode it as mp4 video (takes more time)

Use --recode-video mp4 option to convert the downloaded file as mp4 format

youtube-dl --ignore-errors --continue --no-overwrites --recode-video mp4 --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Download single audio as mp3 from the video

youtube-dl --ignore-errors --continue --no-overwrites --extract-audio --audio-format mp3 --format 'bestaudio' --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Download videos in bulk from list of videos in a file

Use --batch-file batchlist.txt to capture the list of URLs in a separate lines in a text file and download them in batch

youtube-dl --ignore-errors --continue --no-overwrites --format 'bestvideo+bestaudio' --batch-file batchlist.txt --output "~/Downloads/%(title)s.%(ext)s"

Download video with subtitles

Use --write-sub to download the subtitle information along with the video

youtube-dl --write-sub --ignore-errors --continue --no-overwrites --format 'bestvideo+bestaudio' --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Download with proxy

Use --proxy "http[s]://[user:password@]proxyhost[:port]" to download a geo restricted video

youtube-dl --proxy "http[s]://[user:password@]proxyhost[:port]" --ignore-errors --continue --no-overwrites --format 'bestvideo+bestaudio' --output "~/Downloads/%(title)s.%(ext)s" "{URL}"

Convert mkv or webm file to mp4

ffmpeg -i input.mkv output.mp4 -hide_banner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment