Is there a way to get a single Genre for each album?

I would like each and every album to just have 1 genre tag, even if it ends up slightly inaccurate, I prefer to browse music like this. I see a few albums with “different across multiple items” - is it possible to override this and have it set 1 main genre for such items?

Thanks!

Do you want to provide the override manually, or try to get it automatically (e.g. the genre from the first track on the album)? Also, do you want to replace the genre tag in the files or just use this for file naming?

I would prefer the first track of the album to be the new genre tag.

Okay, I haven’t tested this, but you might be able to achieve your desired result using the following…

First, from the Genres section of the Metadata Options, set the maximum number of genres to 1. You might also want to enable the “Fall back on album’s artists genres…” setting. This will help ensure that you end up with one and only one genre per track (although they may still be different between tracks at this point).

Next, install and enable the Persistent Variables plugin from the Plugins Options page in Picard. This will provide the functions necessary to create and retrieve a variable with a value common to all tracks on a release.

EDIT: Note that you need to use the “Make It So!” button to save your changes and activate the plugin before proceeding to adding the new scripts.

The third step is to create a new tagging script in the Scripting Options page. The script should be enabled (checked) and the “Enable Tagger Script(s)” option should also be checked. The script should contain the following:

$if($and($eq(%tracknumber%,1),$eq(%discnumber%,1)),$set_a(_common_genre,%genre%))

This script retrieves the value of the %genre% tag from the first track on the first CD and stores it in a special album-level variable called _common_genre.

Now create another tagging script after (below) the one just created, and make sure that it is also enabled. This new script should contain the following:

$set(genre,$if2($get_a(_common_genre),None))

This script retrieves the value of the album-level variable _common_genre saved in the first script, and stores it in the %genre% tag for each of the tracks in the album. If there was no genre found for the first track of the first disc, the %genre% tag will be set to “None”. If you would like a different default genre value to be used, simply replace “None” in the second script with your preferred default.

As I said earlier, I haven’t tested this so please let me know if it it works for you or if you run into any problems. Thanks.

4 Likes

Some error was given when adding the first script:

1:51:$set_a: unknown function '$set_a

You probably need to use the Make It So! button to ensure that the plugin is activated and then go back and enter the scripts.

1 Like

Your solution seems to work great, thank you very much!

3 Likes