Help setting custom paths for specific genres

I have been in the documentation, guides, and forums for the last few days trying to work out how (or even if this is possible) to set output paths based an some genre types (not all genres). One of my big issues is that when I’m playing my music randomly a Christmas song will get thrown into the mix because it is sonically similar when I am playing an artist station, etc.

I created a custom tagging script:

$noop( Initialize multi-value variables )

	'christmas music'

	'field recording';
	'nature sounds';
	'relaxation - nature'

	'alternative ccm';
	'contemporary christian';

$noop( Assign path from genre )

	$foreach(%genre%,$if($inmulti(_holiday,$lower(%_loop_value%)),$set_a(_folder,holiday)))	$foreach(%genre%,$if($inmulti(_relaxing,$lower(%_loop_value%)),$set_a(_folder,relaxing_sounds)))

…and here is my naming script

$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)
- %title%

Based on my reading, I was under the impression that you could pass an output from the tagging script to the naming script. I also tried disabling the tagging script and putting this code into my naming script, but neither scenario produced the desired results. I tested on several albums that I specifically picked based on their genre tags for testing purposes.

As a side note, I created a “none” folder for my albums without tags so I could start adding tags in Musicbrainz to contribute to community.

Any assistance would be so greatly appreciated.

After a quick glance, I think the problem lies in how you are defining your multi-value variables. I suspect that Picard is interpreting the single quotes that you have around each item and the tab character at the start of the indented lines as part of the item itself. Try replacing the relevant lines in your tagging script with the following and see if that helps:

$noop( Initialize multi-value variables )
$setmulti(_classical,classical; symphony)
$setmulti(_holiday,christmas; christmas music)
$setmulti(_relaxing,field recording; nature sounds; meditative; relaxation; relaxation - nature)
$setmulti(_spiritual,alternative ccm; ccm; christian; contemporary christian; religious)

Indeed. The tagger scriptis very sensitive to whitepace. E.g. in the _relaxing variable you define a value that is literally 'classical' (including the leading tabulator).

THANK YOU for the replies and assistance. Removing the whitespace wasn’t enough to get the desired results, but it definitely caused me to slow down and dig MUCH deeper.

Some notes:

  1. This requires the “Persistent Variables” plugin.

  2. With the genre options, if you have it set to join with a comma (“,”) and you try to $setmulti with the genre to get a list of indexed strings, I was unable to use separator=“, " (escaping out the comma) to get it to parse the object correctly. I switched to using the slash (”/") and was able to do a $replace on the slash for a semi-colon, then $setmulti to achieve this.

  3. In the file naming script I couldn’t just pass the %_folder% variable, but rather had to use the $get_a(_folder) to return the album persistent value.

  4. Setting the default for all other genres to go to the “music” folder did not work inside the $while loop as it was always setting the _folder to music. It’s like the $while loop isn’t exiting as soon as the _folder variable is set to a value and would process through the entirety of the code. Simply moving the default folder outside the loop with an $if statement resolved this issue.

  5. You will see a bit of a speed hit when matching due to the loop iterations. This is just a note if someone is looking to do a very large library and/or getting a lot more in depth with the genre groupings.

Here is my working script for reference incase anyone comes across this thread:

$setmulti(_genre,$replace($lower($get_a(_common_genre)), / ,; ))
$setmulti(_childrens,childrens; lullabies)
$setmulti(_classical,classical; symphony)
$setmulti(_holiday,christmas; christmas music)
$setmulti(_relaxing,field recording; nature sounds; meditative; relaxation;relaxation - nature)
$setmulti(_spiritual,alternative ccm; ccm; christian; contemporary christian; religious)
$setmulti(genre,$replace($if2($get_a(_common_genre),None), / ,\, ))

This includes an added bit for setting the genre for ALL tracks to the genre of the first track as I want my album tagging to be consistent across all tracks in my metadata. And the last line is for putting my genres back into comma format as opposed to the slash format as that is my personal preference.

Last, here is my file naming script:

$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)
- %title%

Note the first line is using the command from the Persistent Variables plugin and can not be simply passed in %variable% notation.

If anyone has ideas on improvement of the script for usability and/or efficiency, please post as I am always looking to improve…

Thanks again!

EDIT: I’ve tweaked the order of the $foreach statements. If you have genres that are in more then one group, then you want the winning genre below the other as the $while statement completes the entire code block. So put the “winning” genre towards the bottom of the code block.