Proposed Genre Mapping Plugin

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 (“;”).

Thanks for providing a plugin which I hope to use to simplify using genres in File Naming
I have v0.5 of the Genre Mapping plugin enabled, and have used it successfully for simple (literal) mappings.
I am now trying to make regex-based mapping work and I get errors from the plugin when using a very simple regex-based mapping configuration with one line:
jazz=Jazz”
(quoted because asterisk otherwise is hidden)

This log snippet shows the plugin being loaded with the one mapping pair:

D: 10:55:46,579 pluginmanager._remove_plugin_files:395: Remove plugin files and dirs : ‘genre_mapper’
D: 10:55:46,579 pluginmanager._remove_plugin_files:406: Removing file ‘/Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins/genre_mapper.zip’
D: 10:55:46,579 pluginmanager.handle_plugin_updates:247: Updating plugin ‘genre_mapper’ (‘/Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins/genre_mapper.zip’))
D: 10:55:46,579 pluginmanager.load_plugins_from_directory:264: Looking for plugins in directory ‘/Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins’, 1 names found
D: 10:55:46,583 plugin.register:82: ExtensionPoint: track_metadata_processors register ← plugin=‘genre_mapper’ item=<function track_genre_mapper at 0x118130720>
D: 10:55:46,583 plugin.register:82: ExtensionPoint: pages register ← plugin=‘genre_mapper’ item=<class ‘picard.plugins.genre_mapper.GenreMapperOptionsPage’>
D: 10:55:46,583 //Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins/genre_mapper.zip/genre_mapper.refresh:71: Genre Mapper: Refreshing the genre replacement maps processing pairs using ‘RegEx’ translation.
D: 10:55:46,583 //Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins/genre_mapper.zip/genre_mapper.refresh:99: Genre Mapper: Add genre mapping pair: “jazz” = “Jazz”
D: 10:55:46,583 pluginmanager._load_plugin:337: Loading plugin ‘Genre Mapper’ version 0.5.0.final0, compatible with API: 2.0, 2.1, 2.2, 2.3, 2.6, 2.7, 2.8, 2.9

My goal is to eliminate all “sub-genre” of Jazz and just give them the genre Jazz. This seems to be straightforward, but I get Python error from the plugin:

E: 11:02:03,388 ui/item.error_append:108: <Album 3d541921-1a77-4154-bb7b-03be1a98a979 ‘’>: Traceback (most recent call last):
File “album.py”, line 409, in _finalize_loading_track
File “metadata.py”, line 697, in run_track_metadata_processors
File “plugin.py”, line 265, in run
File “/Users/gerryplummer/Library/Preferences/MusicBrainz/Picard/plugins/genre_mapper.zip/genre_mapper/init.py”, line 157, in track_genre_mapper
if genre and re.search(original, genre, re.IGNORECASE):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “re/init.py”, line 176, in search
File “re/init.py”, line 294, in _compile
File “re/_compiler.py”, line 743, in compile
File “re/_parser.py”, line 982, in parse
File “re/_parser.py”, line 457, in _parse_sub
File “re/_parser.py”, line 684, in _parse
re.error: nothing to repeat at position 0

I have used regular expressions quite a bit (but years ago); I am not familiar with the RE implementation in Python and possible quirks using it. But my usage seems completely analogous to the Example 1 in the Readme doc.

I’d appreciate any pointers about what I may need to do to make this work. Thank you.

I’ll have a look at it when I get a few minutes. In the meantime try changing your entry to:

^.*jazz.*$=Jazz

and see if that helps.


EDIT:

I just realized that your mapping was actually *jazz*=Jazz which is causing the error because it is an invalid regular expression. If you canage it to .*jazz.*=Jazz or jazz=Jazz with the regular expressions enabled, it should work. Similarly, if you set it to *jazz*=Jazz with the regular expressions disabled, that should also work.

I’ll modify the code so that it traps the error and logs an appropriaate error message about the regular expression being invalid.

Thanks for the reply. After submitting my reported issue, I edited it to show the exact syntax used (needing to quote in this forum app, as it is treating asterisks in some special way). That got me to thinking that his was an issue of the syntax acceptable to the python re feature,

I was about to research the python documentation for acceptable re syntax, but as your documentation example was precisely the syntax I had been failing to get to work, I decided to try the support forum first.

In any case, the tiresome ^.*Literal.*$ syntax did work for me. At least for some simple trials. So at this point I would suggest it would be useful to adjust the documentation (both in-code for the plugin and also the Readme.md file) to show an example that works, and point to python re documentation (or whatever is available) that describes the syntax. As a long-term Linux/Unix user, I am familiar with RE syntax (although not at an advanced level), I’ve not run in to this particular issue with the RE interpreter.

Again, thanks for your help. I"m optimistic the plugin will help me deal with the genre “simplification” which will help me with other issues browsing/searching my library using Apps which are tag-aware vs. filename-only.

I have to say that I’m a bit disappointed in your response, and take exception to some of the things that you say. Normally I would just ignore it and wouldn’t bother responding, but in this case I feel that I need to set the record straight.

I assure you that I personally confirmed that every one of the examples included in the documentation worked when I wrote it, and just confirmed that they still work. Note that all except the last one require that the regular expression option be disabled (and that is noted in the final example). I believe that the problem is that you were trying to use them with the option enabled.

That’s odd because I am not aware of any parser that accepts a regular expression beginning with an asterisk as being valid. The asterisk indicates that the preceeding character (or group) should be repeated (matched) any number of times, so it makes no sense when there is no preceeding character or group.

For clarity, I have submitted a revision to the plugin that catches the exception and logs an error when it finds that a regular expression is invalid. At least that will help identify when it doesn’t work due to a user error.

If you find entering a proper full match regular expression “tiresome”, perhaps you could try one of the other methods I suggested in the edit in my earlier response, or not use regular expressions at all and simply rely on the normal ‘?’ and ‘*’ wildcards (which are easier to understand).

2 Likes