Repository for neat file name string patterns and tagger script snippets

Where you currently have “%media%$if2(%discnumber%,1)/”, replace that with:

$if($in(%media%,CD),CD$if2(%discnumber%,1)/,)

That would make the whole script:

$if2(%albumartist%,%artist%) - /[$left($if2(%date%,%originaldate%,0000),4)] - %album%/$if($in(%media%,CD),CD$if2(%discnumber%,1)/,)%artist% - $num(%tracknumber%,2) - %title%
2 Likes

@rdswift Thank you very much

@rdswift if I may add to this query, how do you move the “, The” and the "A " of the title to the end? I want to this for Artist, Album and the Song itself. Is this scenario covered in your renaming script?

Have a look at the $swapprefix() function.

1 Like

6 posts were split to a new topic: Help configuring file renaming and moving

@rdswift I’m using your naming script and I was wondering if it would be simple to have two of the fields/data items show as Titlecase. The two fields I’m looking at are releasecomment and releasetype. Right now this is what I get:

Thanks for your help!!!

You should be able to by using $title(%releasecomment%) in place of %releasecomment% and $title(%releasetype%) in place of %releasetype%, unless I’ve misunderstood.

1 Like

Thank you so much!! Yes, that is exactly what I’m looking for…I just couldn’t remember how to do that…I knew it would be easy…thank you again!!!

1 Like

Well, it looks like the updates will work except for Soundtracks…I must be doing something wrong. Would you mind looking over the coding? I forget how to add the box in this posting so the code shows properly…How do I do that like your posts?

Precede your code with three backticks and “taggerscript” on a separate line, and put three backticks on a separate line after your code.

```taggerscript
Your code
```

Alternately, you can put your code in something like pastebin and post the link.

$noop(
########################################################################
# #
# Picard File Naming Script 2020-11-15 #
# Bob Swift [rdswift] #
# #
# License: GPLv3.0 #
# #
########################################################################
#
# This script relies on inputs provided by the "Additional Artists
# Variables" plugin. This plugin is freely available for use under
# GPL-2.0 or later, and the latest version can be downloaded from the
# author's repository at:
#
# https://github.com/rdswift/picard-plugins/tree/2.0_RDS_Plugins
#
# Additional variables provided are:
#
# Album Variables
#
# _artists_album_primary_id - The ID of the primary / first album artist listed
# _artists_album_primary_std - The primary / first album artist listed [standardized]
# _artists_album_primary_cred - The primary / first album artist listed [as credited]
# _artists_album_primary_sort - The primary / first album artist listed [sort name]
# _artists_album_additional_id - The IDs of all album artists listed except for the primary / first artist, separated by a semicolon and space
# _artists_album_additional_std - All album artists listed [standardized] except for the primary / first artist, separated with strings provided from the release entry
# _artists_album_additional_cred - All album artists listed [as credited] except for the primary / first artist, separated with strings provided from the release entry
# _artists_album_all_std - All album artists listed [standardized], separated with strings provided from the release entry
# _artists_album_all_cred - All album artists listed [as credited], separated with strings provided from the release entry
# _artists_album_all_sort - All album artists listed [sort names], separated with strings provided from the release entry
# _artists_album_all_sort_primary - The primary / first album artist listed [sort name] followed by all additional album artists [standardized], separated with strings provided from the release entry
# _artists_album_all_count - The number of artists listed as album artists
#
# Track Variables
#
# _artists_track_primary_id - The ID of the primary / first track artist listed
# _artists_track_primary_std - The primary / first track artist listed [standardized]
# _artists_track_primary_cred - The primary / first track artist listed [as credited]
# _artists_track_primary_sort - The primary / first track artist listed [sort name]
# _artists_track_additional_id - The IDs of all track artists listed except for the primary / first artist, separated by a semicolon and space
# _artists_track_additional_std - All track artists listed [standardized] except for the primary / first artist, separated with strings provided from the track entry
# _artists_track_additional_cred - All track artists listed [as credited] except for the primary / first artist, separated with strings provided from the track entry
# _artists_track_all_std - All track artists listed [standardized], separated with strings provided from the track entry
# _artists_track_all_cred - All track artists listed [as credited], separated with strings provided from the track entry
# _artists_track_all_sort - All track artists listed [sort names], separated with strings provided from the track entry
# _artists_track_all_sort_primary - The primary / first track artist listed [sort name] followed by all additional track artists [standardized], separated with strings provided from the track entry
# _artists_track_all_count - The number of artists listed as track artists
#
########################################################################
# #
# For tagging and filing classical music using the Classical file #
# naming scheme, a user script must be enabled that sets the #
# _isClassical processing flag. This script can be a single line: #
# #
# $set(_isClassical,1) #
# #
########################################################################
)

$noop(Test Values
$set(_outputpath,PATH)
$set(_outputfilename,FILENAME)
)


$noop(
########################################################################
# #
# User Settings #
# #
########################################################################
)
$set(_PaddedDiscNumMinLength,2)
$set(_PaddedTrackNumMinLength,2)
$set(_aTitleMaxLength,65)
$set(_tTitleMaxLength,65)
$set(_tFilenameMaxLength,120)

$noop(
$set(_aTitleReleaseYear,1)
$set(_aTitleDisambig,1)
$set(_aTitleLabel,1)
$set(_aTitleCatalog,1)
)
$set(_aTitleReleaseYear,)
$set(_aTitleDisambig,)
$set(_aTitleLabel,)
$set(_aTitleCatalog,)


$noop(
########################################################################
# #
# Constants #
# #
########################################################################
)
$set(_cUnknownArtistID,125ec42a-7229-4250-afc5-e057484327fe)
$set(_cVariousArtistID,89ad4ac3-39f7-470e-963a-56509c546377)
$set(_cUnknownArtist,[Unknown Artist])
$set(_cVariousArtist,[Various Artists])
$set(_cUnknownAlbum,[Unknown Album])
$set(_cNoTitle,[Unknown Title])
$set(_cClassical,[Classical])
$set(_cSoundtrack,[Soundtracks])
$set(_cSingles,[~Singles~])
$set(_cOther,[Other])


$noop(
########################################################################
# #
# RegEx Constants #
# #
########################################################################
)
$set(_reCaseInsensitive,\(?i\))


$noop(
########################################################################
# #
# Defaults if "Additional Artists Variables" plugin not loaded or #
# metadata is missing #
# #
########################################################################
)
$set(_nFAA,$if2(%_artists_album_all_std%,%albumartist%,%_cUnknownArtist%))
$set(_nPAA,$if2(%_artists_album_primary_std%,%albumartist%,%_cUnknownArtist%))
$set(_nFAAS,$if2(%_artists_album_all_sort%,%albumartistsort%,%_cUnknownArtist%))
$set(_nPAAS,$if2(%_artists_album_primary_sort%,%albumartistsort%,%_cUnknownArtist%))
$set(_nFAAPS,$if2(%_artists_album_all_sort_primary%,%albumartistsort%,%_cUnknownArtist%))

$set(_nPTA,$if2(%_artists_track_primary_cred%,%artist%,%_cUnknownArtist%))
$set(_nATA,%_artists_track_additional_cred%)
$set(_nFTA,$if2(%_artists_track_all_cred%,%artist%,%_cUnknownArtist%))

$set(_nAN,$if2(%album%,%_cUnknownAlbum%))
$set(_nANT,$if2(%album%,%_cUnknownAlbum%))

$set(_nTN,$if2(%title%,%_cNoTitle%))
$set(_nTNT,$if2(%title%,%_cNoTitle%))


$noop(
########################################################################
# #
# Initialize Working Variables #
# #
########################################################################
)
$set(_nMedia,%media%)
$set(_nTotalDiscs,$if2(%totaldiscs%,1))
$set(_nDiscNum,$if2(%discnumber%,1))
$set(_nTotalTracks,$if2(%totaltracks%,1))
$set(_nTrackNum,$if2(%tracknumber%,1))
$set(_nAlbumArtistID,$if2(%musicbrainz_albumartistid%,%_kUnKnownArtistID%))
$set(_nInitial,~ $upper($firstalphachar(%_nFAAPS%,#)) ~/)

$noop(
------------------------------------------------------------------------
- If standardized primary album artist is different from credited -
- primary track artist [other than prefix] show in track file name. -
- Otherwise, show any additional credited track artists in track -
- file name. -
------------------------------------------------------------------------
)
$set(_tAlbumArtist,$lower($delprefix(%_nPAA%)))
$set(_tTrackArtist,$lower($delprefix(%_nPTA%)))
$if($eq(%_tAlbumArtist%,%_tTrackArtist%),
$set(_nFeat,$if(%_nATA%, [feat. %_nATA%],)),
$set(_nFeat, [%_nFTA%])
)

$noop(
------------------------------------------------------------------------
- Calculate the maximum lengths for disc and track numbers and set -
- the desired padding lengths. -
------------------------------------------------------------------------
)
$set(_TotalDiscNumberLength,$len($if2(%totaldiscs%,1)))
$set(_TotalTrackNumberLength,$len($if2(%totaltracks%,1)))
$set(_DiscPadLength,$if($gt(%_TotalDiscNumberLength%,%_PaddedDiscNumMinLength%),%_TotalDiscNumberLength%,%_PaddedDiscNumMinLength%))
$set(_TrackPadLength,$if($gt(%_TotalTrackNumberLength%,%_PaddedTrackNumMinLength%),%_TotalTrackNumberLength%,%_PaddedTrackNumMinLength%))

$noop(
------------------------------------------------------------------------
- Automatically pad disc and track numbers to the length of the -
- total number of discs and tracks. -
------------------------------------------------------------------------
)
$set(_PaddedDiscNum,$num($if2(%discnumber%,1),%_DiscPadLength%))
$set(_PaddedTrackNum,$num($if2(%tracknumber%,1),%_TrackPadLength%))

$set(_nYear,[$left($if2(%originaldate%,%originalyear%,%date%,0000),4)])
$set(_nTNum,$if($gt(%_nTotalDiscs%,1),%_PaddedDiscNum%-,)%_PaddedTrackNum%)


$noop(
------------------------------------------------------------------------
- Add disambiguation, release year, label and catalog number to -
- the album title information as available and enabled in the -
- "User Settings" section. -
------------------------------------------------------------------------
)
$set(_nDisambig,$if($and($title(%_releasecomment%),%_aTitleDisambig%), \($title(%_releasecomment%)\),))

$set(_nTitleExtra,)
$if(%_aTitleLabel%,$if(%label%,
$setmulti(_temp,%label%)
$set(_nTitleExtra,$getmulti(%_temp%,0))
)
)
$if(%_aTitleCatalog%,$if(%catalognumber%,
$setmulti(_temp,%catalognumber%)
$set(_nTitleExtra,$trim(%_nTitleExtra% $getmulti(%_temp%,0)))
)
)
$if(%_aTitleReleaseYear%,$if(%date%,
$set(_temp,$left(%date%,4))
$if($ne([%_temp%],%_nYear%),
$if(%_nTitleExtra%,$set(_nTitleExtra,%_nTitleExtra%\,))
$set(_nTitleExtra,$trim(%_nTitleExtra% %_temp%))
)
)
)
$if(%_nTitleExtra%,$set(_nTitleExtra, [%_nTitleExtra%]))

$set(_nANT,%_nANT%%_nDisambig%%_nTitleExtra%)


$noop(
------------------------------------------------------------------------
- Trim the album and track names used to create directories and -
- tracks if they are longer than the maximum lengths set in the -
- "User Settings" section. -
------------------------------------------------------------------------
)
$if($gt($len(%_nANT%),%_aTitleMaxLength%),$set(_nANT,$left(%_nANT%,$sub(%_aTitleMaxLength%,3))...))
$if($gt($len(%_nTNT%),%_tTitleMaxLength%),$set(_nTNT,$left(%_nTNT%,$sub(%_tTitleMaxLength%,3))...))


$noop(
#######################################################################
#
# Set Album Type [Single, Soundtrack, Classical, Other or Standard]
#
# Process as Classical
# Format: /[Classical]/Album Artist/[year] Album/Disc-Track [Composer] Title
#
# Process as Other
# Format: /[Other]/[year] Album/Disc-Track Title [Artist]
#
# Process as Soundtrack
# Format: /[Soundtrack]/[year] Album/Disc-Track Title [Artist]
#
# Process as Single
# Formats: /~ A ~/Album Artist/[~Singles~]/[year] Title [feat.]
#
# Process as Standard
# Formats: /~ A ~/Album Artist/[year] Album/Disc-Track Title [feat.]
# /~ # ~/Album Artist/[year] Album/Disc-Track Title [feat.]
# /[Various Artists]/[year] Album/Disc-Track Title [Artist]
# /[Unknown Artists]/[year] Album/Disc-Track Title [Artist]
#
#######################################################################
)
$noop($if($and($lte(%_nTotalDiscs%,1),$lte(%_nTotalTracks%,1),$in(%_primaryreleasetype%,single)),$set(_nAlbumType,Single)))
$set(_t1,1=)
$set(_t1,%_t1%$if($lte(%_nTotalDiscs%,1),Y,N))
$set(_t1,%_t1%$if($lte(%_nTotalTracks%,1),Y,N))
$set(_t1,%_t1%$if($in(%_primaryreleasetype%,single),Y,N))
$if($eq(%_t1%,1=YYY),$set(_nAlbumType,Single))

$noop(
$set(_t2,2=)
$set(_t2,%_t2%$if($eq(%_nAlbumArtistID%,%_cVariousArtistID%),Y,N))
$set(_t2,%_t2%$if($in(%_secondaryreleasetype%,soundtrack),Y,N))
$if($eq(%_t2%,2=YY),$set(_nAlbumType,Soundtrack))
)
$if($in(%_secondaryreleasetype%,soundtrack),
$set(_nAlbumType,Soundtrack)
$set(_nFeat, [%_nFTA%])
)

$if($in(%releasetype%,other),
$set(_nAlbumType,Other)
$set(_nFeat, [%_nFTA%])
)

$if(%_isClassical%,
$set(_nAlbumType,Classical)
$set(_nFeat, [%_nPTA%])
)
$set(_nAlbumType,$if2(%_nAlbumType%,Standard))


$noop(
########################################################################
# #
# Set File Path #
# #
########################################################################
)
$noop(
$if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nFAAPS%/%_nYear% %_nANT%/))
)
$if(%_releasecomment%,$set(_releasecomment, \(%_releasecomment%\)))
$set(album,$if(%_releasecomment%,%album% \(%_releasecomment%\),%album%))
$set(_bitrate,$rreplace(%_bitrate%,\\.[0-9]*\$,))


$if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nANT%$title(%_releasecomment%) %_nYear% [%media%] [$title(%releasetype%)]/))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nANT%$title(%_releasecomment%) %_nYear% [%media%] [$title(%releasetype%)]/))
$if($eq(%_nAlbumType%,Other),$set(_nFilePath,%_cOther%/%_nANT%$title(%_releasecomment%) %_nYear% [%media%] [$title(%releasetype%)]/))
$if($eq(%_nAlbumType%,Single),$set(_nFilePath,%_nInitial%/%_nPAAS%/%_cSingles%/%_nANT%$title(%_releasecomment%) %_nYear% [%media%] [$title(%releasetype%)]/))
$if($eq(%_nAlbumType%,Standard),$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
$set(_nFilePath,%_cVariousArtist%/%_nANT%$title(%_releasecomment%) %_nYear% [%media%] [$title(%releasetype%)]/),
$if($eq($if2(%musicbrainz_albumartistid%,%_cUnknownArtistID%),%_cUnknownArtistID%),
$set(_nFilePath,%_cUnknownArtist%/%_nANT%$title(%_releasecomment%) %_nYear% [%media% ] [$title(%releasetype%)]/),
$set(_nFilePath,%_nInitial%/%_nFAAPS%/%_nANT%$title(%_releasecomment%) %_nYear% [%media% ] [$title(%releasetype%)]/)
)))


$noop(
########################################################################
# #
# Set File Name #
# #
########################################################################
)
$if($eq(%_nAlbumType%,Classical),$set(_nFileName,%_nTNum%%_nFeat% %_nTNT% [%_bits_per_sample% bit ] [ %_bitrate% kpbs ]))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat% [%_bits_per_sample% bit ] [ %_bitrate% kpbs ]))
$if($eq(%_nAlbumType%,Other),$set(_nFileName,%_nTNum% %_nTNT% [%_bits_per_sample% bit ] [ %_bitrate% kpbs ]))
$if($eq(%_nAlbumType%,Single),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat% [%_bits_per_sample% bit ] [ %_bitrate% kpbs ]))
$if($eq(%_nAlbumType%,Standard),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat% [%_bits_per_sample% bit ] [ %_bitrate% kpbs ]))


$noop(
------------------------------------------------------------------------
- Trim the file name if it is longer than the maximum length set in -
- the "User Settings" section. -
------------------------------------------------------------------------
)
$if($gt($len(%_nFileName%),%_tFilenameMaxLength%),$set(_nFileName,$left(%_nFileName%,$sub(%_tFilenameMaxLength%,3))...))


$noop(
########################################################################
# #
# Note that some of these replacements revert back to an underscore #
# because of processing for Windows compatability. #
# #
########################################################################
)
$noop(
$set(_fnAlbumArtist,$rreplace(%_fnAlbumArtist%,/,•))
$set(_fnAlbumArtist,$rreplace(%_fnAlbumArtist%,:,ː))
$set(_fnAlbumArtist,$rreplace(%_fnAlbumArtist%,[.]3,…))
$set(_fnAlbumArtist,$rreplace(%_fnAlbumArtist%,[.]2_,…))
$set(_fnAlbumArtist,$rreplace(%_fnAlbumArtist%,[._]*\$,))
$set(_wAlbum,$rreplace(%_wAlbum%,:,ː))
$set(_wAlbum,$rreplace(%_wAlbum%,/,•))
$set(_wAlbum,$rreplace(%_wAlbum%,[._]*\$,))
$set(_wTitle,$rreplace(%_wTitle%,:,ː))
)


$noop(
########################################################################
# #
# Output the path and file name to use. #
# #
########################################################################
)

$noop(
$set(OutputPath,%_nFilePath%)
$set(OutputFileName,%_nFileName%)
)

$rreplace(%_nFilePath%/%_nFileName%,[?*:\\_]+,_)


$noop(
########################################################################
# #
# End of script. #
# #
########################################################################
)

Here is what I have…it seems all other types of albums work fine with changing the file path except Soundtracks. I ran the script at least once for each type of album type I have.

What are you getting, and what are you expecting?

This is what I’m getting and what I already have (doesn’t seem to change):
\Music\CD FLAC\[Soundtracks]\American Pie∶ Music From The Motion Picture (BMG club edition) [1999] [CD] [album; soundtrack]

What I would like:
\Music\CD FLAC\[Soundtracks]\American Pie∶ Music From The Motion Picture (BMG Club Edition) [1999] [CD] [Album; Soundtrack]

their is a slash after FLAC for both…don’t know why it won’t show…LOL

This is a bit of a patch because of the way you’ve modified the script, but try changing the line:

$if(%_releasecomment%,$set(_releasecomment, \(%_releasecomment%\)))

to:

$if(%_releasecomment%,$set(_releasecomment, \($title(%_releasecomment%)\)))

and see if that helps with the disambiguation comment.

For the release type, I wonder if the problem is because it’s seeing %releasetype% as a multi-value rather than a string? That’s a bit of a stretch, but perhaps we need to set it to a string variable to process. You could try adding $set(_temp,%releasetype%) before the section where the %_nFilePath% variable is set, and change all following occurrences of $title(%releasetype%) to $title(%_temp%) and see if that helps.

1 Like

OK…I just figured out something that might make more sense of what is going on and maybe you might have an idea on how to fix it. In MBP, in Options Menu, I have the “move files when saving” checked and have it set to the CD FLAC directory. I decided to change it to a different drive and now it is showing both fields like it should. Does this make any sense to you why by changing that it starts working? Oh, the reason why I changed the directory because the new releasecomment part you said to replace with $title didn’t change anything.

You’re using Windows, aren’t you? Windows isn’t case sensitive with its file paths, so if the letters are the same except a different case, the new path won’t be created or the existing path renamed. Nothing Picard can do about that.

1 Like

Never knew I had to watch out for that…so if I use my Mac I should be fine then? I wish they had bigger screens…LOL

It’s too bad Picard can’t do that…I use another program I run in Windows and it has no problem…it’s just not as complex as your script. I won’t give up your script because it is way better!!! Thanks for all your help again!!!

Wanted to share my latest update on my script, I just keep adding more detail and it’s working pretty good let me know if any of you out there like it!

$if($gt(%_bits_per_sample%,16),-=[%_bits_per_sample%bit]=-,)/
$upper(%_extension%)/
$if($eq(%releasetype%,album; soundtrack),Soundtracks/,$if2(
$set(_albumartistprefix,$rsearch(%albumartist%,^\(The|A\)\\s+))
$if(%_albumartistprefix%,$rreplace(%albumartist%,^\(%_albumartistprefix%\)\(.*\),\\2 \(\\1\)),%albumartist%/)))/
$if2($if($eq($len(%musicbrainz_albumid%),0),No MBID/))
$if($is_complete(),,$if($lt($matchedtracks(),%_totalalbumtracks%),_Incomplete/))
$if($or($eq(%releasetype%,EP),$eq(%releasetype%,single)), EPs & Singles/)
$if2(%originalyear%,$left(%originaldate%,4),$left(%date%,4),0000) - %albumartist% - %_albumfolder%/$if(%date%,$left(%date%,4),0000) -
$replace(
$replace($rreplace($if2($if2(%albumartist%,%artist%))-$if2(%_albumfolder%,%album%),[_:*?"<>|], -),?,), ,_)
$if(%_releasecomment%,-[$title(%_releasecomment%)],)
$if($ne_all(%catalognumber%,none,[none]),$if(%catalognumber%,$upper(
-$if(%releasecountry%,\(%releasecountry%)-$replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($rsearch(%catalognumber%,\(.+?\)\(?:; |\$\)+),_,),⋅,),/,),:,),*,),?,),",),<,),>,),|,), ,)\))))
$if($eq(%label%,Mobile Fidelity Sound Lab),-\(Mobile_Fidelity_Sound_Lab\),)$if($eq(%releasestatus%,bootleg),-BOOTLEG,)
$if($eq(%releasetype%,single),-\(CDMaxi\)-SINGLE,$if($eq(%releasetype%,ep),-EP,$if($inmulti(%releasetype%,soundtrack),-OST,$if($inmulti(%releasetype%,live),-LIVE,$if($inmulti(%releasetype%,compilation),-COMPILATION,)))))
$if($eq(%media%,Digital Media),-WEB,)$if($in(%media%,Vinyl),-VINYL,)$if($eq(%media%,SHM-CD),-SHM,)$if($eq(%media%,Blu-spec CD),-BLU-SPEC,)
$if($in(%media%,CD),$if($gt(%totaldiscs%,1),-%totaldiscs%CD,-CD),)$if($in(%media%,Vinyl),$if($gt(%totaldiscs%,1),-%totaldiscs%LP,),)$if($in(%media%,Bluray),$if($gt(%totaldiscs%,1),-%totaldiscs%BD,),)$if($in(%media%,Digital Media),$if($gt(%totaldiscs%,1),-%totaldiscs%DM,),)
$if($ne(%_extension%,mp3),$upper(-%_extension%))$if($if2(%date%,%originalyear%,%originaldate%),)-NOGROUP
$if($gt(%_bits_per_sample%,16), [%_bits_per_sample%bit $div(%_sample_rate%,1000)kHz])
/$if($in(%media%,Vinyl),%_musicbrainz_tracknumber%,$if($gt(%totaldiscs%,1),%discnumber%,)$num(%tracknumber%,2)). $if($and(%_multiartist%,$not($inmulti(%releasetype%,soundtrack))),%artist% - - ,)$truncate(%title%,70)

Add Tagger Script:

$set(_albumfolder,%album%)
$if(%discsubtitle%,$set(album,%album%: %discsubtitle%))