Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Plex parsing rules for TV Shows. #15

Open
wants to merge 5 commits into from

1 participant

@jimgraham

Allow for reading the TV show title from the directory name. The idea here is to match Plex naming rules ( see https://plexapp.zendesk.com/hc/en-us/articles/200220687-Naming-Series-Based-TV-Shows) so that the user can have /path to/TV Shows/Show Name/Season N/S03E01-E03.mp4 and have the parser determine Show Name and episode 1.

  • Fix the regexes that match to Plex rules
  • invert the order of $file, $directory to match previous usage
  • unit test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 30, 2014
  1. @jimgraham

    Allow for parsing TV show directories

    jimgraham authored
    Start TV show directories.
  2. @jimgraham
  3. @jimgraham
Commits on Feb 4, 2014
  1. @jimgraham

    Fix Plex rules

    jimgraham authored
     - Fix the regexes that match to Plex rules
     - invert the order of `$file, $directory` to match previous usage
     - unit test.
  2. @jimgraham

    Update TV.pm

    jimgraham authored
    Remove debug code
This page is out of date. Refresh to see the latest.
View
0  lib/App/MP4Meta/Source/untitled.txt
No changes.
View
36 lib/App/MP4Meta/TV.pm
@@ -17,12 +17,19 @@ use App::MP4Meta::Source::Data::TVEpisode;
# a list of regexes to try to parse the file
my @file_regexes = (
qr/^S(?<season>\d)-E(?<episode>\d)\s+-\s+(?<show>.*)$/,
+ qr/^S(?<season>\d)-E(?<episode>\d)\s*-\s*E(?<end_episode>\d)\s+-\s+(?<show>.*)$/,
qr/^(?<show>.*)\s+S(?<season>\d\d)(\s|)E(?<episode>\d\d)$/,
+ qr/^(?<show>.*)\s+S(?<season>\d\d)(\s|)E(?<episode>\d\d)\s*-\s*E(?<end_episode>\d\d)$/,
qr/^(?<show>.*)\.S(?<season>\d\d)E(?<episode>\d\d)/i,
+ qr/^(?<show>.*)\.S(?<season>\d\d)E(?<episode>\d\d)\s*-\s*E(?<end_episode>\d\d)/i,
qr/^(?<show>.*)\s*-?\s*S(?<season>\d\d?)E(?<episode>\d\d?)/i,
+ qr/^(?<show>.*)\s*-?\s*S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/i,
qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)/,
- qr/^(?<show>.*)_S(?<season>\d\d?)E(?<episode>\d\d?)/,
- qr/S(?<season>\d\d?)E(?<episode>\d\d?)/,
+ qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/,
+ qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)/i,
+ qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/i,
+ qr/S(?<season>\d\d?)E(?<episode>\d\d?)/i,
+ qr/S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d?)/i,
qr/^(?<show>.*)\s*-?\s*(?<season>\d\d?)x(?<episode>\d\d?)/,
);
@@ -67,7 +74,7 @@ sub apply_meta {
# parse the filename for the title, season and episode
( $tags{show_title}, $tags{season}, $tags{episode} ) =
- $self->_parse_filename($file);
+ $self->_parse_filename($file, $directories);
unless ( $tags{show_title} && $tags{season} && $tags{episode} ) {
return "Error: could not parse the filename for $path";
}
@@ -134,7 +141,11 @@ sub apply_meta {
# Parse the filename in order to get the series title the and season and episode number.
sub _parse_filename {
- my ( $self, $file ) = @_;
+ my ( $self, $file, $directories ) = @_;
+
+ my $show = '';
+ my $season = '';
+ my $episode = '';
# strip suffix
$file = $self->_strip_suffix($file);
@@ -142,9 +153,9 @@ sub _parse_filename {
# see if we have a regex that matches
for my $r (@file_regexes) {
if ( $file =~ $r ) {
- my $show = $self->{title} // $+{show};
- my $season = $self->{season} // $+{season};
- my $episode = $self->{episode} // $+{episode};
+ $show = $self->{title} // $+{show};
+ $season = $self->{season} // $+{season};
+ $episode = $self->{episode} // $+{episode};
if ( $show && $season && $episode ) {
@@ -154,6 +165,17 @@ sub _parse_filename {
}
}
+ if ( $directories )
+ {
+ #-- remove Season N
+ $directories =~ s{/season\s+(\d+)$/?}{}i;
+ my @parts = (split /\//, $directories);
+ $show = $parts[$#parts];
+ }
+
+ if ( $show && $season && $episode ) {
+ return ( $self->_clean_title($show), int $season, int $episode );
+ }
return;
}
View
10 lib/test.pl
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use FindBin; # locate this script
+use lib "$FindBin::Bin";
+use App::MP4Meta;
+use App::MP4Meta::TV;
+
+my $tv = App::MP4Meta::TV->new({ sources => [qw{TVDB}] });
+$tv->apply_meta( '/Volumes/Media3/TV Shows/House of Cards (US)/S01E01.mp4');
View
14 t/lib/Test/App/MP4Meta/TV.pm
@@ -84,7 +84,7 @@ sub apply_meta_set_title : Test(9) {
}
# test $tv->_parse_filename($filename)
-sub parse_filename : Test(39) {
+sub parse_filename : Test(45) {
my $self = shift;
my $t = $self->{tv};
@@ -150,6 +150,18 @@ sub parse_filename : Test(39) {
is( $title, 'Extras' );
is( $season, 1 );
is( $episode, 1 );
+
+ #-- Plex style rules
+ $t->{title} = '';
+ ( $title, $season, $episode ) = $t->_parse_filename('S06E01-E02 - Bargaining.mkv', '/Volumes/Media3/TV Shows/Buffy the Vampire Slayer/Season 6/');
+ is ( $title, 'Buffy The Vampire Slayer');
+ is ( $season, 6);
+ is ( $episode, 1);
+
+ ( $title, $season, $episode ) = $t->_parse_filename('S06E01-E02 - Bargaining.mkv', '/Volumes/Media3/TV Shows/Buffy the Vampire Slayer/');
+ is ( $title, 'Buffy The Vampire Slayer');
+ is ( $season, 6);
+ is ( $episode, 1);
}
sub episode_is_complete : Test(2) {
Something went wrong with that request. Please try again.