Sharing my TV shows expression

All about user-defined episode / movie format expressions
Post Reply
User avatar
Wolfie
Posts: 60
Joined: 27 Oct 2015, 02:59

Sharing my TV shows expression

Post by Wolfie » 09 May 2018, 10:17

Thought I would share one of my currently developed expressions. It's not the one I use, but it's the one that others might find useful features to use.

First, some background information...
I use P: as my Plex drive, meaning it contains the database, etc. It also have various junction links to folders on other drives, such as P:\_01 linking to the "Media" folder on the first drive containing my media collection. P:\_02 does the same thing but on the second drive, etc. I also have a P:\dev folder, where the same numbers (P:\dev\01) link to the root of the drive.

The benefits to doing this is that on Plex, I just add in folders P:\_01\TV, P:\_02\TV, etc. No need to assign drive letters, unless desired. Also, no need to remember drive letters, and adding another drive keeps scripting simple as well. Same with having the root of each drive linked in a \dev\ folder, in case it's needed.

Code: Select all

P:/_{any{folder.path.match(/.:\\_((?:dev)?\d\d(?:\\|$))/)}{"03"}}/TV/
Starting off, this is rather simple. It looks at the original path of the file and if it matches P:\_## or P:\dev\## then it will keep it on that same path, otherwise it throws it to P:\_03 (which is currently the default for new material). If you go on a frenzy of renaming files with a new scheme, files will remain on the same drive without having to alter the expression each time.

For anyone wondering, I store newly creature media files in a different structure, so that I can verify that it works without issues in Plex, before fully integrating it. Thus the \dev\ use. Same structure, just a different root folder name. Also, the files don't get all the same fancy naming done to them, so if I have a few different copies, I can more easily identify and remove the culprit among a smaller group of files. After I'm sure everything is fine, I can FileBot them to their final homes.

Code: Select all

{any{concat(readLines('P:/series.txt').find{ it =~ /^${info.id} / }.after(/^\d+\s+/)).before(/[:#\t\/*\\]/)}{"${ny.colon(' - ').validateFileName()} (${y})"}}
Most people won't use this, but it can be useful for people who want to custom name the folders of shows, especially if there are multiple shows with similar names, like Law & Order, CSI, Star Trek, etc. If you want to use this, you will need to create a file (you can edit the location and name, obviously). In the file, at the start of the line, enter in the ID from TheTVDB, followed by a space or tab, then the name you want to use for the show. For example, for Star Trek The Next Generation and Deep Space 9, these two lines would be in the file:
71470 Star Trek TNG
72073 Star Trek DS9

You can add a tab and then a comment after the name if you want to add any comments for personal use (will be ignored by filebot).
An example of the above being used:
Star Trek DS9/Season xx/
Star Trek TNG/Season xx/

If not used, then the original name will be used with the year appended to it:
Star Trek Deep Space Nine (1993)/Season xx
Star Trek The Next Generation (1987)/Season xx

This can also be modified to mix two different shows into one main folder, though I'm not sure why anyone would want to do that.

Code: Select all

{"/Season ${episode.special || episode.special == 0 ? '00':s.pad(2)}/${ny.colon(' - ').validateFileName()}"} ({y}) - {s00e00.lower()}
Generates the "Season ##" folder, adding a leading 0 for seasons less than 10 and using '00' for Specials.
After that the name of the show, the year the show started, and the season/episode numbers. The little extra work you see taking place is convert any colon's to a dash surrounded by spaces, and to validate the name for use. You'll also notice I'm using {ny} instead of {n}, which adds the year to the end of the name. I like to have a year added after the show's name for consistency and reference. Maybe I have OCD, but seeing some titles with a year and others without, it bugs me. (Some titles have the year attached even without the 'y' being used.)

Code: Select all

{if (n != "Tom and Jerry") airdate.format(' - yyyy-MM-dd') else airdate.format(' - (MMM dd)')}
Oddly enough, and no idea why, but when my Tom and Jerry collection has the full date, Plex gets all confused by it. No other show suffers from this that I've noticed. But since each season is also the year number, only need/want to know the month and day the episode originally aired.

Code: Select all

{" - ${t.replacePart(' (Part $1)').colon(' - ').replaceAll(/[*]/,'-').validateFileName()}"}{".[${crc32}]"}
Episode title cleaning as well as separating any reference to a part number, for easier view. CRC32 value in brackets so that files can be verified later on, if desired.

Other useful expressions...

Code: Select all

{ny.colon(' - ').validateFileName()} - {s00e00.lower()}{" - "+fn.after(s00e00).after(/\.| (- )?/)}
This will pretty up the name of the file with the show's name and year, followed by season/episode numbers, and then attach the original filename, starting after the s##e## part of the name (if there is anything left after that). Useful for when you want to retain the file information, such as resolution, encoding, group, etc. Sort of a compromise between the original filename, and having a more pleasant file name.


For movies...

Code: Select all

{any{"_ COLLECTIONS _/".concat(any{MC:{readLines('P:/collections.txt').find{ it =~ imdbid }.after(':').before(/[:#\t*\/\\]/)}}{collection.colon(" - ").validateFileName()})+"/${y} - ${n.colon(" - ").validateFileName()}"}}
This sorts movies that are associated with a collection (or a custom collection) into a folder titled... "_ COLLECTIONS _" as you might expect. It will then add into a folder structure consisting of the collection name, then folder using "(year) (movie name)" as the structure. Only drawback to this is that sometimes Plex doesn't figure out the proper name of the movie, since the year is first. As a personal preference, when I have some movies that are part of a series, I like them to be sorted by year when browsing the files, instead of trying to remember the order.

If you look closely, you'll see a bonus here, which allows you to create custom (or override existing) movie collections. Some movies are already associated with certain collections, but you may want to rename it or alter which collection a particular movie is saved to. With some work, this could also be made to exclude certain movies from being in a collection (file structure wise, not Plex wise). The format of the "collections.txt" file is rather simple:

tt0055928;tt0057076;tt0058150;tt0059800;tt0062512;:James Bond Collection

Mind you, the ;'s are really necessary, and could be replaced with spaces, commas, periods, middle fingers, etc, just not colons. The colon tells the expression where the name of the collection starts. For anyone wondering if there's a change of an false hit despite having proper IMDb ID's in the file, the ID's are all the same length, so if it finds a match, then it's the correct match (assuming you put the correct ID's in there). I have a BluRay set of James Bond movies, and using this allows me to ensure that files are always in a collection, even if an online database doesn't have it properly added. If I wanted to, I could rename it to "007 Collection" or "007 James Bond" or something else. (There are a few more lines in my file for the JB collection, the line shown is just an example.)


Questions, comments, jaws on floor from confusion?
Last edited by Wolfie on 10 May 2018, 11:19, edited 4 times in total.

User avatar
devster
Posts: 149
Joined: 06 Jun 2017, 22:56

Re: Sharing my TV shows expression

Post by devster » 10 May 2018, 08:50

The collections are a very nice touch, didn't think about that one. Does Plex automatically pick them up?

Also I see validateFileName() but not its definition, I can imagine it does filename cleaning?
I only work in black and sometimes very, very dark grey. (Batman)

User avatar
rednoah
The Source
Posts: 14363
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sharing my TV shows expression

Post by rednoah » 10 May 2018, 09:57

String.validateFileName() is a FileBot-specific Groovy extension. It'll remove all special characters that aren't allowed in file names on Windows. FileBot will do that anyway, but if you do it in the format right away, then the FileBot GUI won't need prompt you about validating file names.
:idea: Please read the FAQ and How to Request Help.

User avatar
Wolfie
Posts: 60
Joined: 27 Oct 2015, 02:59

Re: Sharing my TV shows expression

Post by Wolfie » 10 May 2018, 09:58

validateFileName() cleanses out anything that would cause issues with content being used as a filename. I'm not sure if it accepts any arguments, such as what to replace invalid characters with, but it's quite useful when you want to manually control the process. Keep in mind that it will remove illegal characters, which is why I have the colon() option in there, replacing it with a dash surrounded by two spaces, so a show like "Law & Order: Special Victims Unit" will turn into "Law & Order - Special Victims Unit" instead of just dropping the colon altogether. Helps it to stand out better, IMO. You'll also notice for the title (episode title) that I have a replaceAll to change *'s to -'s as well, instead of just letting them get removed.

As for the collections, I just tested it and unfortunately, Plex ignores the filenames and uses the 'root' folder for the series name (and ignores subfolders). So at best, it can be used to rename the folder, which is still useful (instead of "Law & Order - Special Victims Unit", I could have it use "Law & Order - SVU" for example). I tested it with a couple of different Star Trek series I have, and when they are within a folder, even with a subfolder with a good naming mechanism, it groups them all together. It can still be used with movies though, as I have been doing that for awhile. Some movies are already labeled as being part of a collection, but for movies you feel belong together, but aren't being stored that way, you can use the above to make it happen. There's a slightly different expression for it that I use, so that you can have multiple IMDb titles on one line instead of having a ton of seemingly duplicate lines. (Thanks to rednoah for teaching me how to do it.)

Note: I altered the 'collections' section to make it into a way to customize the name of the folder of the series.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests