Sharing my TV shows expression
Posted: 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.
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.
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.
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.)
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.
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...
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...
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?
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/
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})"}}
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()}
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)')}
Code: Select all
{" - ${t.replacePart(' (Part $1)').colon(' - ').replaceAll(/[*]/,'-').validateFileName()}"}{".[${crc32}]"}
Other useful expressions...
Code: Select all
{ny.colon(' - ').validateFileName()} - {s00e00.lower()}{" - "+fn.after(s00e00).after(/\.| (- )?/)}
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()}"}}
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?