How to use youtube-dl (command line) to download YouTube playlists and convert them to MP3

This article explains how to download the YouTube playlist with the best audio format using youtube-dl and convert it to MP3 (with FFmpeg, youtube-dl will automatically use FFmpeg for transcoding). For this you need youtube-dl with ffmpeg Installed on your system. Due to YouTube changes, youtube-dl is not working properly, so you need to install the latest version on your system. Since some Linux distributions usually take a while before updating youtube-dl, I recommend removing the installed youtube-dl package from the repository and following the instructions on youtube-dl for manual installation Download page.To download the entire YouTube playlist (not private) with the best available audio format, extract the audio, and then convert the resulting file to 160K MP3, use (this is a command, left-click three times to select the entire command) :

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist ''

Command description:

  • --ignore-errors Make youtube-dl continue to play in case of errors, such as skipping deleted or unavailable videos from your playlist from your playlist
  • --format bestaudio Download the best available audio quality format
  • --extract-audio As the name suggests, it extracts audio from video
  • --audio-format mp3 Specify audio format-mp3 in this case
  • --audio-quality 160K Specifies the audio quality that ffmpeg / avconv will use when converting to mp3 in this case. You can specify the exact bit rate, such as 128K, 160K, etc., or the VBR quality value is between 0 (best) and 9 (worst). The default is 5. So use “0” for best quality, but be aware that if the original quality is low, using “0” for audio quality results in unnecessary large files (not actually high quality) because of the source quality low). You can omit specifying audio quality, in which case youtube-dl will use the default “5” VBR quality
  • --output "%(title)s.%(ext)s" Representative Output file name template; In this case, it sets the file name to “video title.mp3” format. Without this option (by default), youtube-dl adds the video ID after the video name, and in most cases the video ID is not very beautiful
  • --yes-playlist This way, if the URL points to a video and a playlist, it will still download the entire playlist. This is useful because if you find a playlist on YouTube, click on the video in that playlist, then copy the URL and try to download the video using youtube-dl without having to --yes-playlist, Only one video will be downloaded, not the entire playlist. This way, in this case, you can still download the entire playlist.
  • '' Is the URL of the YouTube playlist you want to download. You need to replace it with the actual YouTube playlist URL. Add single quotes on Linux and double quotes on Windows Avoid problems In some cases (for example, even if you use quotes --yes-playlist Option (if the video URL contains an ampersand, download only one video).

It’s also worth noting that the original video will be deleted, so once the command finishes processing all the files, you will end up with only MP3 files.
Example # 1- Download a YouTube playlist and convert it to the highest quality .mp3:

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist 'https://www.youtube.com/list=PLdYwhvDpx0FI2cmiSVn5cMufHjYHpo_88'

Example # 2-Download a YouTube playlist and convert it to the highest available quality .mp3, even if the link points to both a YouTube video and a YouTube playlist (thanks --yes-playlist And we use single quotes around the YouTube URL):

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist 'https://www.youtube.com/watch?v=PsO6ZnUZI0g&list=PLdYwhvDpx0FI2cmiSVn5cMufHjYHpo_88'

Want to download only part of a YouTube playlist? Adopt --playlist-start NUMBER Specify the starting number and --playlist-end NUMBER Specifies the ending number of videos to download. For example, to download 5 to 10 videos from a YouTube playlist, use --playlist-start 5 with --playlist-end 10, like this:

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist --playlist-start 5 --playlist-end 10 ''

But what if you don’t have a regular YouTube playlist to download, but instead have a text file with a link to a YouTube video? You can download all YouTube links as text files in the following ways: --batch-file="/path/to/playlist.txt" Instead '':

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --batch-file="/path/to/playlist.txt"

Replace /path/to/playlist.txt And the path and name of the text file containing the YouTube video link.
For more information about youtube-dl, see its help (youtube-dl --help)with Project GitHub page.

Source

Sidebar