Help Writing File Renaming Script For Plex Cleanup

Hi all!

I’ve used Picard for a a while just for general music tag processing before I copy the files onto my media server for Plex consumption, but never used it to organize the files and folders themselves.

I’d like to take up the task to standardize my folder structure and naming conventions across my music library, and really don’t want to do it by hand obviously, but I’m struggling with the scripting for the file rename functionality.

The biggest complication is I want to incorporate some “intelligence” in my scripting. I would like to try to separate singles into their own folder on the album level, and I want albums with multiple discs to separate them by “Disc 01”/“Disc 02” folders, as well as when there are multiple discs, I want the tracks filename to append the disc number before the track number (though I do understand that sort of defeats the purpose of the Disc folders, just a good fallback I think).

Here is an example of what I’d like for an album with 2 discs:
<artist name>/(<release year>) <release name>/"Disc" <disc number with leading 0>/<disc number><track number with leading 0> - <track name>

Which would translate to:
2Pac/(1996) All Eyez On Me/Disc 01/101 - Ambitionz as a Ridah.flac

If an album only has a single disc:
<artist name>/(<release year>) <release name>/<track number with leading 0> - <track name>

Which would translate to:
2Pac/(1995) Me Against the World/01 - Intro.flac

And finally, if the release were a single, not an EP or album:
<artist name>/"Singles"/(<release year>) <track name>/<track number with leading 0> - <track name>

Which would translate to:
Sleep Token/Singles/(2018) Jaws/01 - Jaws.flac

The more I’ve tried delving into the scripting language and tried to get something like what I want going, the more confused I wind up getting - I think because I’m trying to do too much at once, especially since this is my first foray into it.

If anyone could show me a script that can do this, and even better, explain the parts of it as well, I would be ever grateful. The time savings of this stands to be immense.

Thanks!

would like to try to separate singles into their own folder on the album level

Not sure what the ultimate goal here is, but just want to note that Plex added the option to separate music content by release type a few versions/years ago.

Path: Settings -> Library -> Group Albums By Type

Additional info: How to get the release type to work? - r/plexamp

The more I’ve tried delving into the scripting language and tried to get something like what I want going, the more confused I wind up getting

If anyone could show me a script that can do this, and even better, explain the parts of it as well

It sounds like you are hoping to learn and not just asking for someone to write a script for you, which I genuinely applaud. If you share what you’ve come up with so far, I’d be happy to provide pointers where able.

2 Likes

Appreciate such a quick reply!

On the first note, I was referring to the folder structure in my file system - breaking singles into their own folder. I already have Plex properly grouping releases by release type, but in the actual file system folder structure, I like to have all albums listed in the same level under an artist folder, and a “Singles” folder alongside those album folders where there are individual folders for each single.

Example:


Here’s what I have thus far. I was able to keep messing around with it and I may have gotten it, but I’d like some more professional input on if this is really doing what I think it is:

%albumartist%/
$if($eq(%releasetype%,Single), Singles/, %year% %album%/)
$if($gt(%totaldiscs%,1), Disc %discnumber%/, )
$if($gt(%totaldiscs%,1), %discnumber%$num(%tracknumber%,2), $num(%tracknumber%,2)) - %title%

Again, thanks a ton for your quick response and help, I appreciate how nice this community is.

1 Like

For sure - nothing jumps out as “incorrect” to me with what you’ve got, but others may have different ideas. Just a few notes:

  • Plex can get picky about folder structure. This should probably be fine, especially if you have the Prefer local metadata option enabled in settings, but wanted to highlight it in case you run into weirdness with matching or incorrect merges that the Plex agent sometimes does on it’s own.
  • More of a probing question to make sure you’re getting what you want out of the setup - I see you’re determining the single status from releasetype. Are you duplicating the singles from albums, or pulling them from the main album and moving them to the Singles folder? If the latter, there’s going to be some manual intervention needed as the album will have a different release ID in MB than the single.
  • Happy to see the Sleep Token representation - I’m thanking the deities that digital media doesn’t degrade with each listen like vinyl because Even In Arcadia hasn’t left the rotation in the last week :stuck_out_tongue:
1 Like

Yeah I familiarized myself with Plex’s official naming and folder structure, thus far, it hasn’t complained about doing it this way after having turned on Prefer local metadata some time ago. I will keep this in mind going forward. Fingers and toes crossed the purported “metadata overhaul” for music files Plex has said is in the works for some time now sees the light of day before too long (and that it’s introduction doesn’t completely implode how I have it working presently.

That’s an incredibly smart question I wouldn’t have thought to ask were I in your shoes, kudos. So the way I organize/collect my digital music, I only keep singles separate from the album if they do not appear on an album or ep. I typically don’t bother getting singles for a known upcoming album, as I would rather wait for the full album drop and until then I’ll use streaming service(s) for the single(s). When I do get the singles prior to album release, I always delete them once I’ve introduced the full album to the collection to keep it simple. This has seemed to work very well so far!

Oh I absolutely feel you. Been a fan since Sundowning and while TPWBYT never did fully click with me, Even In Arcadia has been a very solid follow up to Take Me Back To Eden. Holding out hope the internet copium conspiracies of a shadow double-album to Even In Arcadia somehow come true :face_without_mouth:

Anyways, like I said, I appreciate the help! I’ll give what I posted a shot on some of my collection and see how it fares and report back if I need more help.

1 Like

As an update, I was missing a couple things in my script for the “singles” separation I wanted, so if anyone else comes across this and wants to do what I’m doing, here’s what seems to be working so far:

%albumartist%/
$if($eq(%releasetype%,single), Singles/\(%originalyear%\) %album%/, \(%originalyear%\) %album%/)
$if($gt(%totaldiscs%,1), Disc %discnumber%/, )
$if($gt(%totaldiscs%,1), %discnumber%$num(%tracknumber%,2), $num(%tracknumber%,2)) - %title%

As an additional question I hadn’t thought of until I started actually using the script…
I have a boat load of lyric files alongside my music track files (.lrc and .txt), and I see that I can use the “move additional files” option to make sure they get migrated along with the music tracks, however they don’t get renamed to match the new filenames. Is there anything in the Musicbrainz Picard scripting or options menus that can ensure that when it renames a .flac/.mp3, any .txt/.lrc files with the exact same filename are renamed as well? Would save a lot of time.

You could probably do something using the “Post Tagging Actions” plugin. From the documentation:

This plugin lets you set up actions that run with a context menu click. An action consists in a command line executed for each album or each track along with a few options to tweak the behaviour. This can be used to run external programs and pass some variables to it.