As Tuvok indicates, 'stream ripping' is most definitely illegal in the vast majority of cases. I do it occasionally but try to do so only when the music I want isn't currently commercially available. (e.g. works by youth choirs, etc, or tracks that were only ever released on 78rpm records).
Some (many?) of the online sites offering to convert YouTube videos can be decidedly dodgy (risking your computer getting infected with malware) but the options lists by PC Mag should all be OK:
https://uk.pcmag.com/streaming-music-services/136386/how-to-convert-youtube-videos-to-mp3-files