Proposed Genre Mapping Plugin

Yes! This would be most helpful. For this purpose I’ve been using a large set of $replacemulti() functions in a taggerscript, e.g., $replacemulti(%genre%,Rhythm And Blues,R&B). But something with a better layout and multi-to-one capability (so “Format 2”) with (I would highly recommend this:) a number of out-of-the-box definitions would be great!

I agree, insofar as MB itself is concerned. But one benefit of a plugin like what @rdswift is proposing is that it will help standardize one’s genre tags across different databases. (I currently use MB and Wikidata.)

The lastFM plus plugin essentially consisted of functionality to get genre data from lastFM and a second set of functionality - including an Options UI - to simplify and make it consistent.

IMO this second set of functionality would make an excellent start to a generic plugin (that would run after all other genre plugins had completed) to make sense of a messy set of genres.

Useful points.

In general, I think two sets of features would be helpful. (I don’t know if any existing plugin does this already.)

  1. Checking genre / style tags from multiple sources and consolidating them into more standardized names/spellings.
  2. Using the above data to rank the tags in terms of most common to least. This could also possibly be used to only list those tags that are present in at least two sources.

I quite like this idea of comparing sources for common genre entries - in principle at least because I suspect that there would be lots of minor spelling changes that would need to be handled.

“C&W” vs. “Country and Western” for example.

But if the various genre lists are cleaned up and standardised before comparing, then I guess it could work.

Well, I finally got around to doing something about this, and have created a plugin. It’s still in pre-release status, but I think it’s ready for general use (testing). If you decide to give this a try, I would appreciate any feedback (good or bad) so that I can make any required changes before submitting it for consideration for inclusion on the “official” Picard plugins page. Thanks.


Genre Mapper [Download]

Overview

This plugin provides the ability to standardize genres in the “genre” tag by matching the genres as found to a standard genre as defined in the genre replacement mapping configuration option. Once installed a settings page will be added to Picard’s options, which is where the plugin is configured.

This plugin is set to run at low priority so that any other plugins that might affect the list of genres are processed first.


Settings

The settings panel allows the user to provide a list of the original/replacement pairs used to modify the genres provided in the “genre” tag. Each pair must be entered on a separate line in the form:

[genre_match_test_string]=[replacement_genre]

Supported wildcards in the test string part of the mapping include ‘*’ and ‘?’ to match any number of characters and a single character respectively. Blank lines and lines beginning with an equals sign (=) will be ignored. If the replacement part of the pair is blank, any matching genres will be removed. Case-insensitive tests are used when matching. Replacements will be made in the order they are found in the list.

There is also a setting which allows the user to choose whether or not to apply the first matching pair only, or continue processing the remaining pairs with the updated genre. By default, all of the pairs are processed.


Examples

Example 1

Suppose that you want to combine all the different types of rock genres (e.g. Country Rock, Hard Rock, Progressive Rock, Punk Rock, Rock ‘n’ Roll) into a single “Rock” entry. This could be done using the following matching pairs configuration:

=============================
= Combine all "Rock" genres =
=============================
*rock*=Rock

Example 2

Similar to Example 1, except that you want to keep “Punk Rock” separate from “Rock”. This could be done by enabling the “Apply only the first matching replacement” option and using the following matching pairs configuration:

====================
= Keep "Punk Rock" =
====================
punk rock=Punk Rock

=============================
= Combine all "Rock" genres =
=============================
*rock*=Rock

This would cause a genre of “Punk Rock” to match the first test, keep the genre as “Punk Rock” and stop processing that genre entry. If the “Apply only the first matching replacement” option was not enabled, processing would continue and the next match would change the genre to “Rock”.

Example 3

Similar to Example 2, except that you want to keep processing rather than stop on the first match. This could be done by disabling the “Apply only the first matching replacement” option and using the following matching pairs configuration:

================================================
= Keep "Punk Rock" as temporary "Temp1" tag so =
= that it doesn't match any following lines    =
================================================
punk rock=Temp1

=============================
= Combine all "Rock" genres =
=============================
*rock*=Rock

===========================================
= Additional processing pairs as required =
===========================================

==============================================
= Change the "Temp1" tag back to "Punk Rock" =
==============================================
temp1=Punk Rock

This would cause a genre of “Punk Rock” to match the first test, changing the genre to “Temp1” (not matched in any of the following processing pairs) and continue processing. The final processing pair matches the “Temp1” genre set earlier and changes the genre back to “Punk Rock”.

7 Likes

This is amazing - thank you.

1 Like

I havent tried it yet but looks promising, is it possible to set alias with 2 outcomes, like punk rock = rock, punk

1 Like

I don’t think so, but I suppose something could be added to allow multiple outcomes (separated by semicolons).

I presume this is intended to fill in for the $replace function on tagger scripts? I’ve used Hiccup’s script from the MusicBee forums, with a few changes.

I’ll have to give it a try anyhow. I do a lot of genre tagging by hand and submit them to MusicBrainz with my own plugin (which I need to make a post on, the Discord lot already know) so this should be useful.

Hi@all,

I’ve been using the plugin for a few days now and ran into a problem. Probably I am doing something wrong.

I have configured in the plugin (the following):

...
Synth-Pop=Synth Pop
Rock And Roll=Rock&Roll
...

This also works as long as the track has only one genre. It does not work for multiple genres per track:

What am I doing wrong?

with best
pixel24

First question is what does the log say? Are there any entries that might help explain what’s happening?

Second, you didn’t show the column with the tag names in your screenshot, so I’m having to guess. It appears that your list of genres are comma separated rather than semicolon separated which tells me that either:

  1. they are coming from the local file and not the information that Picard retrieves from MusicBrainz, or;
  2. there is some other plugin or script changing the Picard genre multi-value into a comma separated string.

In any event, the plugin is looking for list of genres to be the Picard standard multi-value format, with the items separated by a semicolon and space "; " (and not a comma and space). Because of this, the plugin is seeing the entire list of genres as a single entry, so of course it isn’t matching any of your match settings.

From the limited information you provided, that’s my best guess as to what is happening.

1 Like

I have set in MusicBrainz Picard that several genres should be separated by a comma.

Was that a mistake?

1 Like

Not a mistake, per se, but possibly the source of the problem.

Can you try changing this setting back to the default and see if that fixes the problem? Also, try setting the log level to “Debug”, and have a look at the log after processing the release that was causing the problem. There should be an entry saying something like “Genres updated from … to …”.

If it works properly with the separator setting changed back to the default, then there is a bug in the plugin that I’ll have to fix.

I tested it here and it is indeed a bug in the plugin. Thanks @pixel24 for bringing it to my attention.

I have submitted a patch to have it corrected in the official Picard plugins, but until that has been merged you can download the updated version from my repository on github.

If you still have problems with the updated plugin, please let me know. Thanks.

1 Like

Thank you very much! I will test it next week :slight_smile:

1 Like

Thanks for providing this plugin. I have downloaded and activated it and set up the simple example rule #1 that you include. After saving the options and restarting MB Picard, I see no entry under the context menu options for Plugins. Does the Genre Mapping plugin then run automatically in the background after scanning an album? If so, it is not working for me, because the genres retrieved from MB are still not consolidated according to the mapping rule. Any advice for a newbie? Thanks in advance.

If it is enabled and you don’t see the configuration panel in the option settings, then there’s something wrong. Have a look at your log and see if there are any error messages that might indicate what is causing it to fail.

The Genre Mapper plugin is enabled and I also see the configuration panel of the plugin under the Plugins.
I have selected the checkbox to enable genre mapping.
I pasted your first example into the replacement pairs text box. The two other check boxes for regex and stop at first match are NOT selected.
I saved the changes (“Make it so!”) and restarted Picard. I imported The Rolling Stones, Rewind album which I synced with MusicBrainz.
All thirteen tracks have multivalued Genre tags, such as “Rock; Rock Music” or “Hard Rock; Rock; Rock Music”.
Even after refreshing the album these genre assignments remain, whereas I would expect the plugin to have replaced all tags with “Rock”.
There is no context menu option under Plugins to manually run the Genre Mapper plugin. When should it execute the replacement mappings? Automatically or on demand?
If on demand, where do I select that?
PS There were no log entries regarding the plugin that I could find.
Thanks for your help.

Actually, looking now at the tags for Genre, I think the Genre Mapper plugin has just added “Rock” to the existing list of tags. Can that be? Example: “Pop Rock; Rock Music” has now been changed to “Pop Rock; Rock; Rock Music” (second entry added by the plugin). This is not the behaviour I would have expected.

I uninstalled the official version of the plugin and installed the latest version of the plugin from your GitHub repo. I now have version 0.5 installed. The same behaviour with multivalue genre tags is observed. It seems the plugin does not work with multiple genre values, even using the standard tag separator (“;”).