The quality of YouTube audio (and video) varies greatly. On many videos, you have the option to select the video resolution (240p, 360p, 480p, 720p, etc.) by clicking on the gear icon of the control bar. Selecting the highest possible video resolution will usually give a correspondingly higher audio bitrate, upwards of 192kbps, which can sound fairly good.
You can record (in realtime) the audio portion with free
Audacity recording software, available for both PC and Mac. On the PC platform, to record internal sounds you will need to set the Recording Device to "Stereo Mix", "Wave Out" or something similar depending on your particular setup.
I would assume recording any copyrighted material is not legal.
Steve