I could use a little help for a custom script

Hello.

So: I’m trying to organize my collection and I’m looking to rename both files and folders.

I already gave a try to other scripts found here and there in the community, but they just don’t feet my needs.

So I’m kind of summoning your help here, in order to achieve something definitely simple.

I’d like to have something like this:

artist_name -> year - album_name -> 01 - track_name

When it comes to album consisting of two or more discs, I’d like it to be like this:

artist_name -> year - album_name -> cd1 -> 01 - track_name and
artist_name -> year - album_name -> cd2 -> 01 - track_name

As you may have noticed, I’m a HUGE fan of the space-hyphen-space pattern LOL .

I’m asking for help because I’m clearly unable to find a solution: syntax’s never been my thing, oh no.

Thank you so much for your time and patience guys: I appreciate that.

Thanks.

1 Like

Give something like this a try and see if it does what you want. I’m assuming that -> means a directory level… Warning, untested code follows.

%albumartist%/$left($if2(%originalyear%,%date%,0000),4) - %album%/$if($gt(%totaldiscs%,1),cd%discnumber%/,)$num(%tracknumber%,2) - %title%

You might also want to take a look at https://picard.musicbrainz.org/docs/scripting/ and https://picard.musicbrainz.org/docs/tags/ for more information regarding the scripts.

1 Like

Worked like a charm!
<3<3<3<3<3<3<3<3

Hey there!
Same as @uoutLou over here: lots of tries but no success…

Here’s what I’d like to see:
Music\B\The_Beatles\[1965]-Help!\The_Beatles-Help!-[1965]-07-Ticket_to_Ride.mp3
Music\A\Artist_FirstName_LastName\[Year]-Album_Name\Artist_FirstName_LastName-Album_Name-[Year]-CD1-01-Song_Name
Music\Various_Artists\Album_Name-[Year]\Album_Name-[Year]-CD1-01-Artist_Name-Song_Name

I’d like to have the underscores shown in the names to avoid any spaces.
Thank you so much for your help!

One easy way is to assigning your name to a variable, then replace all spaces in the variable with the underscore, then write the variable. Something like:

$set(_path,Music/B/The Beatles/[1965]-Help!)
$set(_filename,The Beatles-Help!-[1965]-07-Ticket to Ride)
$replace(%_path%, ,_)/$replace(%_filename%, ,_)

If you post a copy of your current script, I can take a shot at updating it for you.

2 Likes

Hey @rdswift, thank you so much!
I see what you’re doing in your script! that’s cool.
Ok so the closest script I came up with (from one I found) is this one:

$replace($rreplace(
$if($eq(%albumartist%,Various Artists),Various Artists,
$left($if2(%albumartistsort%,%artistsort%),1)/$left($rreplace($if2(%albumartistsort%,%artistsort%),; [^\)]+,), 60))
/
$if(%date%,[$left(%date%,4)]-)$left($replace(%album%,/,), 70)

$if($gt(%totaldiscs%,1),$if(%discnumber%, \(Disc %discnumber%\),),)
/
%albumartist%-%album%[$left(%date%,4)]-$num(%tracknumber%,2)-$left(%title%,120),[:?"_]+,), , )

I didn’t get how to insert the part you gave me.
I believe I need to write something instead of: Music/B/The Beatles/[1965]-Help!

$set(_path,Music/B/The Beatles/[1965]-Help!)

I was about to ask you how do you insert a script neatly the way you do but I figured it out!
Thanks @rdswift :+1:

Here is a script that should be pretty close to what you want. It is nowhere near being optimized, but I wrote it this way to help make it clear what is being done at each step and to make it a bit easier to customize to accommodate any changes in preferences. Also, an opportunity to do a bit of teaching / coaching.

The script is set out in three stages:

  • Stage one sets up local variables with each of the elements that we’ll be using in the naming string. This is so that each is processed only once, and each is done separately so that it’s easy to make changes to any individual element.

  • Stage two creates the directory and file name templates used for the two different options (i.e.: Various Artists versus Other).

  • Stage three selects which template to use and applies it. This is wrapped in the code to replace all spaces with underscores, again so that the replacement is applied to the final selected template and only performed once.

$noop(
********************************************************
***  Set up the various elements that we'll use for  ***
***  the naming so that we only process them once.   ***
********************************************************
)
$set(_AlbumName,$left($replace(%album%,/,_),70))
$set(_TrackName,$left($replace(%title%,/,_),120))
$set(_AlbumYear,[$left($if2(%originaldate%,%date%,----),4)])
$set(_AlbumNameAndYear,%_AlbumName%-%_AlbumYear%)
$set(_DiscAndTrackNumber,$if($gt(%totaldiscs%,1),CD%discnumber%-,)$num(%tracknumber%,2))

$noop(
********************************************************
***  Assemble the elements into directory and file   ***
***  name variables for the two different options.   ***
********************************************************
)
$set(_DirectoryVA,Various Artists/%AlbumNameAndYear%)
$set(_DirectoryOther,$firstalphachar($if2(%albumartistsort%,%artistsort%),nonalpha="#")/$if2(%albumartist%,%artist%)/%_AlbumYear%-%_AlbumName%)
$set(_FileVA,%_AlbumNameAndYear%-%_DiscAndTrackNumber%-%artist%-%_TrackName%)
$set(_FileOther,%artist%-%_AlbumNameAndYear%-%_DiscAndTrackNumber%-%_TrackName%)

$noop(
********************************************************
***  Determine which option to use and present the   ***
***  final directory and file name string to the     ***
***  renamer.  Note that the spaces are converted    ***
***  to underscores at this stage.                   ***
********************************************************
)
$replace($if($eq(%albumartist%,Various Artists),%_DirectoryVA%/%_FileVA%,%_DirectoryOther%/%_FileOther%), ,_)

Hopefully this gets you closer to the naming format that you want.

4 Likes

Really appreciate your time @rdswift!
I’m gonna look at it and get back to you.
Thanks!

Actually, I would suggest changing the last line of the script to:

$rreplace($if($eq(%albumartist%,Various Artists),%_DirectoryVA%/%_FileVA%,%_DirectoryOther%/%_FileOther%),[?*:\\/_ ]+,_)

That way it will change multiple underscore characters together into a single underscore. It just looks a bit cleaner.

4 Likes

Ok so I was just able to remove a “r” from your last line to get me closer to my goal…

$noop(
********************************************************
***  Set up the various elements that we'll use for  ***
***  the naming so that we only process them once.   ***
********************************************************
)
$set(_AlbumName,$left($replace(%album%,/,_),70))
$set(_TrackName,$left($replace(%title%,/,_),120))
$set(_AlbumYear,[$left($if2(%originaldate%,%date%,----),4)])
$set(_AlbumNameAndYear,%_AlbumName%-%_AlbumYear%)
$set(_DiscAndTrackNumber,$if($gt(%totaldiscs%,1),CD%discnumber%-,)$num(%tracknumber%,2))

$noop(
********************************************************
***  Assemble the elements into directory and file   ***
***  name variables for the two different options.   ***
********************************************************
)
$set(_DirectoryVA,Various Artists/%AlbumNameAndYear%)
$set(_DirectoryOther,$firstalphachar($if2(%albumartistsort%,%artistsort%),nonalpha="#")/$if2(%albumartist%,%artist%)/%_AlbumYear%-%_AlbumName%)
$set(_FileVA,%_AlbumNameAndYear%-%_DiscAndTrackNumber%-%artist%-%_TrackName%)
$set(_FileOther,%artist%-%_AlbumNameAndYear%-%_DiscAndTrackNumber%-%_TrackName%)

$noop(
********************************************************
***  Determine which option to use and present the   ***
***  final directory and file name string to the     ***
***  renamer.  Note that the spaces are converted    ***
***  to underscores at this stage.                   ***
********************************************************
)
$replace($if($eq(%albumartist%,Various Artists),%_DirectoryVA%/%_FileVA%,%_DirectoryOther%/%_FileOther%),[?*:\\/_ ]+,_)

This script gives me this:

And that’s how I’d like to see it:
Music/B/The_Beatles/[1965]-Help!/The_Beatles-Help!-[1965]-07-Ticket_to_Ride.mp3
Music/Various_Artists/[2005]-Coup_d’État,_Volume_1:_Ku_De_Ta_Prologue/Coup_d’État,_Volume_1:_Ku_De_Ta_Prologue-[2005]-CD2-05-Snowboy_feat._James_Hunter-I’ve_Got_to_Learn_the_Mambo

Thanks for your help!