Search

Sunday, June 28, 2015

The Episorter: Taking the Monotony out of Renaming TV Episodes



I recently had to rename around 200 TV episodes on my Plex server, a daunting task that would normally involve several terribly boring hours and hundreds of mvs. That is, if I hadn't taken advantage of the power of Bash to solve my problem!


Some background

Plex is an absolutely amazing media server, and, when presented with a directory full of media files, it's generally able to match and categorize them accurately and without human intervention. However, it can be picky, especially when it comes to TV episodes. In my case, I had a couple hundred episodes of The Office that followed a naming convention that Plex didn't like, meaning that I got all the way to season 3 without realizing that I was missing nearly 10 episodes per season!

My episodes were named like so:

.../plex/TV/The Office/Season 2/Episode 3 - Office Olympics.mp4 

However, this is Plex's preferred naming scheme:

.../plex/TV/The Office/Season 2/S02E3 - Office Olympics.mp4

As a result, I whipped up a small script to save me from a future of bloodshot eyes and cramped hands, which was able to tear through the job in less than 2 minutes in total: 

sort.sh

I call it the episorter, and it takes all the variables that it requires from the directory name (i.e. 'Season 2') and the number of episodes in the current directory, and then renames each of the episodes to align with Plex's preferred scheme.

I hope it helps somebody!