Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (12.7k points)

There's a couple of posts on downloading audio from YouTube utilizing youtube-dl, yet none of them are concrete or excessively supportive. I'm considering what the most ideal approach to do it from Python content is. 

Look at the below example,

import youtube_dl

ydl_opts = {}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:

    ydl.download(['

])

Clearly, in the event that you simply care about the audio, you'd preferably not download the entire video... 

The youtube-dl source is just so supportive (ie, not very). 

Anyone suggest to me how to write this code?

1 Answer

0 votes
by (26.4k points)

Try the following code:

from __future__ import unicode_literals

import youtube_dl

ydl_opts = {

    'format': 'bestaudio/best',

    'postprocessors': [{

        'key': 'FFmpegExtractAudio',

        'preferredcodec': 'mp3',

        'preferredquality': '192',

    }],

}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:

    ydl.download(['

])

This will actually download an audio document if conceivable/supportable. In the event that the document isn't mp3 as of now, the downloaded record be changed over to mp3 utilizing ffmpeg or avconv. For more data, allude to the format and postprocessors documentation passages in a current version of the youtube-dl.

Interested to learn python in detail? Come and Join the python course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Mar 3, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Jul 30, 2019 in Python by Eresh Kumar (45.3k points)

Browse Categories

...