User:Bogdanb/RatingsSubmitter

From MusicBrainz Wiki

Amarok-to-MusicBrainz Track Ratings Exporter

The script attached here can be used to submit the ratings in your Amarok database to MusicBrainz.

Technical Warnings:

  • The script only deals with ratings entered in Amarok on Linux. (It attempts to refuse working in other situations, but I might have messed up the tests.) It can probably be adapted easily enough for some other players and architectures, I just don't use any and won't change it without some testing.
  • I'm using Amarok version 2:1.4.10-0ubuntu3 on Ubuntu 8.10 (Intrepid Ibex). As far as I know it should work in other conditions, but it hasn't been tested yet.
  • The script only works if your Amarok uses the sqlite backed for the library. But see the first caveat.
  • It should be trivial to submit scores instead (the thing Amarok calculates by default based on your listening habits), but I don't use that so it doesn't.
  • I'm using the Python 2.5 version that came with my Ubuntu, no idea if it works with any other Python versions.
  • The script uses the Mutagen module to read MBIDs from the files. Mine is from the python-mutagen (version 1.14-1) package in Ubuntu Intrepid, never tested with anything else. I think all other Python modules are installed by default.
  • It also uses sqlite3 to get the ratings and wget to actually post them.
  • I've tested the script as well as I could, and I'm pretty sure it won't do anything to your music library, but don't come crying to me if it formats your computer and installs Windows Millennium Edition...
  • By the way, I'm an almost total Python n00b, so if the code does something really weird it's probably silly rather than smart. And don't blame me if it makes your head hurt. (But I welcome constructive criticism.)
  • I would have liked to have it run on test.musicbrainz.org by default, but it seems the current test version doesn't support the web service, at least not for ratings. If you have a test server available with the ratings service enabled I recommend you try the script there first.
  • I don't completely understand how Amarok stores things in its database, in particular with regards to music on different volumes, and missing files. The only effect I can see is that the script will tell you it can't find some files (check if they're really gone, if so you can ignore those messages), and that it found multiple different ratings for some files (no idea why; the script won't submit anything for those files, but will list them, so you can rate them by hand). Let me know if something really weird goes on in your case, though.
  • If you really want to know but don't care to read the source, the script uses sqlite3 to query the ratings from the database, then uses Mutagen to read the track MBIDs from the files, and then posts the ratings using wget to MusicBrainz' web service.
  • I've only tested the script extensively with mp3, flac and ogg files. It should also support wma (or asf) and m4a (iTunes files), but I haven't tested much since I don't have many such files. I think Mutagen can read other tags, but I don't think Picard can write MBIDs in them anyway.

Usage

  • Amarok has an 11-level rating system; even numbers between 0 and 10 represent score/2 stars, and odd numbers add a half-star to the next lowest even number. MusicBrainz currently only allows from zero to five full stars (zero meaning unrated). This means a lossy conversion needs to be made. You need to edit the script and choose how to make this conversion (two methods are already there, commented out; you can add yours if you want). Note that if you change your mind you can just re-run the script to update the ratings.
  • You need to edit the script to add your MusicBrainz username and password before running it. (I didn't add parameters because I don't like passwords getting in bash's history file.)
  • The script will not run until you do the above.
  • Note that the script will not prompt for anything if successfully run. It will do everything it can and at the end tell you what didn't work.
  • If you have many ratings it can take a long time to run (about a second for every dozen ratings). However it will tell you what it's doing, so if you see a lot of errors you can kill it. See above and below.
  • After it completes, the script will output a lot of messages, including a complete list of all errors it encountered and every rating it thinks it submitted successfully. See below, too.
  • It is strongly recommended to run the script with ./submit-amarok-ratings.py 3>&1 1>&2 2>&3|tee errors.txt. Technical note: the script does a few silly things with stdout to tell you what it's doing, and outputs the serious lists to stderr. This command line will save only stderr to a file, which allows you to read it later and investigate whatever seems suspicious. Note that at the end it has a lot of output, so if you don't put it in a file like this it's likely to drop out of your terminal's scroll-back buffer.
  • I recommend to have Amarok to rescan its library, let it finish, and then close Amarok before starting the script. You can probably safely restart Amarok once the script says it started to submit ratings.
  • The script will always do the entire job from start to end. It can't continue if interrupted, so if you stop it you'll have to wait for the entire thing again.
  • Attention: the script doesn't check for already-existing ratings on MusicBrainz, so it will silently overwrite any ratings you already put on the server!
  • I don't have a script that updates ratings yet (and may never have, since I think I'll switch to Songbird), so you might need to run it periodically. See above, though.
  • The script only rates songs. AFAIK Amarok doesn't have ratings for releases, artists or labels, so I don't do that. If you think up any automatic way of determining that based on the songs, let me know, I might add it. (Or add it yourself.)

Discussion

  • nothing yet