Use folder name in script

HI there: is there a way to use the information in a folder or in a genre in a renaming script. Something like if the genre is classical, then do this? If a track is in this folder, do this? Thank you

You could likely parse the %_dirname% variable and check for a desired genre and then use a $if() statement to conditionally execute part of the script. Have a look at the File Variables section of the Picard User Guide for more information.

1 Like

For genre you could use something like:

$if($inmulti(%genre%,classical),...)
1 Like

If you want to use %genre% for this, then you need to:

  1. Have the correct options settings - in Options / Metadata / Genres, enable “Use genres from MusicBrainz”. I also recommend that you set “Fallback on album’s artists genres…”.

  2. Make sure that you don’t have a plugin that overwrite this variable, especially if it uses track genres rather than release genres (because if you use this in the path part of a file naming script you will get your albums scattered amongst multiple directories). AcoustBrainz Mood-Genre is one example of a plugin to avoid (though I do have a PR submitted to save the values so that you can use a script to restore them), but there may be others.

I also just checked my (relatively small) classical music directory to see how well genre would work to detect Classical music, and there were (from a purely subjective position) some anomalies - for example:

  1. Even MusicBrainz genres can be track by track - I have raised an enhancement request to allow you to see artist and release genres (which are consistent across tracks) as well as the combined genres.

  2. Some releases contain genres which are sub-classifications of Classical but not Classical itself - so you will nee to check for these. Examples in my collection include “Other Classical”, “Modern Classical”, “Opera”, “Chamber Opera”, “Minimalism”, “General Contemporary Era”, “Ambient”, “Soundtrack”, “Concerto”, “Symphony”.

  3. Album artist genres are only included when Release / Release Group don’t have genres. I have included an enhancement for this in the above enhancement request.

Bottom line: Picard isn’t yet ready to handle file naming paths using genres.

2 Likes

Hi. Im trying to get the genre from the path folder D:/MP3/Metal/artist for a tagger script, but isnt working. Actual tagger script:
$set(genre, $if($inmulti(_dirname,Metal),Metal))
Not working too:
$set(genre, $if($inmulti(%_dirname%,Metal),Metal))
Can you help me plz? Im a noobie with codes. Ty.

Sorry I took so long to respond, but I’ve been away on vacation.

I think the problem might be your use of $inmulti(). Try something like:

$if($in(%_dirname%,Metal),$set(genre,Metal))

No problem. Hope you had a nice vacation. Your code worked, but the script doesn’t run automatically like the others. Thanks a lot, it’s just 1 extra click.

I have a very similar question about using the folder structure for tagging to eliminate all “featured” or “band + other band” albumartist tags. My folder tree is already devoid of those combined artists and seems the simplest place to pull the sanitized albumartist name from.

My folder tree structure:
/albumartist/[year] album/track.flac

Goal is to pull the albumartist part from the folder structure and write it to albumartist as well as to any and all other artist-related tags.

Purpose of this is to make sure all apps only show the main albumartist no matter which artist/albumartist/etc tag it pulls from and eliminate featured artists, so that I end up with the same exact list of artists no matter which app I happen to be using.

I can’t figure out how to extract the /albumartist/ part using a script since it’s several folders up the tree. Anyone with better scripting skills than me able to help?

If you actually want to fill the albumartist tag from the filename you could use “Tags from Filenames” with a pattern like this:

%albumartist%/%_yearandalbum%/%_track%

I used underscores in front of tha variables for the “[year] album” folder and the track title itself, as it seems you don’t actually want to read those. The underscore makes sure the read info does not get written to tags.

But if your general wish is to replace all artist tags with albumartist instead you might not even need this. MusicBrainz provides albumartist, so you could also add a script to Options > Scripting to overwrite artist with albumartist:

$set(artist,$if2(%albumartist%,%artist%))
$set(artistsort,$if2(%albumartistsort%,%artistsort%))

The $if2 is only there to provide a fallback to the artist / artistsort value should albumartist / albumartistsort not be set. But for data loaded from MB it should always be there (unless you have some other script or plugin already messing with it).

2 Likes

Thanks that gets me part of the way there.

However I can’t use the “tags from filenames” feature due to the enormous number of files I’m working with causes Picard to crash trying to even open that window. I’m also trying to just make this part of what Picard does on everything I process through it. Basically I just run my whole collection through Picard periodically to clean up any janky or incomplete tags. Each operation I perform on the collection in Picard takes ~6 hours to write tags to disk, so trying to get it configured to do everything in one round.

Is there a way to pull that %albumartist% out of the filename as a script under Options->Options->Scripting similar to what you posted for rewriting artistsort & albumartistsort?

The missing pieces of info I can’t find are:
a) what is the %variable% for the filename itself?
b) how can I parse that %variable% and pull out only the %albumartist% part of the folder tree such that I can write it to all the various artist tags?