youtube-dl not accepting playlist url

2.4k Views Asked by At

With this code

import os

with open('urls.txt') as f:
    for line in f:
            os.system("youtube-dl "+"--write-thumbnail "+"--skip-download "+"--yes-playlist " +line)

The first image in the playlist downloads, then I get an error message saying 'list' is not recognized as an internal or ex ternal command, operable program or batch file. In 'urls.txt' I have just one url of a Youtube playlist. The url is this:

https://www.youtube.com/watch?v=GA3St3Rf9Gs&list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm

It's cutting off input after the & symbol. If I replace 'list' in the url with 'foo' I get the same message. What do I do to make youtube-dl accept playlist URL?

4

There are 4 best solutions below

0
On

You can use the youtube_dl library directly in your script and pass the urls to download from.

import os
import youtube_dl

ydl_opts = {
    'writethumbnail': True,
    'skip_download': True,
    'noplaylist': False
}


with open('urls.txt') as f:
    sources = f.readlines()

with youtube_dl.YoutubeDL(ydl_opts) as ydl:    
    ydl.download(sources)
0
On

Your program has a major command injection security vulnerability. You have triggered this (with harmless code) by accident. You are executing

youtube-dl --write-thumbnail --skip-download --yes-playlist \
https://www.youtube.com/watch?v=GA3St3Rf9Gs&list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm

Since the ampersand is a command character in shell scripts, you're running two commands

youtube-dl --write-thumbnail --skip-download --yes-playlist \
    https://www.youtube.com/watch?v=GA3St3Rf9Gs

and

list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm

Since there is no program with that name, the second command will likely fail.

To fix this, use proper subprocess invocations with subprocess:

import subprocess

with open('urls.txt') as f:
    for line in f:
        subprocess.check_call([
            "youtube-dl",
            "--write-thumbnail", "--skip-download", "--yes-playlist",
            line])
0
On

in commandprompt , you just need to quote the url(with ampersand). You can try to escape the url(with ampersand) in the same way in python. Refer youtube-dl FAQ

0
On

All you have to do to fix this, quote the YouTube URL, as in:

yt-dlp --yes-playlist "https://www.youtube.com/watch?v=XArZ74galOE&list=PLDrswW4_QtejDZdLE4EOVXunQvqU18sPK"

Solved the problem.

Thanks to nav3916872