Downloading youtube videos using python's subprocess

1.3k Views Asked by At

If I do this cmd :

youtube-dl -i -w "ytsearch:funny animals"

Then it will successfully download the first video file with query name funny animals but when I wrote the same thing using python code

from subprocess import call

command = 'youtube-dl -i -w ytsearch:funny animals'
call(command.split(), shell=False)

It downloads funny instead of funny animals . Please help!

1

There are 1 best solutions below

2
On BEST ANSWER

Your video name has a space in it... you could try splitting on a different delimiter instead.

command = 'youtube-dl|-i|-w|ytsearch:funny animals'
call(command.split('|'), shell=False)

More problems arise if your video name contains the same delimiters. A better solution would be to just pass the list explicitly:

call(['youtube-dl', '-i', '-w', 'ytsearch:funny animals'], shell=False)