I recently got fed up with corruption in my iTunes library resulting in predictable behaviour and crashes. Drastic action was called for, so I deleted the whole thing and started a new one. This meant that I lost all of my play counts (not the end of the world) and my star ratings (definitely a big problem!).
There didn’t seem to be anything out there which could take this information from the old .xml library file and transfer it into the new one. It’s the same mp3 files in each library, so surely it shouldn’t be too hard?
I eventually stumbled across an old post by Reinout van Rees, who had written a Python script to deal with the same situation. It didn’t quite do what I needed, but I played around a bit and have now put it on GitHub if anyone’s interested. The final XML output does need some tweaking, as iTunes doesn’t seem to like the plist format written out by the Python library, but it really is just a copy and paste job – see the Readme for more details.