Trying to add one of the two "music video for" from a Music Video entry via script

I am attempting to add Tags to a MP4 Video file so a program (actually a combination of Jellyfin/ErsatzTV) Can display Music video credits, like this. To test this I have been using this entry for the AJR music video Bang!

Picard actually does most of this on its own, the only info that isn’t added is the album which is listed as “[standalone recordings]”

However the Album the Video originally came out for IS listed on the musicbrainz entry for the video. It is listed under “music video for” which itself is listed under “Relationships”.

I was wondering if their was a way to use a script to add that info from the site to the album tag.

The two problems I can see are:
1: I’m not sure if theirs a script function that can do that.
2: Their are actually 2 entry’s in the “music video for” catagory. The album, and the entry for the song itself.

Thanks for any help.

Picard currently can’t follow this relationship to fetch another recording and then apply the data from it.

A Picard Python plugin could do it. But it’s actually quite a few steps it will take to get the data. It would need to

  • check for the “music video for” relationship on the reording
  • fetch the linked recording(s)
  • for each recording fetch the releases this recording appears on
  • apply some filtering to select the best fitting release
  • somehow apply the data to the original recording.

The last step would depend on what should actually be taken from the release or the audio recording. But at a minimum it could set the album title.


Thank you, Sorry for not replying I thought I’d get like an email notification.

I might look into it. Unfortunately I can’t think of any other service to add meta data to music videos, The music video database’s lights are on but No one is home.

So I’m might actually look into that python method.

Are their any examples of it that you know of? If not that’s cool, I’ll go hunting for them either way.

EDIT: OH wait, When you say python script do you mean the built in script stuff? I didn’t realize that was python (Self taught coder >_>). In that case I’ll just scour the API I guess. Hopefully I find the right calls.

EDIT 2: Never mind, I dunno exactly what where talking about, but Imma follow this tutorial: Writing a Plugin — MusicBrainz Picard v2.9.1 documentation

1 Like

You’re on the right track :slight_smile: What you’ll need is a track metadata processor.

There are several plugins that you could use as an example.

I’m not sure if there is a good example that is similar to what you would need to do. It’s a bit more involved then most of the plugins.

The web request part is probably what is the least clear. Picard provides the webservice instance, but for the use case of querying the MB API you can use the more convenient MBAPIHelper wrapper. Below is a very rough idea on how this plugin could be structured to do that API call:

from functools import partial
from picard.metadata import register_track_metadata_processor
from picard.webservice.api_helpers import MBAPIHelper

def recording_request_finished(self, metadata, recording, http, error):
  # Callback called after the get_track_by_id webservice request finished
  # recording holds the data from the JSON response. Read album information from there
  # and fill it into metadata

def load_video_album_details(album, metadata, track, release):
    # 1. Search for the music video rel in track['relations']
    # 2. Do a request for a found recording MBID to get info about that recordings album
    api_helper = MBAPIHelper(album.tagger.webservice)
    api_helper.get_track_by_id(recording_mbid, partial(recording_request_finished, metadata))


I hope the above can get you started :smiley:

OK! Had some real life stuff happen. Back at it for a second.

On thing I wanted to clarify, is that I thought you could link albums to Videos in relations, you cannot. outsidecontext was saying this the whole time, and it went straight over my head.
(You actually CAN link an album to a video but only under the heading of “samples from / sampled by” in the release relations. Though it’s not what that’s for and I think using that relationship incorrectly is a big no no.)

Thusly I guess I could ask if linking Music videos to original release albums is possible. But since it’s such an edge use case, It seems unlikely that it would get far, especially since it’s just my silly idea and their a probably better additions people are campaigning for.

That being said, it should still be possible to make a python script that gets the PROBABLY correct album (I say probably because the operations I came up with are based on a lot of assumptions, which 9/10 times should be right.)

But I hit a snag again. I still haven’t figured out how the API works yet, so I wrote out the operations as text to see where I was going with this.

#if media is video
#   R = Relationship array
#   if R =! null
#       ID = music video for
#       rA = ID.Release array
#       if rA =! null
#           for i=0; i < Ra.entries; i++
#               rA[i]

In that for loop its supposed to take all the albums linked in the release array, filter out every type that isn’t “Album” (So for Bang! no “Singles” and no “Album + Compilation”)
Then it takes the remaining albums and sorts them by release date. Whichever one has the earliest release date is used, if theirs a tie whichever one of those that has the lowest position in the Array is used.

So Like I said, very inaccurate but SHOULD work most of the time?

The wall I’ve run into is I can’t seem to find the type for the albums. The best I’ve got is “type-id” which could be it?

I’m going to keep trying but I figured this topic could use an update with everything I’ve learned in case other people want to try to do this but better.

Thanks again for all the help.