There are a few way to do it. But you must have a sound card which is full duplex.
The simplest way is with windows sound recorder, you get wav files but you can convert these to MP3's.
You can use free recording software called audacity to simply record whatever your are listening to, you will then have to split, name and save the songs. Just set your sound card record settings what you hear
I use a program called replay music, it records names and splits the songs automatically. Not free but good software (like all good software it's worth the money £13) and I suppose you could get a dodgy versions somewhere.
This works digitally by capturing the stream so works with all sound cards.