Rename Script Editor Regexp possible?

Good morning all :slight_smile:
Im trying to change a bit of my process of adding/tagging/renaming stuff and sort out a few extra steps. At the moment its like this:
Rip CD/Tape… or grab the Digital Download files >
Run Picard and Tag it >
Mp3Tag for a few things tag related > (want to cut this)
Rename and move in the wanted location with mp3tag (want to cut this too)

So my rename script from Mp3tag is like this:

%genre%\$replace($left(%albumartist%,1),Ä,A,1,#,2,#,3,#,4,#,5,#,6,#,7,#,8,#,9,#,С,C,Ć,C,$,#,0,#,*,#)\$replace($regexp(%albumartist%,(.*?)/(.*),$1\\- Features -\\mit $2),/,', ')\(%year%) %album%[\CD%discnumber%]\%track%. $left($replace($regexp(%artist%,(.*)/(.*),$1 & $2),/,', '),140) - %title%

Copy&Paste into Picard will result in an error “2:1: Unexpected Character”
Dont know if its the regexp stuff, but i would like to make the rename/move in Picard to. Before that i had to fix some stuff in Mp3tag to fit the rename for my needs. I just would like to have it like this:

Genre >
First letter of the Albumartist name (Numbers in # folder, variations of like ê é etc.
should be in E, âá in A etc.) and folder name should be Uppercase >

Albumartist (only the first one, if there are more than one move to “- Features -” folder
inside the first Albumartist and ignore any kind of feat. ft. with etc. etc. just use “,” as seperator
and on the last one, if there are more then one use “&”.
But dont replace and, with, X etc if they are part of a name/group just replace the seperators used for seperating multiple artist) >

Releasetype like Single,Album,EP (also only the first one if there are more) first Letter should be in Uppercase (EP should stay like that if possible) >
(Year) Album >
Track. Artists (all on that track and also use “,” as seperator and the last one “&”) - Title.ext

small example:
lets say the Track is something like this:
9. 2Pac feat. Biggie X Wu-Tang ft. WunTwo - Blablabla.mp3 from the EP XYZ from 2004, its on disc 2 and genre is Rap.
I want it like that:

Rap/#/2Pac/- Features -/Biggie, Wu-Tang & WuTwo/EP/[2004] XYZ/CD02/09. 2Pac, Biggie, Wu-Tang & WunTwo - Blablabla.mp3

I got it like that with mp3tag after a few changes like disc#, 1disc only i had to remove the 1.
If its 2 or more i had to change 1/2 to 1 and 2/2 to 2 etc. to get it working, same for track#.
I had to change 2/18 to 02 etc. (is it possible to use only 2 letters for albums with track count
below 100, and use 3 if there are more than 100? yea…i know just a few have that much, just to dont mess things up)

how could i achieve this with Picard without removing/changing alot of the tags?
(want to keep them as much “perfect” from MB as possible)

Im playing around with the picard script editor but i cant get some steps to work.
Here is what i got so far:

%genre%/
$upper($firstalphachar(%albumartist%))/
%albumartist%/
%releasetype%/
[$if(%date%,$left(%date%,4),0000)] 
%album%/
$if(%discnumber%,CD%discnumber%,)/
$num(%tracknumber%,2). %artist% - %title%

the problems are here:
$upper($firstalphachar(%albumartist%))/
is this enough to change all the variations like âêé etc.? a quick test changes Ä to A and 23 to # but is this for EVERY variation?

the whole - Features - folder part is missing from the albumartist folder, dont know how to do this im lost here…

%releasetype%/
throws out album and also album; complilation etc. How can i set the first letter only in uppercase on like Album, Single? EP should stay EP. and how to cut it to only use the first one? “album; compilation” should be Album, “album; mixtape” should be Album etc.

$if(%discnumber%,CD%discnumber%,)/
how can i ignore this if theres only 1 disc, and how can i add a 0 before the number if its below 10? Like 01,02 etc (for sorting)

$num(%tracknumber%,2). %artist% - %title%
the conver from 2/18 to 02 seems to work, title also.
But how do i ignore all the types of Artist seperators and just use “,” and for the last one “&”?

I checked the option in picard to alow longer than 259 filenames (windows11) and to replace illegal characters and ASCII, is this save on all of them, or do i need to put something into the rename script? And if the filenames are to long, how can i change it, that it would cut the %artist% part in the end if there are to much artists on one track

A little check to replace stuff ends in an unwanted path.
An album named like “Das Gleiche Wie Immer, Bitte.” would end in “Das Gleiche Wie Immer, Bitte_” so a “.” gets replaced with “", but why? Its not an illegal char… how can i keep it? I changed the option and replaced all "” with “”, but even then… it gets cut.
And how can i change it, that illegal replaced chars dont get an “_”? if its really an illegal char i just want to erase it.

Stuff like this " \ / : * ? " < > |" should just get deleted to “”.
Sorry for the wall of text. just banging my head againts the editor… :smiley:
I hope i did not forget something, and that this wouldnt be that much of work.
Maybe im just to stupid LOL

got a little update. disc numbers, only first type of releasetype and first char on releasetype in uppercase should be fixed now.
Looks like this:

%genre%/
$upper($firstalphachar(%albumartist%))/
%albumartist%/
$title(%_primaryreleasetype%)/
[$if(%date%,$left(%date%,4),0000)] 
%album%/
$if($gt(%totaldiscs%,1),CD $num(%discnumber%,2),)/
$num(%tracknumber%,2). %artist% - %title%

now i have to find a way to make that - Features - folder possible if there are more than 1 albumartist, and also figure out how to ignore the pre defined artist seperatores like feat., ft., with, and, etc. and just use “,” as seperator except the last one should be “&”.

Still trying, if i get any update i will post it, maybe this helps someone in the future :slight_smile:

Also little question, i just saw that ä ö ü will be replace with a o u, because i set the ASCII option.
Is it possible to keep ä ö ü and the others should be replaced like it is now? âéê are fine to be replaced, but as a german Kussen is just strange when it should be Küssen. The others like âéê are fine to be replaces. i just need to keep ä ö ü Ä Ö Ü

Although you might be able to do this using scripting functions only, I think this would be easiest using the “Additional Artists Variables” plugin to provide most of the information for you. The list of additional scripting variables available can be found in the User Guide.

To determine if there are multiple album artists, you need to check if the %_artists_album_additional_id% variable has been created and populated. This can be done as follows:

$if(%_artists_album_additional_id%,- Features -/)

Adding the additional artists separated by commas and an ampersand (&) instead of the separators from the metadata is a bit trickier. I think I would create a new temporary variable to hold the additional artists list with the desired separators, something like:

$if(%_artists_album_additional_id%,
  $set(_aa_count,$sub(%_artists_album_all_count%,2))
  $foreach(%_artists_album_additional_cred_multi%,
    $set(_additional_artists_list,%_additional_artists_list%%_loop_value%$if($lt(%_loop_count%,%_aa_count%),\, )$if($eq(%_loop_count%,%_aa_count%), & ))
  )
)

This will create a new variable called %_additional_artists_list% which you can place in the appropriate place in your naming script. The final file naming script might look something like:

%genre%/
$upper($firstalphachar(%albumartist%))/
%albumartist%/
$if(%_artists_album_additional_id%,
  $set(_additional_artists_list,- Features -/)
  $set(_aa_count,$sub(%_artists_album_all_count%,2))
  $foreach(%_artists_album_additional_cred_multi%,
    $set(_additional_artists_list,%_additional_artists_list%%_loop_value%$if($lt(%_loop_count%,%_aa_count%),\, )$if($eq(%_loop_count%,%_aa_count%), & ))
  )
)
%_additional_artists_list%/$title(%_primaryreleasetype%)/
[$if(%date%,$left(%date%,4),0000)] 
%album%/
$if($gt(%totaldiscs%,1),CD $num(%discnumber%,2),)/
$num(%tracknumber%,2). %artist% - %title%
2 Likes

In this case, I would suggest saving the file naming path and filename information to three variables (%_before_features_artists%, %_features_artists%, and %_after_features_artists%), initially instead of directly creating the path itself. Then get the total length of the three variables to determine if the length is within your desired limit. If it’s over the limit, shorten the %_features_artists% variable as required. Finally, create the actual filename by combining the three parts.

Applying this to the example file naming script in my previous message, this might look something like:

$set(_name_length_limit,$sub(255,$len(%_extension%),1)
$set(_before_features_artists,%genre%/$upper($firstalphachar(%albumartist%))/%_artists_album_primary_cred%/)
$if(%_artists_album_additional_id%,
  $set(_features_artists,- Features -/)
  $set(_aa_count,$sub(%_artists_album_all_count%,2))
  $foreach(%_artists_album_additional_cred_multi%,
    $set(_features_artists,%_features_artists%%_loop_value%$if($lt(%_loop_count%,%_aa_count%),\, )$if($eq(%_loop_count%,%_aa_count%), & ))
  )
)
$set(_after_features_artists,$title(%_primaryreleasetype%)/[$if(%date%,$left(%date%,4),0000)] %album%/$if($gt(%totaldiscs%,1),CD $num(%discnumber%,2),)/$num(%tracknumber%,2). %artist% - %title%)
$if($gt($add($len(%_before_features_artists%),$len(%_features_artists%),$len(%_after_features_artists%)),%_name_length_limit%),
  $set(_trim_length,$sub(%_name_length_limit%,$len(%_before_features_artists%),$len(%_after_features_artists%),1))
  $set(_features_artists,$if($gt(%_trim_length%,0),$left(%_features_artists%,%_trim_length%)/,)
)
%_before_features_artists%%_features_artists%%_after_features_artists%

Note that this will simply truncate the features artists list. If you want to cleanly truncate the list at an artist’s name, additional (or different) processing is required. In this case, I would track the length while adding the artists to the variable and stop adding if the resulting string would exceed the allowed value.

Also note that the allowable length calculation in the first line of the script takes into account the extension that will be added to the file name. You should also replace the 255 with the maximum length that you want to use.

wow, thank you very much. that was way above my head :smiley:
had to adjust it a little bit, because i got an error first, and also to replace duplicated whitespaces.

$set(_name_length_limit,$sub(255,$len(%_extension%),1)
$set(_before_features_artists,%genre%/$upper($firstalphachar(%albumartist%))/%_artists_album_primary_cred%/)
$if(%_artists_album_additional_id%,
  $set(_features_artists,- Features -/)
  $set(_aa_count,$sub(%_artists_album_all_count%,2))
  $foreach(%_artists_album_additional_cred_multi%,
   $set(_features_artists,%_features_artists%%_loop_value%$if($lt(%_loop_count%,%_aa_count%),\,)$if($eq(%_loop_count%,%_aa_count%), &)
  )
)))
$set(_after_features_artists,/$title(%_primaryreleasetype%)/[$if(%date%,$left(%date%,4),0000)] %album%/$if($gt(%totaldiscs%,1),CD $num(%discnumber%,2),)/$num(%tracknumber%,2). %artist% - %title%)
$if($gt($add($len(%_before_features_artists%),$len(%_features_artists%),$len(%_after_features_artists%)),%_name_length_limit%),
  $set(_trim_length,$sub(%_name_length_limit%,$len(%_before_features_artists%),$len(%_after_features_artists%),1))
  $set(_features_artists,$if($gt(%_trim_length%,0),$left(%_features_artists%,%_trim_length%)/,))
)
$strip(%_before_features_artists%%_features_artists%%_after_features_artists%)

thats how it looks now :slight_smile: really, Thank you!

1 Like