Proposed Genre Mapping Plugin

I’m considering developing a Picard plugin to allow mapping genre tags to standard values based on user-specified mapping criteria. Before I spend any time on it, I’m curious to know if anyone would find it useful to them. Personally, I try to avoid genres like the plague when it comes to tagging and organizing my music collection, but I know that it’s very important to others.

What I’m thinking of is to add a new scripting function $mapgenres() which would take a multi-value variable such as %genres% as an argument. The function would look up each item in the variable list to see if there is a match in the mapping list, and if found it would include the mapped item in the output. The function output would be a new multi-value variable.

For example, if %genres% contained an item “Prog Rock” and the user had mapped this to a standard replacement “Progressive Rock”, then the output would contain the replacement “Progressive Rock” rather than the original “Prog Rock”. If there was no match found in the mapping list, then the genre would be dropped from the output.

I envision the mapping file being a simple text file easily maintained by the user. There are a couple of ways that it could be formatted, such as:

Format 1

From1 => To1
From2 => To2
...

where each mapping pair appears on a separate line.

Format 2 (my personal favorite)

To1:
 - From1a
 - From1b
 - From1c
To2:
 - From2a
...

where each mapping group starts with the desired replacement, followed by a list of all the inputs that map to that target. This allows the user to more easily map multiple inputs to a single target output.

The output would use the case specified in the mapping list, but the input test comparison would be case-insensitive, and all duplicate outputs would be removed so that the resulting list would be unique.

The mapping file could either be specified as an argument to the function, or could default to a specific file genremap.txt in the default naming directory.

So what do you think? Is this something that anyone would find useful?

2 Likes

Considering this will probably be quite some work for you, I see one or two obstacles that might hinder it being enough useful/successful at this moment.

If a user retrieves the genres from MusicBrainz, the genres retrieved are (while limited) usually already in a decent format.
There are a couple I personally prefer differently, but a script can handle that.

If the user already has genres in his tags (perhaps retrieved elsewhere, Wikidata, Discogs, or manually entered etc.), and wants to update the file(s) using Picard, it is impossible to have Picard read the existing genre tags, retrieve genres from MusicBrainz, and then process those together.
(correct me if I am wrong?)
If that was possible, I think the plugin you are imagining/suggesting would be quite useful.

Ideally a genre plugin would additionally be able to retrieve genres from different sources in the same run, and process them together, including genres tags that are already in the file.

Note that I wrote this a bit impulsively as a first response.
I may have some facts wrong, and I may be wrong thinking such a plugin would not be very useful at this moment in time.
So take all this as some random thoughts on the matter in trying to give some input and possibly help in having a fruitful further discussion.

1 Like

MB genres are only ever going to be as useful as they are consistently applied.

The good news is that there is a restricted list of tags that MB considers to be genres, so we don’t see quite the pollution of genres that e.g. lastFM suffers from - and less of a need for code to clean them up. But if you want to use genres from other sources as @hiccup points out, then the clean up is much more difficult.

Plugins like this can help, but until genres are handled in a more curated (required and voted) and structured (consistent use of case, hierarchical, selected from dropdowns) fashion they will always be very hit and miss.

But, the whole purpose of plugins is to allow exactly this type of functionality to be delivered and tried. So please don’t let my negativity stop you. :slight_smile:

2 Likes

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.