youtube-dl & alternatives
#4
RE: youtube-dl & alternatives
I hate to say it, lunatic, but that script seems like an unnecessarily and overly complicated way of extracting audio from a YouTube video.  There's no need to use ffmpeg to convert to wav and then lame to encode to mp3; ffmpeg can create the mp3 directly.  There's no need to manually call ffmpeg; both youtube-dl and yt-dlp have built in options for post-processing downloads.  YouTube even offers downloads of the audio and video already separated.  And there's no need to use those shell expansions to get the title; there are formatting options for that. 

If m4a audio will suit you, you could simply do:
Code:
yt-dlp --format m4a https://www.youtube.com/watch?v=ytvideoid

If you really want mp3, the entire script can be replaced with:
Code:
yt-dlp --format bestaudio --extract-audio --audio-format mp3 --postprocessor-args "ExtractAudio:-b:a 256k" -o "%(title)s.%(ext)s" https://www.youtube.com/watch?v=ytvideoid

(NOTE:  watch for line-wrapping in the forum.  The above examples are each a single command line.)

The '--format bestaudio' part will download only the highest quality audio that YouTube has to offer, without the video.  Then '--extract-audio --audio-format mp3' will cause yt-dlp to automatically call ffmpeg and convert the downloaded audio to mp3.  Next, the '--postprocessor-args "ExtractAudio:-b:a 256k"' part ensures it creates a 256 kbps mp3 file, just like the '-b 256' in your lame command.  Finally '-o "%(title)s.%(ext)s"' causes yt-dlp to name the file just like your script would have, without the need for the extra parsing.

SGI:  Indigo, Indigo2, Octane, Origin 300
Sun:  SPARCstation 20 (x4), Ultra 2, Blade 2500, T5240
HP:  9000/380, 425e, C8000
Digital: DECstation 5000/125, PWS 600au
jpstewart
Developer

Trade Count: (1)
Posts: 444
Threads: 6
Joined: May 2018
Location: SW Ontario, CA
Find Reply
04-20-2022, 11:26 PM


Messages In This Thread
youtube-dl & alternatives - by jpstewart - 04-19-2022, 11:41 PM
RE: youtube-dl & alternatives - by Raion - 04-19-2022, 11:45 PM
RE: youtube-dl & alternatives - by lunatic - 04-20-2022, 12:53 AM
RE: youtube-dl & alternatives - by jpstewart - 04-20-2022, 11:26 PM
RE: youtube-dl & alternatives - by lunatic - 04-21-2022, 12:22 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)