I've attached a slightly modified version of the script.
This version does NOT perform the clean up of "dead" files and/or empty collections by default (but you can switch them back on with "--c" and "--e" command-line options, respectively), and it also allows you to switch on/off the report generation ("--nr" options). I've also attempted to make the error handling on character encoding problems more robust: If it encounters one then it'll show an error message but carry on processing the collections if it can.
These changes should make it a bit friendlier if you have a lot of azw files, or other files with embedded metadata, and/or some "unusual" characters in author names, series, tags or book titles.
Unfortunately, I can't test this script at the moment as my Kindle is busy indexing and I don't want to interrupt it. So can somebody run this and make sure that it works (i.e. that I've not made any typos anywhere in the code) and let me know?