205

I am trying to download all the videos from the playlist:

I am using youtube-dl for this and the command is:

youtube-dl -citk –format mp4 –yes-playlist https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2

But this only downloads the first video. Not sure what I am doing wrong.

Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
Dreams
  • 5,854
  • 9
  • 48
  • 71

8 Answers8

331

In a shell, & is a special character, advising the shell to start everything up to the & as a process in the background. To avoid this behavior, you can put the URL in quotes. See the youtube-dl FAQ for more information.

Also beware of -citk. With the exception of -i, these options make little sense. See the youtube-dl FAQ for more information. Even -f mp4 looks very strange.

So what you want is:

youtube-dl -i -f mp4 --yes-playlist 'https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2'

Alternatively, you can just use the playlist ID:

youtube-dl -i PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2
  • 1
    what about this C:\Users\lenovo\Desktop\New folder>youtube-dl -i PLD07B2225BB40E582 [youtube:playlist] PLD07B2225BB40E582: Downloading webpage [download] Downloading playlist: PLD07B2225BB40E582 [youtube:playlist] playlist PLD07B2225BB40E582: Downloading 0 videos [download] Finished downloading playlist: PLD07B2225BB40E582 //says finished downading but nothing is downloaded. – Micheal Brain Hurts May 29 '18 at 19:45
  • 2
    @userqrqh123 That sounds like a different question. Go ahead and [ask it](https://stackoverflow.com/questions/ask)! Don't forget to include the output when you add the `-v` option, because that will be vital in identifying where your problem is. `youtube-dl -i PLD07B2225BB40E582` works fine for me. –  May 29 '18 at 20:36
  • C:\Users\lenovo\Desktop\youtube-dl>youtube-dl -i PLD07B2225BB40E582 [youtube:playlist] PLD07B2225BB40E582: Downloading webpage [download] Downloading playlist: Fundamentals of Physics II with Ramamurti Shankar [youtube:playlist] playlist Fundamentals of Physics II with Ramamurti Shankar: Downloading 25 videos [download] Downloading video 1 of 25 [youtube] NK-BxowMIfg: Downloading webpage [youtube] NK-BxowMIfg: Downloading video info webpage [youtube] NK-BxowMIfg: Extracting video information ERROR: unable to open for writing: [Errno 2] No such file or directory: '1. Electrostati....... – Micheal Brain Hurts May 29 '18 at 21:08
  • 1
    @userqrqh123 As I said, a comment is not the place to discuss your unrelated problem. Please ask a question instead. In that question, please do include the output you get when you add `-v`. Also, you should probably decide which of the two outputs you are seeing right now - they are markedly different. –  May 29 '18 at 22:13
  • 4
    youtube-dl -x -i worked for me to convert a playlist into audio! – Gary Sep 21 '18 at 17:33
  • 3
    I also used `--no-check-certificate` – Gavin Palmer Dec 09 '18 at 20:15
  • 1
    to find the list id for use with -i, copy the ID after 'playlist=' – lobi Jul 06 '20 at 17:17
  • Is there is way to Join them in one file after download ? – Salem Jul 24 '20 at 11:36
  • Is it possible to download directly to mp3? – nilon Dec 23 '20 at 13:17
  • Nice tip about grabbing just the playlist id - hadn't thought of that, thanks! – JonTout Dec 12 '21 at 16:17
  • For a moment I thought you started the post saying: 'In a nut Shell'. Sorry I know this type of comment is not for Stacked :) – dorien Mar 01 '22 at 13:40
  • does --watched argument really work? – elakhdar_ayoub Aug 27 '22 at 01:59
39

I found the best solution after many attempts at solving this problem.

Installation and usage;

For Windows users:

Script:

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/playlist?list={your-youtube-playlist-id}
  • Download youtube-dl.exe file from the offical site.
  • Dowload ffmpeg from the offical site for convert WebM to MP3 (Recomended build version)
  • Exctract all zip files and move youtube-dl.exe, ffmpeg.exe and ffprobe.exe files to the folder that where you want the downloaded MP3 files.
  • Open cmd (Windows terminal) in same folder.
  • Replace the script {your-youtube-playlist-id} parameter with your YouTube playlist id.
  • Run the script.

For macOS/Linux users:

Script:

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/playlist?list={your-youtube-playlist-id}'
  • Open terminal and if you don't have Homebrew, install it. (Linux users can skip this step.)
  • Run brew install youtube-dl ffmpeg and install youtube-dl and ffmpeg for convert WebM to MP3. (Installation may take longer to install other dependencies.) (For Linux users: install youtube-dl ffmpeg)
  • Open a terminal in the folder where you want to download the MP3 files.
  • Replace the script {your-youtube-playlist-id} parameter with your YouTube playlist id.
  • Run the script.
Necip Sunmaz
  • 1,546
  • 17
  • 22
  • 1
    Did the trick. But had to pass in only the playlist ID – ci0ccarellia Feb 12 '21 at 15:55
  • 1
    Just say Linux users have to install youtube-dl and ffmpeg. There are many different distributions and only Debian uses apt. – Kleysley Feb 28 '22 at 09:23
  • @Kleysley That's right, I've updated my answers. Thanks for information. – Necip Sunmaz Feb 28 '22 at 09:49
  • Recommending `-o "%(playlist_index)s-%(title)s.%(ext)s"` for numbered files – mhchem Sep 03 '22 at 06:50
  • 1
    The asker didn't want to know how to download the audio (though useful) https://stackoverflow.com/a/48425625/1436129 is the right answer. Thanks for sharing though. – aubreypwd Dec 29 '22 at 06:04
  • @aubreypwd You're welcome. It didn't completely fix my problem when I tried the same thing. Then I read youtube-dl documentation and tried many things and found this solution. Hope this helps other people as well. – Necip Sunmaz Dec 29 '22 at 14:14
16

I have tried everything above, but none could solve my problem. I fixed it by updating the old version of youtube-dl to download playlist. To update it

sudo youtube-dl -U

or

youtube-dl -U

after you have successfully updated using the above command

youtube-dl -cit https://www.youtube.com/playlist?list=PLttJ4RON7sleuL8wDpxbKHbSJ7BH4vvCk
Spythonian
  • 197
  • 1
  • 7
  • 1
    If no autoupdate allowed (after removing installed one) use: `sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl` and `sudo chmod a+rx /usr/local/bin/youtube-dl` – Alex Szücs Nov 21 '20 at 13:06
  • You should never run youtube-dl with sudo! – aubreypwd Dec 29 '22 at 06:05
15

Some commands which you may find useful while downloading a playlist

Download a playlist

youtube-dl <playlist link>

Best quality video and best quality audio (merged ) + preferred resolution

youtube-dl -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>

This command will download videos in 1080p resolution if 1080p is available otherwise it will download the next best (less than 1080p) resolution. Here, You can use 480 or 720, etc instead of 1080.

Note: Make sure that ‘FFmpeg’ is installed, otherwise video and audio will not be merged.

Best quality video and best quality audio (merged ) + preferred resolution + Add video upload date on the file name

youtube-dl -o "[%(upload_date)s] %(title)s.%(ext)s" -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]'  <playlist link>

Best quality video and best quality audio (merged ) + Preferred resolution + Add video upload date on the file name + Add uploader name on the file name

youtube-dl -o "[%(upload_date)s] %(title)s [%(uploader)s].%(ext)s" -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>

Subtitle

Best quality video and best quality audio (merged ) + Preferred resolution + Download auto-generated Subtitle

youtube-dl --write-auto-sub -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]'  <playlist link>

Best quality video and best quality audio (merged ) + Preferred resolution + Download video creator’s uploaded subtitle

youtube-dl --write-sub -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>

Best quality video and best quality audio merged + Preferred resolution + Download video Creator’s uploaded specific language’s subtitle

youtube-dl --write-sub --sub-lang en -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]'  <playlist link>
Rasaf Ibrahim
  • 1,737
  • 14
  • 10
10

Your link is not a playlist.

A proper playlist URL looks like this:

https://www.youtube.com/playlist?list=PLHSdFJ8BDqEyvUUzm6R0HxawSWniP2c9K

Your URL is just the first video OF a certain playlist. It contains https://www.youtube.com/watch? instead of https://www.youtube.com/playlist?.

Pick the playlist by clicking on the title of the playlist on the right side in the list of videos and use this URL.

bomben
  • 590
  • 6
  • 16
3

Removing the v=...& part from the url, and only keep the list=... part. The main problem being the special character &, interpreted by the shell.

You can also quote your 'url' in your command.

More information here (for instance) :

https://askubuntu.com/questions/564567/how-to-download-playlist-from-youtube-dl

Pac0
  • 21,465
  • 8
  • 65
  • 74
1

The easiest thing to do is to create a file.txt file and pass the link url link so:

https://www.youtube.com/watch?v=5Lj1BF0Kn8c&list=PL9YFoJnn53xyf9GNZrtiraspAIKc80s1i

make sure to include the -a parameter in terminal:

youtube-dl -a file.txt
double-beep
  • 5,031
  • 17
  • 33
  • 41
chris mahn
  • 117
  • 1
  • 2
0

Basically, workaround for this problem could be simple replacing & symbol with it's encoded version %26

For those who are struggling with this problem while doing it through PHP (e.g. shell_exec()) , solution could be str_replace("&", "%26", $shell_command);

Sid
  • 4,302
  • 3
  • 26
  • 27