SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

New Filename mask Requested

Well, I have been using both Jaikoz and Picard and was wondering if I could get a file naming schema added. I have been using Bob Swift’s script with additional adjustments as follows:

$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,1)
$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(%_releasecomment%,%_aTitleDisambig%), \(%_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% \($title(%_releasecomment%)\),%album%))
$set(_bitrate,$rreplace(%_bitrate%,\\.[0-9]*\$,))

$if($eq(%_nAlbumType%,Classical),$set(_nFilePath,%_cClassical%/%_nYear%%_nANT%%_releasecomment% [%media% ] [%releasetype%]/))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFilePath,%_cSoundtrack%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%releasetype%]/))
$if($eq(%_nAlbumType%,Other),$set(_nFilePath,%_cOther%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%releasetype%]/))
$if($eq(%_nAlbumType%,Single),$set(_nFilePath,%_nInitial%/%_nPAAS%/%_cSingles%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%releasetype%]/))
$if($eq(%_nAlbumType%,Standard),$if($eq($if2(%musicbrainz_albumartistid%,%_cVariousArtistID%),%_cVariousArtistID%),
    $set(_nFilePath,%_cVariousArtist%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%releasetype%]/),
    $if($eq($if2(%musicbrainz_albumartistid%,%_cUnknownArtistID%),%_cUnknownArtistID%),
        $set(_nFilePath,%_cUnknownArtist%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%releasetype%]/),
        $set(_nFilePath,%_nInitial%/%_nFAAPS%/%_nYear% %_nANT%%_releasecomment% [%media% ] [%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.                                                      #
#                                                                      #
########################################################################
)

I’ve created a similar file naming in Jaikoz:

ifnotempty4(albumartistsort.substring(0,1),artistsort.substring(0,1),albumartist.substring(0,1),artist.substring(0,1),'/')
+ ifnotempty2(albumartist,artist,'/')
+ ifnotempty(album,' ')
+ ifnotempty(subtitle,' (')
+ ifnotempty(albumversion,") [")
+ ifnotempty(media,'] [')
+ifnotempty(mbreleasetype,']/')
+ ifnotempty(pad(discno,2),' - ')
+ ifnotempty(pad(trackno,2),' - ')
+ ifnotempty(title," [")
 + ifnotempty(audiobitspersample,' bit] [')
+ifnotempty(audiobitrate,']')

But they do not match…I would like to have the same file structure because I like how Bob’s seperates the music by first letter of last name (e.g. ~A~) but also looks at singles, soundtracks, groups that starts with a number, etc. Would it be possible to add this for me?

Ohh, you will see above that I was using subtitle in the Jaikoz version…I have been using that field to actually have the correct subtitle information, mostly for soundtracks…you don’t have to use that. I can manually add that information back into the album title field.

A post was split to a new topic: Different Rules for Genre and Grouping

Hi, the big difference is Bobs script is much more complex !

I am not going to even attempt to understand Bobs Picard script, but Im happy to help you with the jaikoz script if you can explain what it doesn’t currently do with some example filenames.

1 Like

OK…here goes:
Artist: The Andrews Sisters
Album: Greatest Hits: The 60th Anniversary Collection
Media: Digital Media
Year: 1998
MBreleasetype: Album
Album Version: Null
disc no: 1
track no: 1
title: Bei mir bist du schön (Means You’re Grand)
audiobitspersample: 16
audiobitrate:256 kbps (VBR)

File Path Should Be:

~A~/Andrews Sisters,The/[1998] Greatest Hits_The 60th Anniversary Collection [Digital Media] [Album]/01-01 Bei mir bist du schön (Means You're Grand) [16 Bit] [256 kbps (VBR)]

After the word Collection…since the field Album Version does not have anything it will skip it, otherwise it should show in (). Make sense?

Now lets say this album was not a greatest hits but a compilation. Bob’s script doesn’t put it under ~V~ for various artists. It creates a folder [Various Artists]

If the album is a soundtrack, then it creates a folder [Soundtracks].

If the artist start with a number like 4 Non Blondes…it creates a folder ~#~
image

I believe Bob’s script uses the sort album artist field to populate these folders.

Does this make sense?

So the issue is just getting the first folder right ?

We have a separate rename mask for compilations so you don’t have to put all the logic into one mask

1 Like

Correct…getting first folder right.

I have put the logic into a function (firstFolder) which i then call from the mask, the function can be put together with the mask, or if you want to function to be accessible to all masks you can use the Add Javascript Function option when within the Edit mask screen

function firstFolder()
{
   if(mbreleasetype=='Soundtrack')
   {
       return '[Soundtrack]' + '/';
   }
   else if(albumartist== 'Various Artists')
   {
       return '[Various Artists]' + '/';
   }
   else if(!isNaN(albumartistsort.substring(0,1)))
   {
       return '#' + '/'
   }
   else
   {
       return ' ~ ' + ifnotempty4(albumartistsort.substring(0,1),artistsort.substring(0,1),albumartist.substring(0,1),artist.substring(0,1),' ~ /');
   }
}

firstFolder()
+ ifnotempty2(albumartist,artist,'/')
+ ifnotempty(album,' ')
+ ifnotempty(subtitle,' (')
+ ifnotempty(albumversion,") [")
+ ifnotempty(media,'] [')
+ifnotempty(mbreleasetype,']/')
+ ifnotempty(pad(discno,2),' - ')
+ ifnotempty(pad(trackno,2),' - ')
+ ifnotempty(title," [")
 + ifnotempty(audiobitspersample,' bit] [')
+ifnotempty(audiobitrate,']')

This does what you want as as a I can understand it, and should be easy enough for you to modify as required.

1 Like

Oh cool!!! Thank you so much!!!

I’m having two problems. I’m having a problem with albumversion on getting the first ( and same thing for media getting the first [. Any suggestions?

Sorry I don’t understand what you mean.

I put it into my data now. When the information for albumversion is pulled I would expect () around the data. Same thing for media…I would expect [ ] around the data. Obviously, I would like this in the coding instead of me having to manually correct data so I shows properly but it is a workaround I can do.

Anyhoo, I found another problem and it is specific to soundtracks. When Jaikoz pulls the information for my music it changes soundtracks to albums but had Soundtrack field with a checkmark. I do not consider this proper since the release type should show soundtrack. Any ideas?