Is it possible to create a plugin that can get the Discogs link for a release?
I have files fully tagged up with MBIDs. And on the MB Release page is a link to the Discogs page. I’d like to add that to my music files. Is this kind of data available to a Picard Plugin?
3 Likes
First thing to check is whether the Discogs relationship is returned by MusicBrainz - you might need to add related data.
If it is, then it should be relatively easy to write a Plugin that will extract the tag to a metadata variable.
You should be able to use the generic www tag WXXX in ID3 for this. I am not sure how good Picard’s ability is to handle a generic URL in metadata and write it to other formats. But personally (for what it is worth i.e. very little) I would be supportive of any PRs which attempt to increase the scope of data that can be written to the various tag formats, and very supportive of PRs which improve the consistency of tags being supported across multiple tagging formats.
1 Like
I’ve never got close to a plugin like this. So will need to look at some example code to work from. I started to look at your “Album Artist Website“ as it is grabbing extra data… but then realised it is going for Artist and not Release data. But closest I could find so far.
Where would I be able to check if the Discogs URL data is data that can be returned? I need to know it is possible before heading down the road.
I’ll write it to the same tag that other taggers like MP3TAG and Jaikoz use as they do something along these lines.
I was also thinking that a plugin that pulls URL data for a release could also be modified for other common items like Bandcamp, Spotify and stuff like that. So it would be a framework of use to others.
The only time I’ve worked on a plugin was expanding the one to strip Unicode characters. This is a jump up for me, so will be a bit of a slow side project.
Edit: Tried a bit of speed reading Picard source… guess I am outta luck as it doesn’t seem to pull that kind of extra data. Unless I am missing something.
Find out whether Discogs URLs are sent
- Turn on all Relations in Options.
- Turn on debug logging
- Load an album which has a Discogs URL
- Go to the debug log and find the MB call and copy it.
- Paste the URL into a browser to see the JSON/XML that gets returned.
- Search for “Discogs” to see if the relationship is sent.
Determine whether plugin needs to make an extra call
(Likely) If Discogs URL is in the MB response, then the plugin is simple - you only need the plugin to look through the response already returned and find the specific entry and put it into metadata.
(Less likely) If Discogs URL is NOT in the MB response, then you need to make an extra call to get the data from MB (as I did with Artists official website - but remember that is associated with the album artist record which is not part of the release record itself, whereas the Discogs record is a direct relationship) - but if it is not in the original MB response, then you need to make an extra API call to get the data (assuming that there is an API call which will return it) or worse still scrape the data from a web call.
The Artist Official Website plugin does the extra call BUT it also does a lot of stuff to 1) cache the results (because the same artist is across several albums) and 2) complex code to handle situations where you are simultaneously loading multiple albums from the same artist and want to avoid multiple calls for the same data because it isn’t cached yet (so you have to restrict it to a single call and return the results to multiple albums when you get the response). You don’t need any of this complexity when the extra data you want is for a single release.
Release vs. Release Group
Another complexity is that Discogs URLs can be associated with Releases and / or Release Groups, so you need to handle (and test) 3 use cases:
- Release only
- Release Group only
- Both
I hope that this explanation helps.
Incredibly helpful. Thank you. Once the day calms down and I find five mins to try this then I’ll walk through it. It makes sense on initial read.
I also realise the Artist Official Website plugin is way more complex as it is making calls on top of calls. The data I want should just be literally right there on the Release or not at all. Your code in that plugin is a basis to work from because if I can read and understand how that operates, I can then hack and slay it into the task I require.
I also know that every Release I have worked on in MB will have a URL as I make sure of this. I’ll not worry about the Release Group URL.
Yes, URL relationships are included in the query, so the Discogs links on releases should be in the resul.
For your use case you’ll need album metadata processor, see https://picard-docs.musicbrainz.org/en/appendices/plugins_api.html#album-metadata-example for a simple example.
The third parameter passed to the registered function (the one called release
in the example) holds the raw data from MB (the JSON data deserialized into a Python object).
See for example this API response: https://musicbrainz.org/ws/2/release/0a606073-cc75-3940-a52d-0823f0c4f06e?inc=url-rels&fmt=json
For the discogs URL you are looking for an entry inside the releases relations
list with a target-type of “url” and type “discogs”.
Some quick code to get this inside the album metadata processor:
discogs_url = None
if 'relations' in release:
for relation in release['relations']:
if relation['target-type'] == 'url' and relation['type'] == 'discogs':
discogs_url = relation['url']['resource']
break
2 Likes
Thank you to both of you. Had just done the debug log thing. Useful to know that is there.
Even better seeing your example, @outsidecontext. That is all the crumbs I need to get started. Sometimes the sticking points are just the names of things I am looking for.
Once I get some focus time in the week I’ll see what I can now create.
1 Like