Help With Replaygain Plugin

Hi,
Trying to use the replaygain plugin but i’m getting this message evertime

Could not calculate album gain for

I have metaflac.exe in the plugins folder (not sure this is correct) and have let plugin setting to default with no luck.
Also tried the full path C:\Users\myuser\AppData\Local\MusicBrainz\Picard\plugins\metaflac but getting the same result.

What am I doing wrong?

1 Like

is it doing that for just one album or more then one? have you tried reinstalling the pug-in or closed and reopened picard after installing it?

thats all i can do to help for now as im hitting the sack and have work in the morning.

Tried reinstalling the plugin with restarts of picard and still no luck.
Yes does it for every album

start picard with -d and this is the output

D: 15:53:32,954 ui.mainwindow.set_statusbar_message:340: Calculating album gain for Test"…
E: 15:53:32,955 util.thread.run:56: Traceback (most recent call last):
File “picard\util\thread.py”, line 52, in run
File “C:\Users\myuser\AppData\Local\MusicBrainz\Picard\plugins\replaygain.zip\replaygain_init_.py”, line 120, in calculate_albumgain
calculate_replay_gain_for_files(files, format
, self.tagger)
File “C:\Users\myuser\AppData\Local\MusicBrainz\Picard\plugins\replaygain.zip\replaygain_init_.py”, line 43, in calculate_replay_gain_for_files
decode_filename(b’ '.join(file_list)))
TypeError: sequence item 0: expected a bytes-like object, str found

D: 15:53:32,959 ui.mainwindow.set_statusbar_message:340: Could not calculate album gain for “Test”.

Am i correct that the metaflac.exe (and mp3gain etc) must be in the plugin folder?

yes if you installed it from the settings menu it will be in the correct place if you did not give that a go and see if it helps.

it looks like it is a problem with the coding (im not a coder tho so i may be wrong) im just making sure your running the newest vershon and that everything is in the correct place (it looks like it is but im just being on the safe side). so if you did install it from there then you will have to wait and see if someone with more knolage of code can help you.

Thanks for the reply, plugins i always install that way to make sure they work, but replaygain won’t work

Tried it with flac files (metaflac.exe) with mp3’s (mp3gain.exe) and with ogg files (vorbisgain.exe) al give the same message

1 Like

On Linux, the tools simply need to be in the user’s PATH, maybe this is the same for Windows?

Apart from that, I’d set up a workflow where cleaning up and replaygaining files is done before dragging the files into Picard and saving them to their final destinations. Doing ReplayGain within Picard is still something to get used to (you’d have to do it after saving, if I remember correctly), and the tools used all use the older ReplayGain algorithm, not the newer (and better) ReplayGain v2.

Shameless plug: You might want to check out loudgain and its accompanying script rgbpm for replaygaining your files. Uses ReplayGain 2 (EBU R128) and supports much more filetypes. Plus, Picard natively supports all RG tags generated by loudgain.

Were you able to resolve this problem?
I’m having the same issue…Can’t scan flac files.
MusicBrainz Picard Version 2.3.2, Replaygain plugin 0.1, metaflac.exe 1.3.2

Error/debug log shows:

E: 21:17:37,482 util.thread.run:64: Traceback (most recent call last):
  File "picard\util\thread.py", line 60, in run
  File "C:\Users\Mxx\AppData\Local\MusicBrainz\Picard\plugins\replaygain.zip\replaygain\__init__.py", line 120, in _calculate_albumgain
    calculate_replay_gain_for_files(files, format_, self.tagger)
  File "C:\Users\Mxx\AppData\Local\MusicBrainz\Picard\plugins\replaygain.zip\replaygain\__init__.py", line 43, in calculate_replay_gain_for_files
    decode_filename(b' '.join(file_list)))
TypeError: sequence item 0: expected a bytes-like object, str found

I am working on fixing this plugin now. Once I am done (in a day or two) I am happy to share this with anyone who wants to test it in advance of it appearing formally in the plugins repository.

Things fixed so far:

  • Enhanced description with download links for external executables
  • The above TypeError (very easy fix - change b’ ’ to ’ ')
  • The execution works for both albums and tracks for MP3 files providing that the file path / name doesn’t have Unicode characters
  • Output is sent to the Picard debug log not into a pop-up window - so we can see what the executables output if we need to debug

However, I still need to…

  • Make it work for files with unicode characters - these characters are getting garbled
  • Stop an empty window opening
  • Work out why the wrong tags are set for MP3s
  • Filter the messages so that e.g. % complete are not logged
  • Test with files other than MP3s
  • Tweak the options to give more flexibility to use different executables if you want / need to
  • See if we can include the executables in the plugin
3 Likes

Great to hear that!

As most of the tools this originally was using are kind of deprecated it would be awesome to look into basing this either on loudgain or regained.

Both are Python based, support different file formats and use the RG2 specs. I think both use ffmpeg, though, and the ffmpeg executable needs to be available. Ffmpeg can be a bit of a pain cross platform, but there is https://github.com/acoustid/ffmpeg-build/releases/ with optimized builds for audio decoding (used by fpcalc).

Not sure how to package up everything in the plugin ZIP file. Probably requires some unpacking into temporary storage logic. I once experimented with this for bundling a DLL in https://github.com/phw/picard-plugins/blob/opencc/plugins/opencc/opencc.py#L38 . All a bit hackish.

1 Like

Thanks Philipp - I will take a look at those.

1 Like

Taking all suggestions into account we need to:

a. Have a platform independent solution;
b. Ideally put the replay gain values into Picard tags and not write them to the file until they are saved in Picard.

https://github.com/kepstin/regainer seems to be the best option as it utilised mutagen - and it seems to me that the best approach is to take the regainer.py file and include it in the plugin as-is, and then for the plugin to call the routines contain therein within the thread they are already running on and to return the replaygain values to the calling main thread so that they can be inserted into the relevant track metadata objects. Since it calls ffmpeg, we will need to include your versions of ffmpeg in the plugin and include some code to check if we are running from inside a zip file and if so extract the required ffmpeg executable to the parent directory so we can execute it.

This doesn’t seem to me to be too hard if I can find the time to do it - but it is a non-trivial amount of work.

I am going to suggest that I create a PR for the fixes I have already achieved because it is better then the current solution.

3 Likes

Upon reflection, I think that it would be better NOT to use the code as-is - it imports stuff which may not be available in e.g. the Windows executable cut-down Python environment (like asyncio) but which would bypass anyway - and the logging is base Pyton not picard etc.

So I plan to import the code and hack it about.

Can you confirm that your version of ffmpeg contains full functionality and will work with this?

It’s not really my version, more luk’s one, but I helped update it last year (could do another update I guess). But yes, to answer your question this build should support all the relevant formats. It is also used by fpcalc (which gets statically linked against the libraries). So if something is not supported by the ffmpeg executable it would also be not supported by fpcalc for fingerprinting, so at least we have consistency :slight_smile:

I fully agree with your estimation of the features. Especially the part where it calculates values and only updates the tags in Picard first.

1 Like

Maybe a bit too late because totally forgot this bug, but version ReplayGain 0.3 seems to work fine. no errors