Script Help for IF(Then())

Okay, so, I think this is an odd request as naming goes and I am not very good at coding. There isn’t a IfThan script here and I am a bit lost, Essentially I want IF %albumartist% contains “Random Person” THEN %album% = New Name OR F %albumartist% contains “Random Person” don’t create an album folder

I have a lot of songs that, even though they are singles, have their own ‘albums’ and I would rather have one big album with all the tracks in it than 20 ‘albums’ with one track in each.

I am still learning the language here so any tips or explanations are greatly welcomed.

I suggest that you have a look at the following sections from the Picard Users Guide:

  • Scripting - general overview of scripting in Picard
  • Tags & Variables - items that can be used in scripts, with links to detailed descriptions of each item of the available types
  • Scripting Functions - list of all functions that can be used in scripts, with links to detailed descriptions of each function
  • Writing a File Naming Script - step-by-step tutorial on how to write a general file naming script

In general, I think you will need to do something like:

$if($in(%albumartist%,Random Person),$set(album,New Name))
$if($in(%albumartist%,Random Person),,your code to create the album folder)

The other thing to note is that tag values changed in a file naming script will not save the new value to the file’s metadata. That can only be done in a tagging script.

2 Likes

Thank you, will def check these out!!

Thank you, you were a life saver! I got it figured out how I wanted it eventually and am posting what I have right now just in case anyone else would find it useful! This is very much formatted for easy editing NOT for good coding practices lol.

I am still fiddling with it as I go through my music and adding stuff, but so far I am really liking it!

$if($eq($lower(%genre%),soundtrack), $set(Artist1,Sountrack/))
$if($in(%album%,Soundtrack), $set(MainFolder1,Sountrack/))
$if($in(%album%,Soundtrack), $set(Artist1,Sountrack/))
$if($in(%itle%,soundtrack), $set(Mainfolder1,Sountrack/))

$if($eq($lower(%genre%),musical), $set(Artist1,Musical/))
$if($eq($lower(%genre%),musical), $set(Mainfolder1,Musical/))
$if($eq($lower(%genre%),musical), $set(Artist1,%noop%/))
$if($eq($lower(%genre%),musical), $set(MainFolder1,Musical/))


%MainFolder1%
%Artist1%
%Album1%
%MultiDisc1%
%PreTitle2%
%Track1%
%Title%

2 Likes

Glad to hear you got it working.

I understand that this is formatted for easy editing, but I’d like to suggest a couple of things for consideration:

  • Rather than having multiple conditional checks for the same condition each with a single action, you can do the check once and combine the actions in the appropriate “then” or “else” block.
  • I suspect that %itle% in the line $if($in(%itle%,soundtrack), $set(Mainfolder1,Sountrack/)) should actually be %title%.
  • The $if($eq($lower(%genre%),musical), $set(Artist1,Musical/)) line is irrelevant because it is later replaced with $if($eq($lower(%genre%),musical), $set(Artist1,%noop%/)).
  • The $if($eq($lower(%genre%),musical), $set(MainFolder1,Musical/)) line is duplicated, thus being executed twice.
  • I assume that %noop% in the line $if($eq($lower(%genre%),musical), $set(Artist1,%noop%/)) is intended to be an empty string. If that’s the case, you can just leave it out.
  • Although the spaces after the commas don’t impact the following $set() functions, avoiding unnecessary spaces is a good habit to get into because they could be included in resulting strings in tags or output from the file naming script, with unintended consequences.

For example, my suggested revision to what you have posted is:

$if($eq($lower(%genre%),soundtrack),$set(Artist1,Sountrack/))
$if($in(%album%,Soundtrack),$set(MainFolder1,Sountrack/)$set(Artist1,Sountrack/))
$if($in(%title%,soundtrack),$set(Mainfolder1,Sountrack/))

$if($eq($lower(%genre%),musical),$set(Artist1,/)$set(MainFolder1,Musical/))

%MainFolder1%
%Artist1%
%Album1%
%MultiDisc1%
%PreTitle2%
%Track1%
%Title%

If you intended to have the genre “musical” set “Artist1” to “Musical/” rather than “/”, then my suggested revision is:

$if($eq($lower(%genre%),soundtrack),$set(Artist1,Sountrack/))
$if($in(%album%,Soundtrack),$set(MainFolder1,Sountrack/)$set(Artist1,Sountrack/))
$if($in(%title%,soundtrack),$set(Mainfolder1,Sountrack/))

$if($eq($lower(%genre%),musical),$set(Artist1,Musical/)$set(Mainfolder1,Musical/))

%MainFolder1%
%Artist1%
%Album1%
%MultiDisc1%
%PreTitle2%
%Track1%
%Title%
1 Like

The other thing that I just noticed that I will caution you about is the line:

$if($in(%itle%,soundtrack), $set(Mainfolder1,Sountrack/))

Note that %title% (which I assume you meant rather that %itle%) is the title of the track, and this could cause the track to be placed in a different directory than the other tracks on the album.

I also just noticed that you are not consistent in the case when setting the “MainFolder1” tag. In some of the lines it is shown as “Mainfolder1” which is not used elsewhere in the script, which will lead to unexpected results.

Finally, I assume that setting the directory as “Sountrack/” rather than “Soundtrack/” is a language-specific thing.

1 Like