I've had this idea for a while now, and always wondered if a program like this existed, but never found anything like it.
The idea is a selfhosted service/script/daemon that connects to music streaming platforms APIs and automatically downloads your play history. You'd keep listening to your music library on the streaming service until you think you've built a big enough of an offline library and then just drop the streaming service.
This would be a great way to build a music library for people who want to drop streaming services but don't have a music library. I might just put something together myself.
Lidarr supports this with import lists and spotify. Specifically playlists rather than just listened history
https://wiki.servarr.com/lidarr/supported#lists