How to set is_complete() tag into the metadata?

I’d like to set a custom defined tag to all mp3 files showing if the album is complete.

Therefore I’ve setup a simple plugin:

def set_complete_release_tag(album, metadata, *args):
    metadata["releasecompleteness"] = [album.is_complete()]

register_album_metadata_processor(set_complete_release_tag)

The plugins works - but only after a refresh of the already loaded albums.
How to get the metadata written at the first run?

I’ve tried to set the priority to low, without success.
Usage of the tagger script is also no option, because according to the documentation the is_complete() function works only in the file rename scripts.

That’s not really possible. It only works when refreshing the release with the files already matched because only in this case it is guaranteed that all the files are present.

One option could be to use register_file_post_addition_to_track_processor instead, then update the tag for all files of the album every time this runs. Something roughly like this:

from picard.file import register_file_post_addition_to_track_processor

def set_complete_release_tag(track, file):
    album = track.album
    for file in album.iterfiles():
        file.metadata["releasecompleteness"] = album.is_complete()


register_file_post_addition_to_track_processor(set_complete_release_tag)

Not sure if this works, though. You need to try.

3 Likes

Works perfectly! Thanks for the hint and even more, thanks for this great software.

Just one restriction: If a file is moved from a complete album to another album, then the old album is not complete anymore. But the tags are not updated. To fix this, also register the same function to register_file_post_removal_from_track_processor.

3 Likes

Ah, yes. Forgot about the removal.

I’m glad this works, thanks for trying it. I just wrote this down here as an idea, I was totally unsure if it would do what it should :smiley:

2 Likes