python - --extract-audio equivalent for YoutubeDL class? -
i want extract audio in mp3 format youtube links, can't figure out how without calling youtube-dl
command line --extract-audio
option. there way within youtubedl
class similar examples given here?
here's have far, still creates mp4 file.
import youtube_dl # download using optimal audio settings ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'ffmpegextractaudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], 'quiet': true, 'restrictfilenames': true} ydl = youtube_dl.youtubedl(ydl_opts) ydl.download(['https://www.youtube.com/watch?v=pnt2cy5mwyw'])
clarification: above code generate mp3 file, generates mp4 video file. only want generate mp3.
update: here sample of output when quiet set false:
[youtube] et6sslen8le: downloading webpage [youtube] et6sslen8le: extracting video information [youtube] et6sslen8le: downloading dash manifest [download] destination: downloaded_tracks/et6sslen8le.m4a [download] 0.0% of 7.63mib @ 47.07kib/s eta 02:46 [download] 0.0% of 7.63mib @ 138.74kib/s eta 00:56 [download] 0.1% of 7.63mib @ 319.81kib/s eta 00:24 [download] 0.2% of 7.63mib @ 679.31kib/s eta 00:11 [download] 0.4% of 7.63mib @ 1.12mib/s eta 00:06 [download] 0.8% of 7.63mib @ 1.19mib/s eta 00:06 [download] 1.6% of 7.63mib @ 1.65mib/s eta 00:04 [download] 3.3% of 7.63mib @ 2.43mib/s eta 00:03 [download] 6.5% of 7.63mib @ 3.38mib/s eta 00:02 [download] 13.1% of 7.63mib @ 4.32mib/s eta 00:01 [download] 26.2% of 7.63mib @ 4.96mib/s eta 00:01 [download] 52.4% of 7.63mib @ 5.15mib/s eta 00:00 [download] 100.0% of 7.63mib @ 6.87mib/s eta 00:00 [download] 100% of 7.63mib in 00:01 [ffmpeg] correcting container in "downloaded_tracks/et6sslen8le.m4a" [avconv] destination: downloaded_tracks/et6sslen8le.mp3 deleting original file downloaded_tracks/et6sslen8le.m4a (pass -k keep)
this code should work fine. output if set quiet
false
? make sure using latest version of youtube-dl , have ffmpeg/avconv installed. ffmpeg/avconv should in path
or can explicitly specify location adding 'ffmpeg_location': '/path/to/directory/containing/ffmpeg/or/avconv'
ydl_opts
.
Comments
Post a Comment