yt-dlp is a free and open-source command-line tool that can be used to download videos from YouTube and other video hosting websites. yt-dlp is a fork of the now-discontinued youtube-dlc, with the goal of adding new features and patches while also staying compatible with the original project. It supports a wide range of video and audio formats, and it can also be used to download subtitles and metadata. yt-dlp is available for Windows, macOS, and Linux.
# To download a video or playlist (with the default options from command below):
yt-dlp "<https://www.youtube.com/watch?v=oHg5SJYRHA0>"
# To list the available downloadable formats for a video:
yt-dlp --list-formats "<https://www.youtube.com/watch?v=oHg5SJYRHA0>"
# To download a video or playlist using the best MP4 video available (default is "bv\*+ba/b"):
yt-dlp --format "<bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]>" "<https://www.youtube.com/watch?v=oHg5SJYRHA0>"
# To extract audio from a video (requires ffmpeg or ffprobe):
yt-dlp --extract-audio "<https://www.youtube.com/watch?v=oHg5SJYRHA0>"
# To specify audio format and audio quality of extracted audio (between 0 (best) and 10 (worst), default = 5):
yt-dlp --extract-audio --audio-format <mp3> --audio-quality <0> "<https://www.youtube.com/watch?v=oHg5SJYRHA0>"
# To download all playlists of a YouTube channel/user keeping each playlist in a separate directory:
yt-dlp -o "<%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s>" "<https://www.youtube.com/user/TheLinuxFoundation/playlists>"
# To download a Udemy course keeping each chapter in a separate directory:
yt-dlp -u <user> -p <password> -P "<path/to/directory>" -o "<%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s>" "<https://www.udemy.com/java-tutorial>"
# ---
# To download a video:
yt-dlp <video_url>
# To download a playlist:
yt-dlp <playlist_url>
# To select the best quality:
yt-dlp -f best <video_url>
# To select specific format:
yt-dlp -f <format_id> <video_url>
# To download only audio:
yt-dlp -f bestaudio <video_url>
# To limit download speed:
yt-dlp -r 50K <video_url>
# To resume download:
yt-dlp -c <video_url>
# To download by file extension:
yt-dlp --format mp4 <video_url>
# To set size limit:
yt-dlp --min-filesize 100M <playlist_url>
# To download thumbnails:
yt-dlp --ignore-errors --write-thumbnail --skip-download $1 $2 $3 <video_url>