Sharing my renaming script

Hi there,

I just want to share my picard renaming script, maybe he will help people :

I tried to write the script so it’s readable (not like almost all script we can found online). it’s indented when possible, and commented.

You can use the settings system to modify the behavior of renaming.

Actually it’s possible to separate (or not) folder by type in artist folder (Single/EP/Compilation …), use (or not) sub-folder for multi-disc, show (or not) the disc subtitle, order root folder with last.fm category OR by first letter of artist (A/Arthur, B/Bruno). It’s also possible to set the name of sub-folder in artist and also the one used for various/soundtrack.

Example of path :
~/Music/SoundTracks/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac
~/Music/Various/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac
~/Music/Category/Artist, The/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac
~/Music/Category/Artist, The/Compilations/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac
~/Music/Category/Artist, The/Singles/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac
~/Music/Category/Artist, The/EP/Album name - 2016 [Vinyl]/CD1~subtitle/01. Track.flac)

See ya

9 Likes

Really cool awesome script.

One question?

Why doesn’t it use Vinyl track numbers for Vinyl releases?

When tagging a vinyl release I want track numbers that look like this:
A1, A2, A3 … B1, B2, B3

I have tried using the following:

$if($ne(%_absolutetracknumber%,%_musicbrainz_tracknumber%), %_musicbrainz_tracknumber%,$num(%tracknumber%,2))

But that will not put in the leading zero on disc 2 and above when tagging multi-disc releases for tracks 1-9.

Basically I need to use the %_musicbrainz_tracknumber% only for vinyl releases and $num(%tracknumber%,2) for non-vinyl but I’m not quite sure how to make that happen.

Thanks

Hi,

It’s because i handle vinyl differently (related to ampache). I will add vinyl track numbering.

If i understand correctly, you want cd track number to be 01, 02 etc…well $num(%tracknumber%,2) is for that, so it must be good actually (with my script, all multi-disc have leading zero for track number, and i use $num(%tracknumber%,2))

What i’ve tested is this (replace at end of my script):
$noop(★ Track. Title ★)
$if($in(%media%,Vinyl),
$if(%musicbrainz_tracknumber%,%musicbrainz_tracknumber%. ), $if(%tracknumber%,$num(%tracknumber%,2). )
)
%_titleForFilename%

So if media type contain Vinyl, use musicbrainz vinyl/cassette style for track numbering, if not use basic track numbering with leading zero (in both case add [dot][space] after number), and append title.

It will look like this :
http://i.imgur.com/mLHxBcx.png

Let me know if it’s good, if not point me to some vinyl you own (musicbrainz url) so i check what type of info is present, and how i can handle vinyl track numbering better.

Edit : %_musicbrainz_tracknumber% was added in picard 1.3, so check your version before using this variable (on debian jessie current version is 1.2 for example)

1 Like

I’m a bit of a novice when it comes to python coding, but from looking at your code I was able to figure out how to do it. At least I thought I had it working earlier but I must have changed something as it’s not working now. I’ll figure it out.

I just have a couple other questions:

When renaming a Vinyl Double LP I don’t want the sub-folders to be called CD1 when Disc1 or Vinyl1 are more appropriate. I’m probably going to modify the script I’m using to use Disc instead of CD for everything. Any chance of an option to use CD1 for CDs and Disc1 for Vinyl?

When renaming a multiple disc release with more than 10 total discs is it possible to get a leading zero on discs 1-9? I’ve been manually editing the disc numbers in Picard but would prefer not to have to.

Any change of a separate folder for Live Albums? I’ve always kept Studio Albums separate from Live Albums.

I already added in releasecountry, label and catalognumber to the script I’m using as I have multiple copies of some releases such as both the European and US versions which I noticed your script dumped into the same folder.

I will keep playing with it trying to find my own solutions.

That’s about it. Overall thought I love the script and appreciate all the hard work you have put into it. Great Job!!!

As for the Vinyl numbering. Your solution is basically the same as what I came up with except I am setting _isVinyl as a flag earlier in the script. It works great for Vinyl releases which have Vinyl style track numbers entered in the Musicbrainz database. Unfortunately there are so many which don’t. At least they don’t require voting for the edits to track numbering to go thru.

I figured out where I had broken my script it when I looked at your code. I was checking for Vinyl in %releasetype% instead of %media% because I had cut and pasted and forgot to change to the correct database field.

For using Disc vs CD based on media type, i will explain the part to modify. Look at this code :
$if($gt(%totaldiscs%,1),
$if($and(%_discsubtitleForFilename%,$eq(%_showDiscSubtitle%,1)),
$if($eq(%_useSubDiscFolder%,1),/,[)CD%discnumber%~%_discsubtitleForFilename%$if($eq(%_useSubDiscFolder%,1),/,]/),
$if($eq(%_useSubDiscFolder%,1),/,[)CD%discnumber%$if($eq(%_useSubDiscFolder%,1),/,]/)
)
)/

So translation in plain english :

If (there is more than one disc) {
  if (disc subtitle is set AND user set to show subtitle) {
    if (user set to use subfolder for disc) {
      add "slash" (to indicate a folder)
    } else {
      add "opening bracket" (So we have [CD])
    }

    add "CD" + disc number + "~" + disc subtitle

    if (user set to use subfolder for disc) {
      add "slash" (to indicate a folder)
    } else {
      add "closing bracket" (So we have [CD])
    }
  } else {
    if (user set to use subfolder for disc) {
      add "slash" (to indicate a folder)
    } else {
      add "opening bracket" (So we have [CD])
    }

    add "CD" + disc number

    if (user set to use subfolder for disc) {
      add "slash" (to indicate a folder)
    } else {
      add "closing bracket" (So we have [CD])
    }
  }

As you see, we use CDx or CDx~subtitle for folder naming. So what we need is to check if it’s a vynil, and change CDx/CDx~subtitle to Discx/Disc~subtitle when necessary.

Original :
$if($eq(%_useSubDiscFolder%,1),/,[)CD%discnumber%~%_discsubtitleForFilename%$if($eq(%_useSubDiscFolder%,1),/,]/),
$if($eq(%_useSubDiscFolder%,1),/,[)CD%discnumber%$if($eq(%_useSubDiscFolder%,1),/,]/)

Transformed to use CD/Disc :
$if($eq(%_useSubDiscFolder%,1),/,[)$if($in(%media%,Vinyl),Disc,CD)%discnumber%~%_discsubtitleForFilename%$if($eq(%_useSubDiscFolder%,1),/,]/),
$if($eq(%_useSubDiscFolder%,1),/,[)$if($in(%media%,Vinyl),Disc,CD)%discnumber%$if($eq(%_useSubDiscFolder%,1),/,]/)

CD%discnumber% get replaced by $if($in(%media%,Vinyl),Disc,CD)%discnumber%

So before it was simply write CDx, and after :
if (there is Vinyl in media type) {
write Discx
} else {
write CDx
}

Sorry if it’s a bit long, but i think explaining Foobar scripting in c++ like pseudo code is good for better understanding.

For disc numbering, yeah it’s possible, i will post you the solution later.

For separate live album, i’m not sure. If there is tag on metabrainz database to handle this, yes it’s possible, i will look into it.

For vinyl numbering, yes it’s a problem. My idea was to check if media type is vinyl AND if vinyl numbering is not present, then take the disc number, replace with the letter at this position in alphabet (so disc 1 track 1 become disc A1, disc 2 track 1 become B1 etc…), but there is no function to transform number to letter position in alphabet (ah ah we’re just using some basic scripting language, it’s not c++ :D)

Version 0.2 was released :

  • [Added] Custom folder tag for multi-disc CD/Vinyl [CD1/Disc1]
  • [Added] Put multi-CD release in same folder [naming become 101/102/201…]
  • [Added] Vinyl can use musicbrainz style for track [A1/A2/B1…]
  • [Changed] Code cleanup in multi-disc naming to prevent duplicate code

So now folder will be “AlbumName - Year [CD1]” or “AlbumName - Year [Disc1]” for multi-disc (you can modify CD/Disc with settings)

If you choose to disable subfolder for multi-disc, you can now choose to have all track of all disc go in same folder. To prevent bad folder listing (having all track 01 of each disc at top) i’ve added disc number in front of track number (so, 101/101/201). It’s a common thing to have multi-disc in same folder with 3-number-track numbering, so it’s here. It will not be used when using vinyl numbering, because there’s already A/B/C for this.

And last you can choose to use musicbrainz style for track numbering of vinyl (A1/A2/B1…).

Edit :
Version 0.3.2 released :

  • [Fixed] Fix typo when getting if it’s EP

Version 0.3.1 released :

  • [Added] Handle live for main type
  • [Fixed] Main type ordering now check for Compilation->Live->Single->EP->Broadcast->Other->Album (i do this because tag type can be “album; live”, so with the old method we ended up with path like Album/Lives/AlbumName, now it’s Lives/AlbumName)

Live type will now use Lives/ (or what you set) subfolder.

I remade the code for main type ordering because before i was checking if it’s album, then single etc…making sub-subfolder in some case (eg. Album/Lives/AlbumName). Now it’s one type at a time (album being the most basic type, it’s the last to be checked).

But since live is a secondary type like compilation, i’m going to remade the code to better handling type ordering.

Edit 2 :
Ok it’s commited, now it check if’s a secondary type (compilation/live etc…), if not check the main type (since it can only have one main type, it’s not necessary to do if/else/if/else etc…)

WOW that was a quick response!!

Question:

I just tested the new script with


I am sorting by first letter of artist name with a slight modification as follows:
$upper($firstalphachar($if2(%_albumartistForFilename%, [~%_artistForFilename%~]),[~#~]))/

The files for the 12" Vinyl 1 get put into
[~#~]\38 Special\Compilations\Flashback -1987 [12_ Vinyl]\Disc1

The files for the 7" Vinyl 2 get put into
[~#~]\38 Special\Compilations\Flashback -1987 [7_ Vinyl]~Flashback Live\Disc2

Shouldn’t the files for the 7" Vinyl 2 be put into
[~#~]\38 Special\Compilations\Flashback -1987 [7_ Vinyl]\Disc2~Flashback Live

This doesn’t seem to be working correctly.

I however would prefer that both Disc1 and Disc2~Flashback Live be in the same folder.
[~#~]\38 Special\Compilations\Flashback -1987 [12_ Vinyl~7_ Vinyl]
I figure this would be difficult as it would require knowing the media type for all items in the release rather than just using the data from the current file.

Anyway, Great Script - Thanks So Very Much - You ROCK!!!

Ohh, i forget that i’m now using a variable to construct multi-disc part of the naming (to avoid repeating code), my bad :blush:
That’s fixed in 0.3.4

For the different media in multi-disc release, it’s the same problem exposed in “Further improvement” on the wiki page.

I think it’s possible to resolve this problem, but with global script only. Will look into it when i have some time.

Glade to see it’s useful for someone.

Did this version take care of the leading zero for discs 1-9 on multi-disc sets with 10 or more total discs? I haven’t tested it yet as I’m still in the middle of processing all the vinyl releases that I renamed when my vinyl solution wasn’t working properly.

Not yet, i know how to do it, but i don’t have any >9 disc release to test. Well i just have to choose 10 random song and tag cd1/2/3 etc, i’ll post the update when it’s good (10/15 min).

Edit :
Is this what you want ?

I have quite a number of set with more than 9 discs.
The first one that comes to mind is:

Anyway, I you aren’t probably getting sick of all the questions.

Just one more…

I notice that if a release doesn’t have a value set for %media% that your script will put an empty set of brackets in the folder name. Since you don’t put [CD] in the path when the media type is CD I guess this does identify the release as being without a media type entry. I prefer to actually use [CD] for CD releases and know if there is nothing listed then the release doesn’t have media type data.

I’m not asking for you to incorporate a choice to use [CD] into your script. I can figure that out myself. I’m just wondering if the empty brackets on releases without media type data are there by design.

I meant to say that I’m sure you are probably getting sick of all the questions.

No that’s cool don’t worry.

For empty [] yeah it’s here by design, maybe some [Unset] or [Undefined] may be better, but for now i always check media type before renaming.

Commited the change for disc numbering with leading zero when disc count > 9

I have to go, don’t hesitate if you have question, problem, idea etc…

I believe that I have managed to modify your MBP Magic-Script - v0.3.5 to meet my needs.

I would post the entire script but I’m not sure how to post code on here without the editor trying to render parts of it.

I can only think of two other features which your script currently doesn’t have.

  1. Option to choose sorting first letter of an artist’s first or last name when sorting by artist name. Some people prefer to have Bruce Springsteen sorted under S instead of B. I am currently sorting by first name but had everything by last name the last time I reorganized my library. I think some people might like the feature. Not too difficult to implement with the %_albumartist_sort% field.

  2. In the past I have included the track artist in the actual file-name anytime it is not the same as the album artist. Most of the time you will only see it on Various Artists releases which will for the most part show up in Various or in SoundTracks with your script. As these are really the only places I actually want to have this implemented doing the following will make that happen.

The current last line of your script is as follows:

%_titleForFilename%

You just need to replace that line with the following:

$if(%_isVarious%,
	$if($ne(%albumartist%,%artist%),%artist% - %_titleForFilename%,
		$if(%_isSoundTrack%,
			$if($ne(%albumartist%,%artist%),%artist% - %_titleForFilename%,
				%_titleForFilename%
			)
		)
	)
)

I’m sure this isn’t the most effecient way to do this and you would likely change the value of _titleForFilename somewhere earlier in the script but it does get the job done.

The one problem I ran into with my old script when I was testing all files was there are too many artists like a-ha where most of their releases list the %artist% as a-ha but the %albumartist% as A-Ha. That is the main reason I only want the track artist for Various and SoundTracks in the script that I use.

I don’t know if you are aware of it but there seems to be a minor issue with the way you sort artists by letter.

Jimi Hendrix will get sorted into J
but
The Jimi Hendrix Experience will go into H
Also
The J. Geils Band will get sorted into G instead of J
and
The Alan Parsons Project will get sorted into P instead of A

This seems to happen only some of the time when a groups name includes the group lead singer’s name after "The "

Other groups do get put where they are supposed to go:

The Mick Fleetwood Band gets sorted into M
The Phil Collins Big Band gets sorted into P

Obviously this is because of how the data has been entered into the MusicBrainz database but there are ways to get around it. Rather than using the first alpha character you should simply access the first alpha character to appear after "The " or just the 5th overall character of the albumartist.

Thanks for all your suggestion.
In 0.4.2 i’ve implemented the setting to use first or last name for artist ordering, but the thing about “the” you speak is not yet implemented (maybe letter if i have time).

I finally removed the empty bracket for unknown media type, since i always check if media type is present before renaming.

And last i now use release date instead of original group date for folder naming. I decided to do this because if you have 2 variant of one album, and both have the same name, you end up with all the track in the same folder. With release it’s not possible (well, it’s not true, if both got released the same year, the problem appear again !)

I try to keep the script the most generic as possible, but it’s not easy will all the possibility (the problem mainly come from user filling the database differently each other).

1 Like

@Ski-lleR
I know this is an old thread but I have question. I have played around with the script to do a few things differently. So far love it and it saves a ton of time and better than Media Monkey or Bliss.
Would it be easy to make Vinyl go into its own folder like the Eps/Singles. I have just been making a folder and moving them, not a big deal but would like it automated if possible. I have tried looking at the script and copying/adding parts to make it happen but haven’t had any luck.
Tried adding the following under the current places but it didn’t work.

$noop(★ CUSTOM SUBFOLDER BY TYPE ★)
$set(_vinylSubFolder,_Vinyl/)

$noop(★ Detect Album ★)
$if($in(%media%,album),
$set(_isVinyl,1)

$noop(★ Organize by type ★)
$if($eq(%_isVinyl%,1),%_VinylSubFolder%

That is all I could figure out as I don’t know scripting at all. So I tried and it didn’t work.

Thanks again for this great script.

1

I believe this:

should be:

$if($in(%media%,vinyl),

That should catch vinyl, 12" vinyl and 7" vinyl.

EDIT: I forgot the percent signs around mediatype.
EDIT again: It’s media, not mediatype. I had mp3tag open at the time and it displays the tagname as mediatype, while Picard calls it media.