MP4Meta/TV.pm

filter: Statementstmt 29.4% 25 / 85 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 63.6% 7 / 11 Podpod 100% 2 / 2 totaltotal 17.1% 34 / 198 CC 32 SCAR 52.1
CC
32
Cov
16%
apply_meta
306.0
_parse_filename
182.0
_episode_is_complete
20.0
CRAP 182.3
↑ Summary MP4Meta/Film.pm »
1 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package App::MP4Meta::TV;
6 {
7 2 $App::MP4Meta::TV::VERSION = '1.153340';
8 }
9  
10 # ABSTRACT: Add metadata to a TV Series
11  
12 2 ▶use App::MP4Meta::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our @ISA = 'App::MP4Meta::Base';
14  
15 2 ▶use File::Spec '3.33';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use AtomicParsley::Command::Tags;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use App::MP4Meta::Source::Data::TVEpisode;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # a list of regexes to try to parse the file
21 2 my @file_regexes = (
22 qr/^S(?<season>\d)-E(?<episode>\d)\s+-\s+(?<show>.*)$/,
23 qr/^S(?<season>\d)-E(?<episode>\d)\s*-\s*E(?<end_episode>\d)\s+-\s+(?<show>.*)$/,
24 qr/^(?<show>.*)\s+S(?<season>\d\d)(\s|)E(?<episode>\d\d)$/,
25 qr/^(?<show>.*)\s+S(?<season>\d\d)(\s|)E(?<episode>\d\d)\s*-\s*E(?<end_episode>\d\d)$/,
26 qr/^(?<show>.*)\.S(?<season>\d\d)E(?<episode>\d\d)/i,
27 qr/^(?<show>.*)\.S(?<season>\d\d)E(?<episode>\d\d)\s*-\s*E(?<end_episode>\d\d)/i,
28 qr/^(?<show>.*)\s*-?\s*S(?<season>\d\d?)E(?<episode>\d\d?)/i,
29 qr/^(?<show>.*)\s*-?\s*S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/i,
30 qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)/,
31 qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/,
32 qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)/i,
33 qr/^(?<show>.*)-S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d)/i,
34 qr/S(?<season>\d\d?)E(?<episode>\d\d?)/i,
35 qr/S(?<season>\d\d?)E(?<episode>\d\d?)\s*-\s*E(?<end_episode>\d\d?)/i,
36 qr/^(?<show>.*)\s*-?\s*(?<season>\d\d?)x(?<episode>\d\d?)/,
37 );
38  
39 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
40 0 my $class = shift;
41 0 my $args = shift;
42  
43 0 my $self = $class->SUPER::new($args);
44  
45 # args for skipping
46 0 $self->{'continue_without_any'} = $args->{'continue_without_any'};
47 0 $self->{'continue_without_overview'} = $args->{'continue_without_overview'};
48 0 $self->{'continue_without_genre'} = $args->{'continue_without_genre'};
49 0 $self->{'continue_without_year'} = $args->{'continue_without_year'};
50 0 $self->{'continue_without_cover'} = $args->{'continue_without_cover'};
51  
52 # attributes
53 0 $self->{'season'} = $args->{'season'};
54 0 $self->{'episode'} = $args->{'episode'};
55 0 $self->{'overview'} = $args->{'overview'};
56 0 $self->{'year'} = $args->{'year'};
57 0 $self->{'cover'} = $args->{'cover'};
58  
59 # we are a TV Show
60 0 $self->{'media_type'} = 'TV Show';
61  
62 0 return $self;
63 }
64  
65 0 ▶sub apply_meta {
Subroutine apply_meta: not called CC=17 SCAR=57.2
Pod documented
66 0 my ( $self, $path ) = @_;
67 my %tags = (
68 show_title => $self->{'title'},
69 season => $self->{'season'},
70 0 episode => $self->{'episode'},
71 );
72  
73 # get the file name
74 0 my ( $volume, $directories, $file ) = File::Spec->splitpath($path);
75  
76 0 ▶ unless ( $tags{show_title} && $tags{season} && $tags{episode} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tags{"show_title"} and $tags{"season"} and $tags{"episode"}) 0 0 0
Condition0%0/6
$tags{"show_title"} and $tags{"season"} and $tags{"episode"}
!ll&&!rl&&r
000
$tags{"show_title"} and $tags{"season"}
!ll&&!rl&&r
000
MC/DC0%0/3
$tags{"show_title"} and $tags{"season"} and $tags{"episode"}
$tags{"show_title"} $tags{"season"} $tags{"episode"}
Truth table0%0/4
A and B and C
A= $tags{"show_title"}B= $tags{"season"}C= $tags{"episode"}
ABCresult
0XX0
10X0
1100
1111
77  
78 # parse the filename for the title, season and episode
79 0 ( $tags{show_title}, $tags{season}, $tags{episode} ) =
80 $self->_parse_filename($file, $directories);
81 0 ▶ unless ( $tags{show_title} && $tags{season} && $tags{episode} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tags{"show_title"} and $tags{"season"} and $tags{"episode"}) 0 0 0
Condition0%0/6
$tags{"show_title"} and $tags{"season"} and $tags{"episode"}
!ll&&!rl&&r
000
$tags{"show_title"} and $tags{"season"}
!ll&&!rl&&r
000
MC/DC0%0/3
$tags{"show_title"} and $tags{"season"} and $tags{"episode"}
$tags{"show_title"} $tags{"season"} $tags{"episode"}
Truth table0%0/4
A and B and C
A= $tags{"show_title"}B= $tags{"season"}C= $tags{"episode"}
ABCresult
0XX0
10X0
1100
1111
82 0 return "Error: could not parse the filename for $path";
83 }
84 }
85  
86 my $episode = App::MP4Meta::Source::Data::TVEpisode->new(
87 genre => $self->{'genre'},
88 cover => $self->{'cover'},
89 overview => $self->{'overview'},
90 0 year => $self->{'year'},
91 );
92 0 ▶ unless ( _episode_is_complete($episode) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_episode_is_complete($episode)) 0 0 0
93 0 for my $source ( @{ $self->{'sources_objects'} } ) {
94 say sprintf( "trying source '%s'", $source->name )
95 0 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
96  
97 # merge new epiosde into previous
98 0 $episode->merge( $source->get_tv_episode( \%tags ) );
99  
100 # last if we have everything
101 last
102 0 ▶ if ( _episode_is_complete($episode) );
Branch: 1 branch
BranchTrueFalseTotal
if _episode_is_complete($episode) 0 0 0
103 }
104 }
105  
106 # check what we have
107 0 ▶ unless ( $episode->overview ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($episode->overview) 0 0 0
108 0 ▶ if ( $self->{'continue_without_any'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'continue_without_any'} or $self->{'continue_without_overview'}) { } 0 0 0
Condition0%0/3
$self->{"continue_without_any"} or $self->{"continue_without_overview"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"continue_without_any"} or $self->{"continue_without_overview"}
$self->{"continue_without_any"} $self->{"continue_without_overview"}
Truth table0%0/3
A or B
A= $self->{"continue_without_any"}B= $self->{"continue_without_overview"}
ABresult
1X1
011
000
109 || $self->{'continue_without_overview'} )
110 {
111 0 say 'no overview found; continuing';
112 }
113 else {
114 return sprintf( 'no overview found for %s, season %d, episode %d',
115 0 $tags{show_title}, $tags{season}, $tags{episode} );
116 }
117 }
118  
119 0 ▶ my $show_title = $episode->show_title // $tags{show_title};
Condition0%0/3
$episode->show_title // $tags{"show_title"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$episode->show_title // $tags{"show_title"}
$episode->show_title $tags{"show_title"}
Truth table0%0/3
A // B
A= $episode->show_titleB= $tags{"show_title"}
ABresult
1X1
011
000
120 my $apTags = AtomicParsley::Command::Tags->new(
121 artist => $show_title,
122 albumArtist => $show_title,
123 title => $episode->title,
124 album => sprintf( "%s, Season %s", $show_title, $tags{season} ),
125 tracknum => $tags{episode},
126 TVShowName => $show_title,
127 TVEpisode => $tags{episode},
128 TVEpisodeNum => $tags{episode},
129 TVSeasonNum => $tags{season},
130 0 stik => $self->{'media_type'},
131 description => $episode->overview,
132 longdesc => $episode->overview,
133 genre => $episode->genre,
134 year => $episode->year,
135 artwork => $episode->cover
136 );
137  
138 0 ▶ say 'writing tags' if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
139 0 my $error = $self->_write_tags( $path, $apTags );
140 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
141  
142 0 return $self->_add_to_itunes( File::Spec->rel2abs($path) );
143 }
144  
145 # Parse the filename in order to get the series title the and season and episode number.
146 0 ▶sub _parse_filename {
Subroutine _parse_filename: not called CC=13 SCAR=52.0
147 0 my ( $self, $file, $directories ) = @_;
148  
149 0 my $show = '';
150 0 my $season = '';
151 0 my $episode = '';
152  
153 # strip suffix
154 0 $file = $self->_strip_suffix($file);
155  
156 # see if we have a regex that matches
157 0 for my $r (@file_regexes) {
158 0 ▶ if ( $file =~ $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /$r/) 0 0 0
159 0 ▶ $show = $self->{title} // $+{show};
Condition0%0/3
$self->{"title"} // $+{"show"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"title"} // $+{"show"}
$self->{"title"} $+{"show"}
Truth table0%0/3
A // B
A= $self->{"title"}B= $+{"show"}
ABresult
1X1
011
000
160 0 ▶ $season = $self->{season} // $+{season};
Condition0%0/3
$self->{"season"} // $+{"season"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"season"} // $+{"season"}
$self->{"season"} $+{"season"}
Truth table0%0/3
A // B
A= $self->{"season"}B= $+{"season"}
ABresult
1X1
011
000
161 0 ▶ $episode = $self->{episode} // $+{episode};
Condition0%0/3
$self->{"episode"} // $+{"episode"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"episode"} // $+{"episode"}
$self->{"episode"} $+{"episode"}
Truth table0%0/3
A // B
A= $self->{"episode"}B= $+{"episode"}
ABresult
1X1
011
000
162  
163 0 ▶ if ( $show && $season && $episode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show and $season and $episode) 0 0 0
Condition0%0/6
$show and $season and $episode
!ll&&!rl&&r
000
$show and $season
!ll&&!rl&&r
000
MC/DC0%0/3
$show and $season and $episode
$show $season $episode
Truth table0%0/4
A and B and C
A= $showB= $seasonC= $episode
ABCresult
0XX0
10X0
1100
1111
164  
165 0 return ( $self->_clean_title($show), int $season,
166 int $episode );
167 }
168 }
169 }
170  
171 0 ▶ if ( $directories )
Branch: 1 branch
BranchTrueFalseTotal
if ($directories) 0 0 0
172 {
173 #-- remove Season N
174 0 $directories =~ s{/season\s+(\d+)$/?}{}i;
175 0 my @parts = (split /\//, $directories);
176 0 $show = $parts[$#parts];
177 }
178
179 0 ▶ if ( $show && $season && $episode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show and $season and $episode) 0 0 0
Condition0%0/6
$show and $season and $episode
!ll&&!rl&&r
000
$show and $season
!ll&&!rl&&r
000
MC/DC0%0/3
$show and $season and $episode
$show $season $episode
Truth table0%0/4
A and B and C
A= $showB= $seasonC= $episode
ABCresult
0XX0
10X0
1100
1111
180 0 return ( $self->_clean_title($show), int $season, int $episode );
181 }
182 0 return;
183 }
184  
185 # true if we have all we need in an episode
186 0 ▶sub _episode_is_complete {
Subroutine _episode_is_complete: not called CC=4 SCAR=30.0
187 0 my $episode = shift;
188 0 ▶ return ( $episode->overview
Condition0%0/9
$episode->overview && $episode->genre && $episode->year && $episode->cover
!ll&&!rl&&r
000
$episode->overview and $episode->genre and $episode->year
!ll&&!rl&&r
000
$episode->overview and $episode->genre
!ll&&!rl&&r
000
MC/DC0%0/4
$episode->overview && $episode->genre && $episode->year && $episode->cover
$episode->overview $episode->genre $episode->year $episode->cover
Truth table0%0/5
A and B and C && D
A= $episode->overviewB= $episode->genreC= $episode->yearD= $episode->cover
ABCDresult
0XXX0
10XX0
110X0
11100
11111
189 && $episode->genre
190 && $episode->year
191 && $episode->cover );
192 }
193  
194 2 1;
195  
196 __END__
↑ Summary MP4Meta/Film.pm »