How to use yt-dlp to download videos and audio from the internet (Installing yt-dlp on Linux)


I can certainly help you with a tutorial on how to use yt-dlp to download videos and audio from the internet! In this comprehensive yt-dlp tutorial, we will explain what yt-dlp is, how to install it on Linux, and the most commonly used yt-dlp commands to download audio and video from various websites.

However, please note that downloading copyrighted content without permission from the content creator may infringe on their rights, which could lead to legal consequences. Always make sure you have the right to download and use the content before doing so.

What is yt-dlp?

Yt-dlp is a command-line program to download videos and audio from many different websites. It is an improved version of youtube-dl, which was taken down from GitHub. Yt-dlp supports a vast number of websites, and it’s regularly updated to keep up with changes on those platforms.

Installing yt-dlp on Linux using Pip:

1.Open Terminal:

Open your terminal emulator. You can do this by searching for “Terminal” in your applications menu.

2.Install Dependencies:

Before you install yt-dlp, you might need to install some dependencies like python3 and pip if you haven’t already. Run the following commands:

sudo apt update
sudo apt install python3 python3-pip

3.Install yt-dlp:

Once you have the dependencies installed, you can install yt-dlp using pip:

pip3 install --upgrade yt-dlp

Common yt-dlp Commands:

Here are some common commands you can use with yt-dlp to download videos and audio:

Download a Video:

yt-dlp

This will download the video with the best available quality.

Download Audio Only:

yt-dlp -x --audio-format mp3

This will download only the audio of the video in mp3 format.

Download Playlist

yt-dlp -x --audio-format mp3 -i

This will download all videos from the playlist in mp3 format.

Download Video with Specific Quality:

yt-dlp -f [format code]

Replace [format code] with the desired format code. You can get the format codes by running yt-dlp -F .

Download Subtitles:

yt-dlp --write-sub --sub-lang [language code]

Replace [language code] with the desired language code.

Download Video Thumbnail:

yt-dlp --skip-download --write-thumbnail

This will download the video thumbnail without downloading the actual video.

Remember to replace with the URL of the video you want to download.

Always check the terms of service of the website you are downloading content from to make sure you are compliant with their policies.


Output template examples

# Output template examples
$ yt-dlp --print filename -o "test video.%(ext)s" BaW_jenozKc
test video.webm    # Literal name with correct extension

$ yt-dlp --print filename -o "%(title)s.%(ext)s" BaW_jenozKc
youtube-dl test video ''_ä↭𝕐.webm    # All kinds of weird characters

$ yt-dlp --print filename -o "%(title)s.%(ext)s" BaW_jenozKc --restrict-filenames
youtube-dl_test_video_.webm    # Restricted file name

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
$ yt-dlp -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" "https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re"

# Download YouTube playlist videos in separate directories according to their uploaded year
$ yt-dlp -o "%(upload_date>%Y)s/%(title)s.%(ext)s" "https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re"

# Prefix playlist index with " - " separator, but only if it is available
$ yt-dlp -o "%(playlist_index&{} - |)s%(title)s.%(ext)s" BaW_jenozKc "https://www.youtube.com/user/TheLinuxFoundation/playlists"

# Download all playlists of YouTube channel/user keeping each playlist in separate directory:
$ yt-dlp -o "%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" "https://www.youtube.com/user/TheLinuxFoundation/playlists"

# Download Udemy course keeping each chapter in separate directory under MyVideos directory in your home
$ yt-dlp -u user -p password -P "~/MyVideos" -o "%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s" "https://www.udemy.com/java-tutorial"

# Download entire series season keeping each series and each season in separate directory under C:/MyVideos
$ yt-dlp -P "C:/MyVideos" -o "%(series)s/%(season_number)s - %(season)s/%(episode_number)s - %(episode)s.%(ext)s" "https://videomore.ru/kino_v_detalayah/5_sezon/367617"

# Download video as "C:\MyVideos\uploader\title.ext", subtitles as "C:\MyVideos\subs\uploader\title.ext"
# and put all temporary files in "C:\MyVideos\tmp"
$ yt-dlp -P "C:/MyVideos" -P "temp:tmp" -P "subtitle:subs" -o "%(uploader)s/%(title)s.%(ext)s" BaW_jenoz --write-subs

# Download video as "C:\MyVideos\uploader\title.ext" and subtitles as "C:\MyVideos\uploader\subs\title.ext"
$ yt-dlp -P "C:/MyVideos" -o "%(uploader)s/%(title)s.%(ext)s" -o "subtitle:%(uploader)s/subs/%(title)s.%(ext)s" BaW_jenozKc --write-subs

# Stream the video being downloaded to stdout
$ yt-dlp -o - BaW_jenozKc

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据