Search code examples
pythonsubprocessyoutube-dl

Downloading youtube videos using python's subprocess


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!


Solution

  • 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)