Rename patterns

Tags: #<Tag:0x00007fa5cbff8908>

I am currently using these 4 rename patterns. Switching them in the settings is getting cumbersome. So I was wondering how I could combine them into a single pattern.

Albums/%albumartistsort%/$left(%originalyear%,4) %album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) $if(%_multiartist%,%artist% - ,)%title%

Compilations/%album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) $if(%_multiartist%,%artist% - ,)%title%

Soundtracks/%album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) $if(%_multiartist%,%artist% - ,)%title%

Singles/%artist% - %album% - %title%

Given that the Singles are often enough (at least in theory) part of an album (the same might be true for compilations) it seems hard to separate them based on metadata. So I was wondering - maybe I could switch the rename expression depending on where the source file is?

If it’s in the Albums folder it will use the Albums pattern and so on.

I could not find how to do this yet though.
Or do you have other suggestions on automating the different patterns?

I use the primary and secondary releasetype tag contents to determine the naming format to use. This is all done automatically in my file naming script (available on GitHub).

2 Likes

Wow - that’s a pretty impressive but also complex script/format.

I guess the problem with _primaryreleasetype and _secondaryreleasetype is that what I call “singles” are also tracks where I don’t have the full album. So the metadata would show “album” but I want to treat them as “single”. As in “I don’t have the full album”.

I guess the track just doesn’t know if the album is completely available or not?
Not sure if there is a better way.

But I just found _dirname which might be allow for a work around.
The docs are just unclear on whether that is the absolute path?

Maybe something like this could work?

$if($endswith($_dirname, '/Album'),
  Albums/%albumartistsort%/$left(%originalyear%,4) %album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) $if(%_multiartist%,%artist% - ,)%title%
,)

Not that I am fan of the approach.

In that case, you should be able to trigger based on the $is_complete() scripting function. For more information, please see the Picard User Guide.

1 Like

Wow - so something like that is available. That’s awesome!
I will give that a try.

Not sure what this means though:

This function only works in File Naming scripts.

Is the rename field a “file naming script”?

Also - what defines the album? Let’s say there is no match on musicbrainz, the cluster/album is defined to have 13 tracks, all tracks are there - is $is_complete() true or not?

The file naming script is what is defined in the “Name files like this:” box in the Filenaming Options section of the configuration settings.

I believe that the album is the release in the right hand pane to which your various tracks have been matched.

Is there a way to see where Picard would write a track to? without actually saving it?
The path in the bottom bar seems to show the source - but not the transformed filename.

The way I do it is by saving the output path information to a variable (tag starting with an underscore so it won’t be written to the file) and then inspecting the variables using the View Script Variables plugin.

1 Like

To get started I just tried this:

$set(_complete,$is_complete())
$set(_foo,1234)

%artist% - %album% - %title%

but I don’t see the _complete or _foo variables listed by the plugin.

What am I missing?

Sorry, I think I may have misled you a little. The View Script Variables plugin will only show the variables set in user scripts (and not from the naming script). You would need to duplicate the file naming script in a user script (saving the output to a variable), but this still wouldn’t do exactly what you’re after because the $is_complete() function does not work in the user scripts.

What you might do is create a variable for each of the naming templates that you use, and then trust that the naming script will select the correct template.

1 Like

Urgh. That does not sound so great. This could really need some improvements.

But many thanks for all the help.

I got a bit further - but are now a little lost.

$if($endswith(%_dirname%,B), works
$if($endswith(%_dirname%,"B"), does not work
$if($endswith(%_dirname%,/B) does not work

The view plugin shows _dirname to be /some/path/B

What am I missing?

It’s because it is trying to match EXACTLY what you have between the comma and the closing bracket, including any quotes, slashes and spaces. Then again, you didn’t say what you’re trying to match so I’m just guessing.