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.