youtube-dl is a command-line program to download videos from YouTube.com and a few more sites.

Download youtube-dl directly

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

sudo chmod a+rx /usr/local/bin/youtube-dl

And then get the mp3 from a video

youtube-dl --extract-audio --audio-format mp3 <video URL>

 

More informatio

Youtube-dl site

Documentation