for mp3 playback ,you first have to install the required plugins because they are not free and not included in ubuntu by default.
refet to this question to read more
enabling the multiverse source in your /etc/apt/source.list
and a simple
sudo apt-get update && sudo apt-get install ubuntu-restricted-extras
should get you going.
for Youtube videos , use youtube-dl , it's a python script
downloading is as simple as youtube-dl "youtube-video-url"
, by default it downloads the highest quality available.
it supports downloading from playlists,with subtitles and combining dash videos, meaning you can have a low quality video with high quality audio etc.
to see what formats exist for a video youtube-dl -F "utube-video-url"

you now just have to select the combinaison of video+audio you like
youtube-dl -f 135+171 "url"
or
youtube-dl -f 135+bestaudio "url"
youtube-dl -f worstvideo+171 "url"
this downloads the audio only, note that you won't have an mp3 file but either a .webm
, .mp4
or a .mp4a
with audio only.
youtube-dl -f bestaudio "url"