I mainly copied code from the existing plugin, while trying to understand how the original beet plugin works, as well as the audiotools library. I actually used a lot of the code of the original plugin.
My idea was to make a new backend for the existing plugin, because that gives more choices to people: I tried to install gstreamer without success on mac os x, so I resorted to the audiotools module.
I thought about using that replaygain module separately, but it needs a PCM stream, so I need the rest of the library (or another one) to read the actual files (mp3, flac, etc.).
Feel free to use the code, I'll have a go at making it another backend for the replaygain plugin, anyway.