I am going to assume on Windows only?
Well, there are two orthogonal issues: one is Vista vs. earlier OSes, and the other is DRM vs. non-DRM audio.
For example, on Vista or higher, look into WASAPI (Windows Audio Session API) in CoreAudio. YOu can easily jack in and do some loopback recording. However, it won't work with DRMed audio.
On earlier versions of Windows, or with DRMed audio, you have to get much more exotic. You basically have to build a driver (a filter driver, I think). Not a quickie type task, that's certain.