python ~ youtube-dl: error: no such option: --audio-format

1.6k Views Asked by At

Here is my code :

call(['youtube-dl', '-i', '--extract-audio', '--audio-format mp3','-w','ytsearch:'+song ,'-o '+song2file(song)+'.%(ext)s'], shell=False)

Note:This is an implementation of this code : youtuble-dl -i --extract-audio --audio-format mp3 -w ytsearch:Wham Bam -o WhamBam.%(ext)s Where song = Wham Bam, When I run this cmd it works perfectly but the python implementation is not working.

On running it, it returns me this error:

youtube-dl: error: no such option: --audio-format

2

There are 2 best solutions below

0
On

Essentially the issue is coming from the fact that you're lumping arguments together in a list entry when they should be separate entries in the list for subprocess to handle them correctly.

In this example it would be something like this:

args= [
    '-i',
    '--extract-audio',
    '--audio-format',
    'mp3',
]
subprocess.call(args)

Notice that --audio-format and mp3 are separated

0
On

as part of solution, it better to format your string properly like this:

arg= ['-i', '--extract-audio', '--audio-format mp3','-w','ytsearch:'+song ,'-o 
'+song2file(song)+'.%(ext)s'];
yt-arg= " ".join(str(x) for x in arg);

then call it

subprocess.call(['youtube-dl', yt-arg], shell=False)

this already solve the problem you describe but it seems still have issue on the -o option. please remember to format your string properly, not carelessly.