Repository for neat file name string patterns and tagger script snippets

@tdiaz Great Update, big Improvements!

…and It’s 2.0 now, it does what I want, it’s been taken apart function by function.

Gone through, line by line and the CBR/VBR section has been fixed up a lot.

I had some squirrelly voodoo going on with the File Metrics being created. It was probably a combination of things script wise and pre-processed file wise.

With “Ignore Tags” set, to where I’m just over-riding the two I use within the script for special album placement, it’s all good!

I had some cross-use of %_underScore% vs %noUnderScore% so some tags were getting created and then that was having an affect on anything that already had and MBID …and the unintended tags.

Sorry for clogging up the thread … :slight_smile:

Now I’ll go mess with the Python for a bit … and see what I come up with.

2 Likes

I just wanted to share that I updated my script to v2.0 if interested check it out. And once again thanks the all the people who help me out within this board, it’s like school for me I just keep on learning from the great teachers who dwell here!

1 Like

EDIT: I found a serious misplaced parenthesis error in my script. It was causing soundtracks to become completely messed up. I’ve replaced it below with my corrected version.

I rewrote my script to make it a little more compact. I used to have a lot of repeated code, but now I pulled the common code out of the $if statements and consolidated it.

I also added a feature I just discovered to clean up my folder names. I added some scripts to set control variables and then my naming script adds some disambiguating elements to file names only where necessary.

I have a couple versions of the same release, and I was using release comments to keep them in separate folders. The unfortunate side effect of this was presence of release comments on releases where I didn’t need them. Now I can designate only certain releases to add the release comment to the folder name, while all the rest are unaffected. Since variables are written to the files as tags, I only have to designate the release once, and it will always use the alternate naming script.

In this test, you can see the AKB48 single has it’s release comments (Type-A, Type-B) in the folder name, while the Rush album doesn’t. Kate Bush’s Cloudbusting single now has it’s media type in the folder name, but none of the other albums do.

In the Scripting tag, I added the following lines, each in it’s own script:

$set(usereleasecomment,1)
$set(usemediatype,1)
$delete(usereleasecomment)
$delete(usemediatype)

I also have a common script that’s set to run automatically.

$if($gt(%_totalalbumtracks%,99),$set(tracknumber,$num(%tracknumber%,3)),$set(tracknumber,$num(%tracknumber%,2)))

My full naming script is:

$replace(
$replace(
$replace(
$replace(
$replace(
$replace(
$if($in(%releasetype%,soundtrack),
	$noop(Soundtracks)
	Soundtrack/~
	$left($swapprefix(%album%,A,An,The),1)~/$swapprefix(%album%,A,An,The),
		$if(%compilation%,
		$noop(Various artist albums)
		Various Artists/~
		$left($swapprefix(%album%,A,An,The),1)~/$swapprefix(%album%,A,An,The),
		$noop(Normal albums)
		~$left($if2(%albumartistsort%,%artistsort%,%albumartist%,%artist%),1)~/
		$if2(%albumartistsort%,%artistsort%,%albumartist%,%artist%)/%album%))
	$noop(Common path)
	$if(%usereleasecomment%,$if(%_releasecomment%, \(%_releasecomment%\)))
	$if(%usemediatype%,$if(%media%, \(%media%\)))
	$if($in(%releasetype%,single), \(Single\))
	$if($in(%releasetype%,ep), \(EP\))/
	$if($gt(%totaldiscs%,1),%discnumber%)
	$if($gt(%_totalalbumtracks%,99),$num(%tracknumber%,3),$num(%tracknumber%,2)) - %artist% - %title%
,*,[x])
,?,)
,:,-)
,",')
,<,{)
,>,})
4 Likes

I was playing around a little just to satisfy myself as to what would really work for me as a script. Came up with this in two days may have a bug here and there but I thought maybe it would help someone out who doesn’t understand the tagger-script language and needed a pretty cool script. This script goes about 3 layers deep but it has lots of info for each album. Like I said there is a chance it may have a few errors but overall not too bad, feel free to play with it if you like.

$if($inmulti(%releasetype%,soundtrack),Soundtrack,$swapprefix($if2(%_artists_album_primary_std%,%artist%),The,Die,Le))
/$if2(%originalyear%,$left(%originaldate%,4),$left(%date%,4),0000) - %album%
$if($eq(%releasestatus%,promotion), [Promo],)
$if($eq(%releasestatus%,bootleg), [Bootleg],)
$if($eq(%releasetype%,album), [Album],
$if($eq(%releasetype%,single), [Single],
$if($eq(%releasetype%,ep), [EP],
$if($eq(%releasetype%,broadcast), [FM],
$if($eq(%releasetype%,other), [Other],
$if($inmulti(%releasetype%,dj-mix), [DJ Mix],
$if($inmulti(%releasetype%,remix), [Remix],
$if($inmulti(%releasetype%,soundtrack), [OST],
$if($inmulti(%releasetype%,live), [Live],
$if($inmulti(%releasetype%,mixtape/street), [Mixtape],
$if($inmulti(%releasetype%,compilation), [Compilation],)))))))))))
/$if(%date%,[$left(%date%,4)] ,----)
$if(%media%,[$title(%media%)] ,)
$if($gt(%totaldiscs%,1),[%totaldiscs%CD] ,)
$if(%label%,$title([%label%])
$if(%catalognumber%,$title([%catalognumber%]))
$if(%releasecountry%, [%releasecountry%]))
/$upper(%_extension%)
$if($gt(%_bits_per_sample%,16), [%_bits_per_sample%bit $div(%_sample_rate%,1000)kHz])
/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,))
/$if($in(%media%,Vinyl),%_musicbrainz_tracknumber%,$num(%tracknumber%,2)). $if(%_multiartist%,%artist% - ,)$truncate(%title%,70)

Results:
masterpiece

1 Like

A post was split to a new topic: Help with finding or making tagger script to handle (feat. …)

Here is my final version:

$swapprefix($if2(%_artists_album_primary_std%,%artist%),The,Die,Le)
/$replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($swapprefix($if2(%albumartist%,%artist%),The,Die,Le),",''), meets , & ), X , & ), × , & ),; , & ), x , & ), | , & ), • , & ), ⋅ , & ), and , & ),+,&), with , & ), _ , & ), vs , & ), vs. , & ) - $replace($replace($truncate(%album%,100),",''),:,-)
$if($gt(%totaldiscs%,1), %totaldiscs%CD)
$if($in(%media%,Vinyl), [Vinyl],)
$if($in(%media%,Cassette), [Cassette],)
$if($eq(%releasestatus%,promotion), [Promo],)
$if($eq(%releasestatus%,bootleg), [Bootleg],)
$if($ne_all(%catalognumber%,none,[none]),$if(%catalognumber%, $upper([$replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($rsearch(%catalognumber%,\(.+?\)\(?:; |\$\)+),_,),⋅,),/,),:,),*,),?,),",),<,),>,),|,), ,)])))
$if(%date%, [%date%],)
$if($eq(%releasetype%,album), [Album],
$if($eq(%releasetype%,single), [Single],
$if($eq(%releasetype%,ep), [EP],
$if($eq(%releasetype%,broadcast), [FM],
$if($eq(%releasetype%,other), [Other],
$if($inmulti(%releasetype%,dj-mix), [DJ Mix],
$if($inmulti(%releasetype%,remix), [Remix],
$if($inmulti(%releasetype%,soundtrack), [OST],
$if($inmulti(%releasetype%,live), [Live],
$if($inmulti(%releasetype%,mixtape/street), [Mixtape],
$if($inmulti(%releasetype%,compilation), [Compilation],)))))))))))
$if($ne(%_extension%,mp3), $upper(%_extension%))
$if($gt(%_bits_per_sample%,16), %_bits_per_sample%bit $div(%_sample_rate%,1000)kHz)
/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,))
/$if($in(%media%,Vinyl),%_musicbrainz_tracknumber%,$num(%tracknumber%,2)). $if($and(%_multiartist%,$or(%compilation%,%_artists_album_additional_id%)),%artist% - ,)$truncate(%title%,70)

Last edit: HERE
Full info: HERE

Result:

2 Likes

I Just made an alternate script I like to borrow ideas and see what I can come up with. It has similarities to my other script but it puts albums into folder categories like Studio albums, Live albums, singles, etc…
of course, as usual, there may be an issue somewhere or there but overall it’s working pretty good!

The Script:

$if($gt(%_bits_per_sample%,16),-=[%_bits_per_sample%bit]=-,)/
$upper(%_extension%)/
$if2($if($eq($len(%musicbrainz_albumid%),0),No MBID/$if2(%albumartist%,%artist%),)/
$if($and($lt($matchedtracks(),%totaltracks%),$lt($matchedtracks(),60)),Incomplete Releases/$if2(%albumartist%,%artist%),$if2(Artists/$if2(%albumartist%,%artist%)))/
$if($eq(%releasetype%,album; soundtrack),Soundtracks/,)
$if($eq(%releasestatus%,promotion),Promo's/,)
$if($eq(%releasestatus%,bootleg),Bootlegs/,)
$if($eq(%releasetype%,album),Studio Albums/,
$if($eq(%releasetype%,single),Singles/,
$if($eq(%releasetype%,ep),EP's/,
$if($inmulti(%releasetype%,soundtrack),OST/,
$if($inmulti(%releasetype%,live),LIVE/,
$if($inmulti(%releasetype%,compilation),Compilations/,
$if($eq(%releasetype%,album; soundtrack),Soundtracks/,))))))))
$replace($replace($rreplace($if($not($inmulti(%releasetype%,soundtrack)),$if($eq(%albumartist%,Various Artists),VA,%albumartist%)-)%album%,[_:*?"<>|], -),?,), ,_)
$if($eq(%releasestatus%,promotion),-PROMO,)
$if($eq(%releasestatus%,bootleg),-BOOTLEG,)
$if($ne_all(%catalognumber%,none,[none]),$if(%catalognumber%,$upper(-\($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($rsearch(%catalognumber%,\(.+?\)\(?:; |\$\)+),_,),⋅,),/,),:,),*,),?,),",),<,),>,),|,), ,)\))))
$if($eq(%releasetype%,single),-\(CDMaxi\)-SINGLE,
$if($eq(%releasetype%,ep),-EP,
$if($eq(%releasetype%,broadcast),-FM,
$if($eq(%releasetype%,other),-OTHER,
$if($inmulti(%releasetype%,dj-mix),-DJ MIX,
$if($inmulti(%releasetype%,remix),-REMIX,
$if($inmulti(%releasetype%,soundtrack),-OST,
$if($inmulti(%releasetype%,live),-LIVE,
$if($inmulti(%releasetype%,mixtape/street),-MIXTAPE,)))))))))
$if($gt(%_bits_per_sample%,16),-[%_bits_per_sample%bit,)
$if($gt(%_sample_rate%,48000), $div(%_sample_rate%,1000)kHz],)
$if($in(%media%,Vinyl),-VINYL,)
$if($in(%media%,Cassette),-CASSETTE,)
$if($eq(%media%,Hybrid SACD),-[Hybrid-SACD],)
$if($eq(%media%,SACD),-[SACD],)
$if($eq(%media%,SHM-CD),-[SHM-CD],)
$if($eq(%media%,SHM-SACD),-[SHM-SACD],)
$if($eq(%media%,Digital Media),-WEB,)
$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%,Digital Media),$if($gt(%totaldiscs%,1),-%totaldiscs%CD,),)
$if($ne(%_extension%,mp3),$upper(-%_extension%))
$if($if2(%date%,%originalyear%,%originaldate%),-$left($if2(%date%,%originalyear%,%originaldate%),4), [0000])-PiCARD
/$if($in(%media%,Vinyl),$if($gt(%totaldiscs%,1),LP$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
$if($in(%media%,CD),$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
$if($in(%media%,Digital Media),$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
/$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)

Results:
result

If you like this script give me some likes, please. If there are issues feel free to correct them and let others know. I spend way too much time playing with tagger script and you would think I would be a little better with it by now. Anyway, maybe it will help somebody out there!

1 Like

Fine Tuning and a little house cleanup v2.1

1st you will need 3 scripting files
1: 4 Digit Date: $set(date,$left(%date%,4))
2: Release Comment: $set(album,$if(%_releasecomment%,%album% ($title(%_releasecomment%)),%album%))
3: Remove feat from album title: $set(album,$rreplace(%album%,\s(feat. [^)]+),))

$if($gt(%_bits_per_sample%,16),-=[%_bits_per_sample%bit]=-,)/
$upper(%_extension%)/
$if2($if($eq($len(%musicbrainz_albumid%),0),No MBID/$if2(%albumartist%,%artist%),)
,$if($eq(%releasetype%,album; soundtrack),Soundtracks/,)
,$if($and($or($eq(%releasetype%,album; compilation),$or($eq(%releasetype%,album),$eq(%releasetype%,compilation))),$eq(%albumartist%,Various Artists)),Compilations/,)
,$if($in(%album%,Promo Only),Promo Only/,)
$set(_albumartistprefix,$rsearch(%albumartist%,^\(The|A\)\\s+))
,$if($and($lt($matchedtracks(),%totaltracks%),$lt($matchedtracks(),60)),Incomplete Releases/$if2(%albumartist%,%artist%),$if(%_albumartistprefix%,$rreplace(%albumartist%,^\(%_albumartistprefix%\)\(.*\),\\2 \(\\1\)),%albumartist%)))/
$replace($replace($rreplace($if($not($inmulti(%releasetype%,soundtrack)),$if($eq(%albumartist%,Various Artists),VA,%albumartist%)-)%album%,[_:*?"<>|], -),?,), ,_)
$if($eq(%releasestatus%,promotion),-PROMO,)
$if($eq(%releasestatus%,bootleg),-BOOTLEG,)
$if($ne_all(%catalognumber%,none,[none]),$if(%catalognumber%,$upper(-\($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($replace($rsearch(%catalognumber%,\(.+?\)\(?:; |\$\)+),_,),⋅,),/,),:,),*,),?,),",),<,),>,),|,), ,)\))))
$if($eq(%releasetype%,single),-\(CDMaxi\)-SINGLE,
$if($eq(%releasetype%,ep),-EP,
$if($eq(%releasetype%,broadcast),-FM,
$if($eq(%releasetype%,other),-OTHER,
$if($inmulti(%releasetype%,dj-mix),-DJ MIX,
$if($inmulti(%releasetype%,remix),-REMIX,
$if($inmulti(%releasetype%,soundtrack),-OST,
$if($inmulti(%releasetype%,live),-LIVE,
$if($inmulti(%releasetype%,mixtape/street),-MIXTAPE,)))))))))
$if($gt(%_bits_per_sample%,16),-[%_bits_per_sample%bit,)
$if($gt(%_sample_rate%,48000),-$div(%_sample_rate%,1000)kHz],)
$if($in(%media%,Vinyl),-VINYL,)
$if($in(%media%,Cassette),-CASSETTE,)
$if($eq(%media%,Hybrid SACD),-[Hybrid-SACD],)
$if($eq(%media%,SACD),-[PS3-SACD],)
$if($eq(%media%,DVD-Audio),-[DVD-A],)
$if($eq(%media%,SHM-CD),-[SHM-CD],)
$if($eq(%media%,SHM-SACD),-[SHM-SACD],)
$if($eq(%media%,Digital Media),-WEB,)
$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%,Digital Media),$if($gt(%totaldiscs%,1),-%totaldiscs%CD,),)
$if($ne(%_extension%,mp3),$upper(-%_extension%))
$if($if2(%date%,%originalyear%,%originaldate%),-$left($if2(%date%,%originalyear%,%originaldate%),4), [0000])-PiCARD
/$if($in(%media%,Vinyl),$if($gt(%totaldiscs%,1),LP$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
$if($in(%media%,CD),$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
$if($in(%media%,Digital Media),$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)$if(%discsubtitle%, - %discsubtitle%,)))
/$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)

Results:
Annotation 2020-01-17 214818

2 Likes

tdiaz thanks so much for your time and sharing your script. It is doing basically exactly what I have been looking for. I made a small tweak to the file naming to get [Year] ahead of the album name but other than this code is the bees knees.

Out of curiosity, are you revisiting or planning to expand code section re:bit rates for files in excess of 320? I’d love to add in higher bit rates for lossless audio but not sure where to start.

Thanks again!

Hello all,

I know very little about scripting, so I have two scripts that I copied from the old thread, in the old forum that was perfect for my needs. It’s been doing an excellent job for years but I need help in modifying it for a new “need” lol. As a result I have two questions:

1- Back then I copied a script for Single Artists, and another for Various Artists. Do we still need two separate ones? Basically, what I do is paste the “Various Artists” script whenever I’m tagging that type of album, the rest of the time I just have the “Single Artist” Script. Is there a way to incorporate both into one so that I don’t have to keep copying and pasting?

2- I would now like the script to treat Soundtracks differently. If it’s a soundtrack release type then I would like it placed in a folder called “[Soundtrack]”. Currently, my Various Artists script places the album in a “[Various Artists]” folder, so I would like the same thing, but for soundtracks. If it’s not a soundtrack then it would simply go in “[Various Artists]” as it has been doing.

To reiterate, the two questions are: Can I combine them? and how can I separate the Soundtracks from all other Various Artists releases?

Here are the two scripts:

Single Artists:

$rreplace($replace($replace($replace($replace($replace($replace($replace(
$if2(%albumartistsort%,%artist%)/%albumartist% - 
$if(%originaldate%,[$left(%originaldate%,4)]) %album%
$if($eq(%releasetype%,ep),[EP]) 
$if($eq(%releasetype%,single),[Single]) / 
$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2)
$if(-%compilation%, - %artist%) - %title%
,?,),_,-),*,x),:,-),",),|, ),<,[),>,])

Various Artists:

$rreplace($replace($replace($replace($replace($replace($replace($replace(
$if2([Various Artists])/
$if(%date%,[$left(%date%,4)]) %album%
$if($eq(%releasetype%,ep),[EP])
$if($eq(%releasetype%,single),[Single])/ 
$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2)
$if(-%compilation%, - %artist%) - %title%
,?,),_,-),*,x),:,-),",),|, ),<,[),>,])

In the end a soundtrack would look something like this:
\Music\[Soundtrack]\[1995] The Karate Kid - Original Movie Soundtrack\10 - Joe Esposito - You're the Best.mp3.
While any other Various Artists release would like this:
\Music\[Various Artists]\[1996] Pure Disco\05 - Gloria Gaynor - I Will Survive.mp3
The Single Artists would not change either. It would look like this:
\Music\Aaliyah\Aaliyah - [2002] I Care 4 U\02 - Aaliyah - Are You That Somebody.mp3

Thank you all for any help, I would greatly appreciate it!

The script that I use automatically processes soundtracks and singles differently, as well as Various Artists, and a few other things. It’s a bit lengthy (because I haven’t gone in an optimized it yet), but I’ve written and heavily commented it such that it should be easy to follow and pick pieces from or customize to fit your needs. It basically creates all the various “elements” of the path and file name, and then assembles them to meet the appropriate release criteria. If you have any questions, please just ask.

$noop(
#######################################################################
#
#  Picard File Naming Script                               2019-01-31
#  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
#
#  For tagging and filing classical music using the Classical file
#  naming scheme, a user script must be enabled that sets the
#  _isClassical processing flag.
#
#  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
#
#######################################################################
)

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


$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(_aTitleMaxLength,65)
$set(_tTitleMaxLength,65)
$set(_tFilenameMaxLength,120)


$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(
-----------------------------------------------------------------------
-  Trim the album and track names used to create directories and tracks
-  if they are longer than the maximum lengths set in the "Constants"
-  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(
#######################################################################
#
#  RegEx Constants
#
#######################################################################
)
$set(_reCaseInsensitive,\(?i\))


$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%])
)

$set(_nYear,[$left($if2(%originaldate%,%originalyear%,%date%,0000),4)])
$set(_nTNum,$if($gt(%_nTotalDiscs%,1),%_nDiscNum%-,)$num(%_nTrackNum%,2))


$noop(
#######################################################################
#
#  Set Album Type [Single, Soundtrack, Classical or Standard]
#
#  Process as Classical
#	Format: /[Classical]/Album Artist/[year] Album/Disc-Track [Composer] Title
#
#  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($if($and($eq($if2(%_nAlbumArtistID%,%_cVariousArtistID%),%_cVariousArtistID%),$in(%_secondaryreleasetype%,soundtrack)),$set(_nAlbumType,$if2(%_nAlbumType%,Soundtrack))))
$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))


$noop($set(_nYear,%_nYear% [%_t1%\,%_t2%]))


$if(%_isClassical%,$set(_nAlbumType,$if2(%_nAlbumType%,Classical)))
$set(_nAlbumType,$if2(%_nAlbumType%,Standard))


$noop(
#######################################################################
#
#  Set File Path
#
#######################################################################
)
$if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nFAAPS%/%_nYear% %_nANT%/))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nYear% %_nANT%/))
$if($eq(%_nAlbumType%,Single),$set(_nFilePath,%_nInitial%/%_nPAAS%/%_cSingles%/))
$if($eq(%_nAlbumType%,Standard),$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
    $set(_nFilePath,%_cVariousArtist%/%_nYear% %_nANT%/),
    $if($eq($if2(%musicbrainz_albumartistid%,%_cUnknownArtistID%),%_cUnknownArtistID%),
        $set(_nFilePath,%_cUnknownArtist%/%_nYear% %_nANT%/),
        $set(_nFilePath,%_nInitial%/%_nFAAPS%/%_nYear% %_nANT%/)
)))


$noop(
#######################################################################
#
#  Set File Name
#
#######################################################################
)
$if($eq(%_nAlbumType%,Classical),$set(_nFileName,%_nTNum%%_nFeat% %_nTNT%))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%))
$if($eq(%_nAlbumType%,Single),$set(_nFileName,%_nYear% %_nTNT%%_nFeat%))
$if($eq(%_nAlbumType%,Standard),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%))

$noop(
-----------------------------------------------------------------------
-  Trim the file name if it is longer than the maximum length set in
-  the "Constants" 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.
#
#######################################################################
)
3 Likes

Hi!

Thanks for the quick reply and for lending out your script.

It looks like it mostly formats the way I would like except for the standard (and singles) type. I don’t like to have my artists separated by letter. It seems all I have to do is remove the %_nInitial% from the script. But the thing I noticed as soon as I pasted it into musicbrainz was that the Year is not being populated. See the attached photo… any suggestions?
Script YR missing

Also, if there is more than one disk I’d like the sic number at the beginning of the file name to be padded. Where would I need to make that change?

Thanks again!

After testing it out I noticed that even though it shows up that way in the Picard preview it still works as intended and adds the year to the file when it renames and saves the file (my apologies for not testing!). After testing a couple of files I did notice something. Here’s an example of an album I have: Classics for Lovers, which is a compilation of different classical songs and composers so it is a “Various Artists” Release. Is it possible to modify the scripts so that an album such is this not placed under Various Artists but rather under the “Classical” type instead? When I ran your script it still placed it under Various Artists… so if it’s possible where would I make the change?

It’s possible to process the release as “Classical” as explained in the comments in the file itself:

#  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 would require the creation of a one-line script (under the “scripting” section) containing $set(_isClassical,1). Then simply enable the script before you load a release that you want processed as classical. Note that the default resulting format will be:

#  Process as Classical
#	Format: /[Classical]/Album Artist/[year] Album/Disc-Track [Composer] Title

For anything more extensive, I strongly recommend that you look into the “Classical Extras” plugin by @MetaTunes, which will provide access to much more information.

1 Like

Good morning!

Just want to thank you again for all your help!

When I first read that in the comments of the script I did not understand it, so thank you for explaining it :smiley: I have now been able to set it to fit my needs exactly. I don’t think I’ll ever have a set with more than 9 disks so even if the disk numbers aren’t padded it’s no big deal. In such exceptions I can always pad them myself with batch file renamers and such, so not important. I LOVE not having to switch between Various and Single artist releases anymore, this script is great!

Thanks again for everything @rdswift nad to the whole community!

1 Like

Here’s a small change that should take care of that for you automatically:

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

Wow thanks for that!

I just added it to between setting the file path and setting the file name sections and it didn’t work. The files were renamed as before. Where should I place it?

I tweaked this a bit to deal with effective bit rates higher than 3 places. (999)
I also did away with the CBR table.

$noop(############## Determine Bit Rate Integer Value #############)

$if($eq(%_devMode%,1),$set(_intBitRate,$rreplace(%_biitrate%,\\.\\d*\$,)),$set(_intBitRate,$rreplace(%_bitrate%,\\.\\d*\$,)))

$if($eq(%_devMode%,1),$set(_bitRateSpeed,%_saample_rate%KHz),$set(_bitRateSpeed,%_sample_rate%KHz))
$if($eq(%_devMode%,1),$set(_bitsPerSample,[%_biits_per_sample%]bit),$set(_bitsPerSample,[%_bits_per_sample%]bit))
$if($eq(%_devMode%,1),$set(_audioChannels,%_chaannels%ch),$set(_audioChannels,%_channels%ch))
$if($eq(%_devMode%,1),$set(_titleForFilename,%_tiitle%),$set(_titleForFilename,%title%))

$set(_bitRateType,$if($eq_any(%_intBitRate%,320,256,224,192,160,128,112,96,80,64,48,40,32,24,16,8),CBR$set(_cbrRateValue,%_intBitRate%)$set(_fileCBRRate,%_intBitRate%),VBR$set(_vbrRateValue,%_intBitRate%)))

$noop(Bitrate factors of 8.0 are most likely CBR with the remainder being VBR)

$if($eq(%_bitRateType%,VBR),
$if($gt(%_vbrRateValue%,339),$set(_fileVBRRate,320+),
$if($gt(%_vbrRateValue%,319),$set(_fileVBRRate,320),
$if($gt(%_vbrRateValue%,260),$set(_fileVBRRate,V0+),
$if($gt(%_vbrRateValue%,220),$set(_fileVBRRate,V0),
$if($gt(%_vbrRateValue%,191),$set(_fileVBRRate,V1),
$if($gt(%_vbrRateValue%,170),$set(_fileVBRRate,V2),
$if($gt(%_vbrRateValue%,150),$set(_fileVBRRate,V3),
$if($gt(%_vbrRateValue%,140),$set(_fileVBRRate,V4),
$if($gt(%_vbrRateValue%,130),$set(_fileVBRRate,V5),
$if($gt(%_vbrRateValue%,120),$set(_fileVBRRate,V6),
$set(_fileVBRRate,%_intBitRate%)
)))))))))))
$noop(######### File Naming Structure Variables Complete #########)

$noop(★ Pathname Generation Starts Here ★)

To Display values higher than what I’m calling ‘V0+’, 320, etc. You’ll need to add in an additional if-greater-than line with it’s accompanying parenthesis closing on the ))))))) line… and modify the ranges as desired.

Since Bit Rate is most commonly associated with MP3, I’m just accounting for those effective ranges when I’m applying the value to other than MP3 encoded files.

It’s generally assumed that an M4A of similar BR Value is going to be of no less quality than the MP3 format.

Of course, all of this only absolutely comparable if you have control of the bit stream from the moment it’s sourced and the quality of that source.

You can encode a flexi-disc off the back of a cereal box using an apparatus consisting of a Dixie Cup attached to a sewing pin … being manually dragged around in a circle on the medium… using a full on Lossless format and it’s still going to sound just as atrocious. e.g.: Overkill.

So we just have to ‘trust’ our ‘sources’ of data streams … that someone didn’t take a 16K bit rate file and transcode it to 128K :slight_smile:

$noop(############## Determine Bit Rate Integer Value #############)

$if($eq(%_devMode%,1),$set(_intBitRate,$rreplace(%_biitrate%,\\.\\d*\$,)),$set(_intBitRate,$rreplace(%_bitrate%,\\.\\d*\$,)))

$if($eq(%_devMode%,1),$set(_bitRateSpeed,%_saample_rate%KHz),$set(_bitRateSpeed,%_sample_rate%KHz))
$if($eq(%_devMode%,1),$set(_bitsPerSample,[%_biits_per_sample%]bit),$set(_bitsPerSample,[%_bits_per_sample%]bit))
$if($eq(%_devMode%,1),$set(_audioChannels,%_chaannels%ch),$set(_audioChannels,%_channels%ch))
$if($eq(%_devMode%,1),$set(_titleForFilename,%_tiitle%),$set(_titleForFilename,%title%))

$set(_bitRateType,$if($eq_any(%_intBitRate%,320,256,224,192,160,128,112,96,80,64,48,40,32,24,16,8),CBR$set(_cbrRateValue,%_intBitRate%)$set(_fileCBRRate,%_intBitRate%),VBR$set(_vbrRateValue,%_intBitRate%)))

$noop(Bitrate factors of 8.0 are most likely CBR with the remainder being VBR)

$if($eq(%_bitRateType%,VBR),
$if($gt(%_vbrRateValue%,339),$set(_fileVBRRate,320+),
$if($gt(%_vbrRateValue%,319),$set(_fileVBRRate,320),
$if($gt(%_vbrRateValue%,260),$set(_fileVBRRate,V0+),
$if($gt(%_vbrRateValue%,220),$set(_fileVBRRate,V0),
$if($gt(%_vbrRateValue%,191),$set(_fileVBRRate,V1),
$if($gt(%_vbrRateValue%,170),$set(_fileVBRRate,V2),
$if($gt(%_vbrRateValue%,150),$set(_fileVBRRate,V3),
$if($gt(%_vbrRateValue%,140),$set(_fileVBRRate,V4),
$if($gt(%_vbrRateValue%,130),$set(_fileVBRRate,V5),
$if($gt(%_vbrRateValue%,120),$set(_fileVBRRate,V6),
$if($gt(%_vbrRateValue%,95),$set(_fileVBRRate,V7),
$if($gt(%_vbrRateValue%,69),$set(_fileVBRRate,V8),
$if($gt(%_vbrRateValue%,44),$set(_fileVBRRate,V9),
$set(_fileVBRRate,%_intBitRate%)
))))))))))))))
$noop(######### File Naming Structure Variables Complete #########)

$noop(★ Pathname Generation Starts Here ★)

I added an additional line denoting ‘320’ vs. greater than 320 as well as filled in the lower values of V7,V8,V9 and anything lower just shows the actual number.

Just fill out the table as desired.
The “Dev Mode” is so you can see what your script is doing while using the Scripting Editor on the File Naming Option Pane.

The VBR Values correspond with LAME encoding presets. For CBR, the only values we actually care about per the specification are those ones. Anything over 320 you’ll need to make an entry in the VBR table to have them show the Integer value.

$if($gt(%_vbrRateValue%,500),$set(_fileVBRRate,%_intBitRate%)

If you want to see the actual file rate including anything past the decimal then put:

$if($gt(%_vbrRateValue%,500),$set(_fileVBRRate,%_bitrate%)

I’ve added a whole bunch of stuff for final sorting to the
MBP YA Magic-Script that does more stuff too. script since what was posted above. It’s currently v2.6a

1 Like

Actually, this sets a different variable. To make it work with the earlier script, replace the entire “Initialize Working Variables” section with:

$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(
-----------------------------------------------------------------------
-  Automatically pad disc and track numbers to the length of the total
-  number of discs and tracks.
-----------------------------------------------------------------------
)
$set(_PaddedDiscNum,$num($if2(%discnumber%,1),$len($if2(%totaldiscs%,1))))
$set(_PaddedTrackNum,$num($if2(%totaltracks%,1),$len($if2(%totaltracks%,1))))
$set(_nYear,[$left($if2(%originaldate%,%originalyear%,%date%,0000),4)])
$set(_nTNum,$if($gt(%_nTotalDiscs%,1),%_PaddedDiscNum%-,)%_PaddedTrackNum%)

2 Likes