If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Episode Title from File Name

profplumpprofplump Posts: 245Members, Plex Pass Plex Pass
Not really a scanner, but a quick way to replace all those unnamed episode titles in Plex with the name of the underlying file -- I use it for things like special features that aren't listed in TheTVDB but that I have named on disk. Thought I'd share it in case anyone else thinks it's useful.

The script will only rename files named "Episode XX", and will only rename them if the underlying file has a 2+ character name that does not contain an "Episode XX". So it's safe to run repeatedly and will not continuously rename already-named file, or screw up the name of properly scanned/matched episodes.

The script is designed for use in a TV Show hierarchy and probably does not work for Movies/etc. It also does not support episodes that contain more than one media file (i.e. ISOs, multi-part episodes, etc.).

It's a perl script (in spite of the filename extension -- the forum doesn't like .pl files). Usage is simple:
perl ./renameFromDisk.txt host:port username password section_number


The username and password can probably be empty/garbage if you're in the "local" zone where the PMS HTTP GUI allows access without authentication, though I haven't tested that.

This script doesn't support MyPlex auth tokens (only 0.93-style local username/password auth), but it should be fairly easy to patch if you need that feature.

--
EDIT
--

Forget the attachment. Use the always-current version from GitHub:
https://github.com/profplump/Plex-Rename-from-Disk

Comments

  • MazeMaze Posts: 14Members
    A question from a complete newbie ...

    I guess this could be very useful for me, I have a lot of music videos in a TV-section;

    /Gary Moore
    /Season 1
    Gary Moore - s01e01 - After the War.m4v
    Gary Moore - s01e02 - Before I Run.m4v
    Gary Moore - s01e03 - Military Man.m4v

    In the PMS they appear as Episode 01, Episode 02 ... which I would like to replace with the proper names.

    However, I don't understand how to use the script, I get the "Unable to fetch data for section ..." message.

    I've no experience or perl-scripts, so maybe I'm doing it all wrong, running the script from the terminal.
    Is "section_number" in the command line supposed to be replaced with a real number?
  • profplumpprofplump Posts: 245Members, Plex Pass Plex Pass
    Maze wrote:

    A question from a complete newbie ...

    I guess this could be very useful for me, I have a lot of music videos in a TV-section;

    /Gary Moore
    /Season 1
    Gary Moore - s01e01 - After the War.m4v


    This script will work for that, but you'll need to add a filter to get rid of the " - s01e01" part if you don't want that to show up. This regex would work:
    $file =~ s/\s+\-\s+S\d+E\d+//i;
    


    If you don't care about the sXXeYY bit in your episode names you can ignore this change.

    Maze wrote:

    I've no experience or perl-scripts, so maybe I'm doing it all wrong, running the script from the terminal.
    Is "section_number" in the command line supposed to be replaced with a real number?


    Yes, the section number for your TV section. If you're not sure what that is, take a look at the URL when you're browsing the section in the PMS web GUI. It will be something like:
    http://my.pms.ip:32400/manage/index.html#/library/sections/4

    The section number this script needs is that digit from the end.
  • profplumpprofplump Posts: 245Members, Plex Pass Plex Pass
    edited March 2012
    profplump wrote:

    This script will work for that, but you'll need to add a filter to get rid of the " - s01e01" part


    In fact, I've posted a new version that contains that change, and moved the source to GitHub in case I make future improvements:

    https://github.com/profplump/UberZach-Video/blob/master/renameFromDisk.pl
  • retroseriestvretroseriestv Posts: 193Members, Plex Pass Plex Pass
    I am interested in your solution as it would be very useful for me in order to catalogue all shows that do not exist in thetvdb and that are not suitable to be uploaded to this page because they are personal. It would spare me many hours of work if I do not have to edit the episodes one by one and they can be substituted by the name of the file they refer to.
    The problem is that my programming notions are zero and I am not able to understand how to make your solution work. I would therefore be very grateful if you could explain in a few steps how to install it and make it work for someone like me who knows nothing about Perl programming, scripts execution, etc.
  • dreamlayersdreamlayers Posts: 22Members
    profplump wrote:

    In fact, I've posted a new version that contains that change, and moved the source to GitHub in case I make future improvements:

    https://github.com/p...nameFromDisk.pl


    Thanks for the script. A few comments:

    The script must be run from Perl which uses the same filename syntax as the Plex server. Otherwise, basename() will fail to remove paths from filenames. For example, it happens when using a Windows Plex server and Cygwin perl. I used "$file =~ s/^.*\\//;" as a workaround.

    It will fail to remove the last character of 4 character file extensions such as .mpeg or .divx. I changed the file extension removal pattern to:
    $file =~ s/\.\w{2,4}$//;

    It's easy to alter the Perl code to do other stuff, such as reading descriptions from text files. However, warning: don't put invalid UTF-8 into the database. The web interface won't be able to edit it, and in this script XMLin() will kill the script with a "Cannot decode string with wide characters" error. I got around this problem via "use Encode;" and "XMLin(encode("UTF-8", $content))". That's wrong, but it allows the script to work well enough to re-write what I needed to remove invalid XML.
  • profplumpprofplump Posts: 245Members, Plex Pass Plex Pass

    Thanks for the script. A few comments:

    The script must be run from Perl which uses the same filename syntax as the Plex server. Otherwise, basename() will fail to remove paths from filenames. For example, it happens when using a Windows Plex server and Cygwin perl. I used "$file =~ s/^.*\\//;" as a workaround.

    It will fail to remove the last character of 4 character file extensions such as .mpeg or .divx. I changed the file extension removal pattern to:
    $file =~ s/\.\w{2,4}$//;

    It's easy to alter the Perl code to do other stuff, such as reading descriptions from text files. However, warning: don't put invalid UTF-8 into the database. The web interface won't be able to edit it, and in this script XMLin() will kill the script with a "Cannot decode string with wide characters" error. I got around this problem via "use Encode;" and "XMLin(encode("UTF-8", $content))". That's wrong, but it allows the script to work well enough to re-write what I needed to remove invalid XML.


    I appreciate your input.

    Yes. I am assuming File::basename() "just works". I'll give some thought to better cross-platform support; there's probably some module that provides a cross-platform basename() function. But for the moment I'm assuming everyone runs UNIX on all their systems; after all, I did write this thing in perl.

    As for the media file names themselves, yes, there are many cases the will not be covered. The 4-character extension is reasonable and pretty common, so I'll add that, but generally speaking the extension-truncator will fail for non-standard extensions, so I'm not terribly interested in supporting more exotic extensions (unless you've got a suggestion to handle a more general case).

    And yes, I'm aware the script doesn't handle wide characters well. Heck, it doesn't even handle inbound XML well. If you ever get to a patch to do real XML parsing/encoding/etc. I'd be all for it. I've thought about fixing it, but "support use cases other than my own for the plex-rename-script" is around item 187 on my to-do list, so I'll probably never add that myself (unless it becomes a problem in my personal usage).
  • arbergarberg Posts: 8Members, Plex Pass Plex Pass
    The script has been moved (by profplump), I found it again here:

    https://github.com/profplump/UberZach-Integration

    I missed a perl package but managed to install it using help from here: http://stackoverflow.com/questions/10524840/cant-locate-lwp-simple-pm-in-inc

    Then I ran the script, and it worked, it changed the names of the unnamed episodes ! Awesome, thx profplump.

    Cheers, Alex
  • sjstevesjsteve Posts: 1Members, Plex Pass Plex Pass

    This script is a godsend, thank you!

    I made a small tweak to remove the series name from the description written to Plex -- I found it a bit redundant since the series title and season is usually at the top of the screen on my clients anyway.

    I just split the contents of $file on / - / and used the second array element as the argument to uri_escape instead of just $file:

                            my @fields = split(/ - /, $file);

                            my $encoded = uri_escape($fields[1]);

    That turned this file:

    Michigan Football - S2011E1126 - Ohio State.mp4

    Into the episode title:

    Ohio State

    Instead of:

    Michigan Football - Ohio State

    Thank you again for your great work on this!

    --Steve.

  • kamakamadaunkamakamadaun Posts: 22Members, Plex Pass Plex Pass

    Does this still work? The plex URLs seem to be named differently now so if it still works how do you get the section number?

    Or is there another way to do this?

  • ZeroQIZeroQI Posts: 1,199Members ✭✭✭

    My absolute series scanner does provide the episode title from the filename until the agent updates it, output readable custom logs and support season numbering too. Please give it a try and feedback

    Absolute Series Scanner (ASS): Seasons+Absolute mode series scanner managing subdirectories and AniDB type specials,with a logging off all files (skipped on top of root folder, then sorted one line per file with regex used and info, all series sorted alphabetically) and one with the filelist to reproduce the library on my end with dummy files. It also add all files and recognise specials pretty accurately.

    http AniDB Metadata Agent (HAMA): Some good info there, will have to re-write it at some point... Data folders are kinda mandatory... Huge libraries can fetch 10gb in space. If you have no poster but other metadata is showing, create "Plug-in Support/Data/com.plexapp.agents.hama/DataItems" agent folders as indicated in the readme on GitHub

    Impressed by the agent recognition rate? Consider donating few euros through Paypal: Absolute Series Scanner + HTTP AniDB Metadata Agent. (Donators: xnaas, Sven-7, Niegen, Vorador, Fratal, T. Mayville,  A. Estremera, KJKingJ. Thanks guys)

  • music4al@gmail.commusic4al@gmail.com Posts: 7Members ✭✭

    I discovered Plex just recently and found it a very good platform to build my media library on especially for it's look and feel, however it does have it's drawbacks, it works well with tv's and movies, but it does have the drawback with .iso, .ts files in such, and Plex's resolve not to support an tried and true existing format is quite frankly disturbing and the thought of having to convert them over to mp4 files (and loose some features) is an absolute NO GO....however the "Plex Series Scanner with Disc Image Support" overcomes that hurdle, then the fact that the Plex Media Player..doesn't support those files, again overcome with "External Plex Player Support" program, now that those hurdles have been overcome....I'm shot down again, Plex and most databases out there don't know how to handle "Music Videos" . I have an incredible amount of music videos (Concerts, documentaries, individual performances, etc). so based on what I needed, I set up my Music Videos Library as a "TV Shows" type library and renamed it "Music Videos", with the "Artist" now as the "TV Show". the files are now the episodes. With Shows hidden so it just shows the number of episodes or "files / videos" by an individual artist
    Folder: Simply Red (Artist instead of TV Show)
    Episode 1: Simply Red - 1x01 - Discovering Simply Red (2015).mp4
    Episode 2: Simply Red - 1x02 - Home (Live In Sicily) (2014).iso
    The problem I'm facing now is that I have to rename all the episode titles in Plex manually when all I want is a script or program to run for the specific library and not the entire media database that will take the filename and insert it into the title minus if possible the "Simply Red - 1xXX -" and of course the ".ext", so it leaves
    Artist (Folder) Simply Red
    Episode 1: Discovering Simply Red (2015)
    Episode 2: Home (Live In Sicily) (2014)
    But I don't really care if it put's the whole filename and I have to edit...it's just the shear thought of cut/paste/edit every sing title and title sort field individually sucks.
    After reading your description of your script and seeing that you had something that might help "Plex-Rename-from-Disk", but the link in your article doesn't work. Any thoughts. Thanks for any help you may provide.

  • ZeroQIZeroQI Posts: 1,199Members ✭✭✭

    my absolute series scanner does take the episode title in filename s to populate it and support season numbering

    Absolute Series Scanner (ASS): Seasons+Absolute mode series scanner managing subdirectories and AniDB type specials,with a logging off all files (skipped on top of root folder, then sorted one line per file with regex used and info, all series sorted alphabetically) and one with the filelist to reproduce the library on my end with dummy files. It also add all files and recognise specials pretty accurately.

    http AniDB Metadata Agent (HAMA): Some good info there, will have to re-write it at some point... Data folders are kinda mandatory... Huge libraries can fetch 10gb in space. If you have no poster but other metadata is showing, create "Plug-in Support/Data/com.plexapp.agents.hama/DataItems" agent folders as indicated in the readme on GitHub

    Impressed by the agent recognition rate? Consider donating few euros through Paypal: Absolute Series Scanner + HTTP AniDB Metadata Agent. (Donators: xnaas, Sven-7, Niegen, Vorador, Fratal, T. Mayville,  A. Estremera, KJKingJ. Thanks guys)

  • music4al@gmail.commusic4al@gmail.com Posts: 7Members ✭✭

    How does absolute series scanner rename the episode title in Plex to the name of the file on my hard-drive?

    I've set up the database as "Music Videos" (It is based on a TV Shows Library format, where artist replaces TV Show and the filename is the episode). Note: I hide "Show Season" so I don't get the "Season" listed, Just the Artist with the number of episodes (files) listed below.
    .
    Example: I have the Artist "10cc"
    The layout is
    Folder: 10cc
    Filename: 10cc - 1x01 - Clever Clogs (Featuring Graham Gouldman And Friends) (2008)
    10cc - 2x02 - In Concert BBC Studios (1974-08-21)
    10cc - 3x03 - In Concert BBC Studios (1974-08-21)
    Note: The filename is listed as using this structure Artist - SeasonxEpisode - Filename
    Note: In my case the Season happens to be which Hardrive the file is stored on.

    Plex reads it as 10cc (Artist) on Main Library Page and lists the number of episodes (video files) attributed to that artist. When clicking on the artist, I move to the sub-directory where all the episodes (Files) are listed. However Plex lists them as, Episode 1, Episode 2, etc....however I want the episode listed as the filename. Preferably like the following

    Clever Clogs (Featuring Graham Gouldman And Friends) (2008)
    In Concert BBC Studios (1974-08-21)
    In Concert BBC Studios (1974-08-21)

    Any thoughts

  • ZeroQIZeroQI Posts: 1,199Members ✭✭✭

    The scanner keeps all after the ep number but remove the serie name and all in brackets and crcs...
    then it adds the ep with the title: tv_show = Media.Episode(show, season, epn, title, year)
    Did my scanner not add the title like "In Concert BBC Studios (1974-08-21)" ?

    Absolute Series Scanner (ASS): Seasons+Absolute mode series scanner managing subdirectories and AniDB type specials,with a logging off all files (skipped on top of root folder, then sorted one line per file with regex used and info, all series sorted alphabetically) and one with the filelist to reproduce the library on my end with dummy files. It also add all files and recognise specials pretty accurately.

    http AniDB Metadata Agent (HAMA): Some good info there, will have to re-write it at some point... Data folders are kinda mandatory... Huge libraries can fetch 10gb in space. If you have no poster but other metadata is showing, create "Plug-in Support/Data/com.plexapp.agents.hama/DataItems" agent folders as indicated in the readme on GitHub

    Impressed by the agent recognition rate? Consider donating few euros through Paypal: Absolute Series Scanner + HTTP AniDB Metadata Agent. (Donators: xnaas, Sven-7, Niegen, Vorador, Fratal, T. Mayville,  A. Estremera, KJKingJ. Thanks guys)

  • music4al@gmail.commusic4al@gmail.com Posts: 7Members ✭✭

    Excellent, The Scanner worked perfectly, what I made a mistake was choosing the wrong type agent. Re-ran it again and I got the titles.

    Thanks

Sign In or Register to comment.