Restore music metadata after SSD loss

I had the same problem, in that I had a complete copy of my audio collection on my iPhone (X) but a fresh macOS installation with only old Music Library backup.

I had to use a third party tool. I couldn't get this to work with Music.app (previously iTunes.app), applescript, or any other free tool.

I ended up with iMazing.app (https://imazing.com/iphone-music-transfer) which did transfer over what was important for me: rating, play count, and for audiobooks the meta data where to resume playing and in what chapter. I got a 30% discount using University email address, and I have continued to use this tool, primarily now to backup my Call history and Messages history with images and other attachments. I am not affiliated with iMazing other as a user. There are a myriad tools to "backup iPhones" but it's a shady market when it comes to free tools. After some back on forth on reddit I concluded iMazing would deliver and it did. In the end I had some new music that wasn't synced over to the iPhone that I had to manually sync over later, but thats my fault and no single piece of software could fix that. Good luck!