Saturday, April 21, 2012

Better TV show naming for Plex Media Server

Files added to Plex Media Server need to be named a certain way so that Plex can find the right information online. The naming convention is documented online. Movies should be named "Movie name (year).ext", which is perfectly appropriate. However, the TV show "Show name\Season #\Show - s##e## - Optional episode name.ext" naming isn't the best choice. Some shows only have one season, making the "Season 1" directory and "s01" in the filename pointless. Also, the "Show name - " is pointless at the start of the filename, because the file is already under the "Show name" directory. When viewing the folder via DLNA or other means, a long show name can make it harder to view the episode number and name, which is what really matters. Fortunately, it is possible to simply use "Show name\E## - Episode name.ext". When there are multiple seasons, it's also possible to not use the "Season #" directories, but I do not recommend this. The season number can be a single digit, but episode numbers must be two digits. The " - Episode name" part is ignored by Plex. However, it is useful when viewing the files via other means, so I recommend including it. If you have a show with no online metadata, you can use a Perl script to import episode names from the file name into Plex.

I automatically renamed all my shows to this more sensible naming convention, and Plex Media Server automatically picked up the changes without any problems. Here are the commands I used. They create a shell script which does renaming. You can just add | sh to the end but it's better to look through the output a bit first, to make sure that it's sensible.

find . -type f -iname "*[Ee][0-9][0-9] - *" | sed -n 's|^\(.*/\)\([^/]*\)\(/Season [0-9]*/\)\2 - \(.*\)$|mv "&" "\1\2\3\4"|p'
find . -type f -iname "*[Ee][0-9][0-9] - *" | sed -n 's|^\(.*/\)\([^/]*\)/\2 - \(.*\)$|mv "&" "\1\2/\3"|p'

No comments: