Info.pm

filter: Statementstmt 90.9% 220 / 242 Branchbran 79.1% 95 / 120 Conditioncond 63.7% 44 / 69 MC/DCmcdc 43.1% 19 / 44 Subroutinesub 100% 46 / 46 Podpod 100% 29 / 29 totaltotal 82.3% 453 / 550 CC 89 SCAR 18.2
CC
89
Cov
83%
new
22.4
_isolate_name_year
8.6
_get_episode_name
8.0
CRAP 6.2
↑ Summary EpisodeName.pm »
1 package File::TVShow::Info;
2  
3 14 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use File::TVShow::EpisodeName 0.02 qw (@episode_name_patterns);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use File::TVShow::Networks 0.02 qw(@networks);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 ▶use vars qw(@filePatterns);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 File::TVShow::Info - Perl meta data extractor from file name for TV Show file.
14  
15 =head1 VERSION
16  
17 Version 0.01.2
18  
19 =cut
20  
21 14 our $VERSION = '0.01.2';
22  
23  
24 =head1 SYNOPSIS
25  
26 This module is intended to identify and extract nformation in the file name of a TV show. These details can then be accessed
27 by calling the relevant methods. It does B<NOT> attempt to read the contents of the file.
28  
29 Note: This module will be modelled off L<https://metacpan.org/pod/Video::Filename> created by Behan Webster, but will focus on TV Shows only and with additional features.
30  
31 If the file name is parsed and can not be identified as a TV show then L</is_tv_show> will return 0.
32  
33 use File::TVShow::Info;
34 my $show = File::TVShow::Info->new('file');
35  
36 =cut
37  
38  
39 14 @filePatterns = (
40 { # TV Show Support - By Date no Season or Episode
41 # Perl > v5.10
42 re => '(?<show_name>.*?)[.\s_-](?<year>\d{4})[.\s_-](?<month>\d{1,2})[.\s_-](?<date>\d{1,2})(?:[.\s_-](?<extra_meta>.*)|)[.](?<ext>(?:[a-z]{3}|[a-z]{2}[0-9]))$',
43  
44 # Perl < v5.10
45 re_compat => '(.*?)[.\s_-](\d{4})[.\s_-](\d{1,2})[.\s_-](\d{1,2})(?:[.\s_-](.*)|)[.]((?:[a-z]{3}|[a-z]{2}[0-9]))$',
46 keys_compat => [qw(filename show_name year month date extra_meta ext)],
47 },
48 { # TV Show Support - SssEee or Season_ss_Episode_ss
49 # Perl > v5.10
50 re => '^(?:(?<show_name>.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(?<season>\d{1,2})[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(?<episode>\d{1,2})(?:-?(?:(?:e|ep)[\s._]*)?(?<endep>\d{1,2}))?(?:[\s._]?(?:p|part)[\s._]?(?<part>\d+))?(?<subep>[a-z])?(?:[\/\s._-]*(?<extra_meta>[^\/]+?))?[.](?<ext>(?:[a-z]{3}|[a-z]{2}[0-9]))$',
51  
52 # Perl < v5.10
53 re_compat => '^(?:(.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(\d{1,2})[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(\d{1,2})(?:-?(?:(?:e|ep)[\s._]*)?(\d{1,2}))?(?:[\s._]?(?:p|part)[\s._]?(\d+))?([a-z])?(?:[\/\s._-]*([^\/]+?))?[.](?<ext>(?:[a-z]{3}|[a-z]{2}[0-9]))$',
54 keys_compat => [qw(show_name season episode endep part subep extra_meta)],
55 },
56 { # TV Show Support - sxee
57 # Perl > v5.10
58 re => '^(?:(?<show_name>.*?)[\/\s._-]*)?(?<openb>\[)?(?<season>\d{1,2})[x\/](?<episode>\d{1,2})(?:-(?:\k<season>x)?(?<endep>\d{1,2}))?(?(<openb>)\])(?:[\s._-]*(?<extra_meta>[^\/]+?))?[.](?<ext>(?:[a-z]{3}|[a-z]{2}[0-9]))$',
59  
60 # Perl < v5.10
61 re_compat => '^(?:(.*?)[\/\s._-]*)?\[?(\d{1,2})[x\/](\d{1,2})(?:-(?:\d{1,2}x)?(\d{1,2}))?\]?(?:[\s._-]*([^\/]+?))?[.](?<ext>(?:[a-z]{3}|[a-z]{2}[0-9]))$',
62 keys_compat => [qw(show_name season episode endep extra_meta)],
63 },
64 );
65  
66 =head1 Methods
67  
68 =head2 new
69  
70 Create a Info object to extract meta information from the file name.
71  
72 my $show = File::TVShow::Info->new('file');
73  
74 =cut
75  
76 =head3 Object attributes.
77  
78 Attributes may be accessed through $show->{attribute_name} however methods
79 do exist for all required operations.
80  
81 =over 4
82  
83 =item * show_name:
84 Name of the show.
85  
86 =item * original_show_name:
87 This will contain the show name found in the file name without any modifications.
88 This will only be defined if _isolate_name_year has found a year string
89 within the file name such as name.2019, name.(2019), name 2018, name (2018)
90  
91 =item * season:
92 Show season
93  
94 =item * episode:
95 Show episode
96  
97 =item * episode_name
98  
99 =item * country
100  
101 =item * endep: (Naming under consideration)
102 last Episode number found when file name contains SXXEXXEXX
103  
104 =item * year, month, date:
105 Show date e.g 2019.03.03
106 This can be accessed using the method L</ymd>
107 Note: year will be defined in two cases.
108 One: show name contains year. show_name.yyyy or
109 Two: File name contains YYYY.MM.DD that are identified by date. These are mutually
110 exclusive and no conflict is expected.
111  
112 =item * source
113  
114 =item * resolution:
115 Show resolution 480p/720p and so on. This will be '' if not found.
116  
117 =item * release_group
118  
119 =item * is_subtitle
120  
121 =item * subtitle_lang
122  
123 =item * ext:
124 File extension
125  
126 =back
127  
128 =cut
129  
130 54 ▶sub new {
Subroutine new: called CC=14 SCAR=31.1
Pod documented
131 54 my $class = shift;
132 54 my $self = {};
133 54 bless $self, $class;
134 # Set default attributes
135 54 @{$self->{valid_countries}} = qw( US UK KR);
136  
137 # Read default values
138 54 for my $key (qw(file name season episode part options)) {
139 108 ▶ last unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 54 54 108
140 54 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 54 54
141 # Use a hashref for values
142 0 ▶ while (my ($key, $value) = each %{$_[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$_[0];}) 0 0 0
143 0 $self->{$key} = $value;
144 }
145 } else {
146 54 $self->{$key} = shift;
147 }
148 }
149  
150 54 $self->{filename} = $self->{file};
151  
152 # Run filename through list of patterns
153 54 for my $pat (@filePatterns) {
154 107 ▶ if ($] >= 5.010000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 107 0 107
155 107 ▶ if ($self->{file} =~ /$pat->{re}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"} =~ /$pat->{"re"}/i) 53 54 107
156 # We have a match we will exit after this loop
157 53 $self->{regex} = $pat->{re};
158 53 ▶ while (my ($key, $data) = each %-) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %-) 420 53 473
159 420 ▶ $self->{$key} = $data->[0] if defined $data->[0] && !defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->[0] and not defined $self->{$key} 262 158 420
Condition66%2/3
defined $data->[0] and not defined $self->{$key}
!ll&&!rl&&r
1580262
MC/DC50%1/2
defined $data->[0] and not defined $self->{$key}
defined $data->[0] not defined $self->{$key}
Truth table66%2/3
A and not(B)
A= defined $data->[0]B= not defined $self->{$key}
ABresult
0X0
100
111
160 }
161 # We have a match so we are skipping all other @filePatterns
162 53 last;
163 }
164 } else { # No named groups in regexes
165 0 my @matches;
166 0 ▶ if (@matches = ($self->{file} =~ /$pat->{re_compat}/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches = $self->{"file"} =~ /$pat->{"re_compat"}/i) 0 0 0
167 #print "MACTHES: ".join(',', @matches)."\n";
168 0 $self->{regex} = $pat->{re_compat};
169 0 my $count = 0;
170 0 foreach my $key (@{$pat->{keys_compat}}) {
171 0 ▶ $self->{$key} = $matches[$count] unless defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 0 0 0
172 0 $count++;
173 }
174 0 last;
175 }
176 }
177 }
178 54 $self->_set_tvshow_organize_name();
179 54 $self->_isolate_name_year();
180 54 $self->_get_resolution();
181 54 $self->_get_network();
182 54 $self->_get_release_group();
183 54 $self->_is_tv_subtitle();
184 54 $self->_get_subtitle_lang();
185 54 $self->_get_country();
186 54 $self->_get_episode_name();
187 54 return $self;
188 }
189  
190 =head2 show_name
191  
192 Return the show name found in the file name.
193  
194 =cut
195  
196 11 ▶sub show_name {
Subroutine show_name: called CC=1 SCAR=0.0
Pod documented
197  
198 11 my $self = shift;
199 11 my $attr = 'show_name';
200 11 $self->__get_obj_attr($attr);
201 }
202  
203 =head2 strip_show_name
204  
205 Return show_name after removing string delimiters
206  
207 =cut
208  
209 13 ▶sub strip_show_name {
Subroutine strip_show_name: called CC=3 SCAR=11.3
Pod documented
210  
211 13 my $self = shift;
212  
213 13 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 13 13
214  
215 13 ▶ return $self->{show_name} if defined $self->{do_not_strip};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"do_not_strip"} 0 13 13
216 13 (my $newString = $self->{show_name}) =~ s/[\._-]/ /g;
217 13 return $newString;
218  
219 }
220  
221 =head2 clean_show_name
222  
223 Return complete show name with year and country in brackets if they exist.
224 Also remove any delimiters, replaced with spaces
225  
226 =cut
227  
228 9 ▶sub clean_show_name {
Subroutine clean_show_name: called CC=4 SCAR=13.9
Pod documented
229  
230 9 my $self = shift;
231  
232 9 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 9 9
233  
234 9 my $newString = $self->strip_show_name();
235 9 ▶ if ($self->has_year()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_year) { } 3 6 9
elsif ($self->has_country) { } 4 2 6
236 3 $newString .= ' (' . $self->year() . ')';
237 } elsif ($self->has_country()) {
238 4 $newString .= ' (' . $self->country() . ')';
239 }
240 9 return $newString;
241 }
242  
243 =head2 original_show_name
244  
245 Return the original show name.
246  
247 This method will return the orginal show name if original_show_name is defined.
248 This will be defined if show_name contains a year string (YYYY) or YYYY
249  
250 If not defined it will return {show_name}
251  
252 =cut
253  
254 5 ▶sub original_show_name {
Subroutine original_show_name: called CC=2 SCAR=8.1
Pod documented
255  
256 5 my $self = shift;
257  
258 5 ▶ return $self->{original_show_name} if defined $self->{original_show_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"original_show_name"} 5 0 5
259 0 return $self->{show_name};
260 }
261  
262 =head2 season
263  
264 Return the season found in the file name. Return '' if {season} is not defined.
265  
266 =cut
267  
268 12 ▶sub season {
Subroutine season: called CC=1 SCAR=0.0
Pod documented
269  
270 12 my $self = shift;
271 12 my $attr = 'season';
272 12 $self->__get_obj_attr($attr);
273 }
274  
275 =head2 season_to_int
276  
277 Return season as an integer
278  
279 =cut
280  
281 2 ▶sub season_to_int {
Subroutine season_to_int: called CC=2 SCAR=8.1
Pod documented
282  
283 2 my $self = shift;
284 2 ▶ return int($self->season()) if defined $self->{season};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"season"} 2 0 2
285 0 return undef;
286 }
287  
288 =head2 episode
289  
290 Return the episode found in the file name. Return '' if {episode} is not defined.
291  
292 =cut
293  
294 11 ▶sub episode {
Subroutine episode: called CC=1 SCAR=0.0
Pod documented
295  
296 11 my $self = shift;
297 11 my $attr = 'episode';
298 11 $self->__get_obj_attr($attr);
299 }
300  
301 =head2 episode_to_int
302  
303 Return episode as an integer
304  
305 =cut
306  
307 2 ▶sub episode_to_int {
Subroutine episode_to_int: called CC=2 SCAR=8.1
Pod documented
308  
309 2 my $self = shift;
310 2 ▶ return int($self->episode()) if defined $self->{episode};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"episode"} 2 0 2
311 0 return undef;
312 }
313  
314 =head2 source
315  
316 Return the source of tv show. Return '' if not defined.
317 Yet to be coded.
318  
319 =cut
320  
321  
322 =head2 is_multi_episode
323  
324 Return 1 if this is a multi-episode file SXXEXXEXX. Return 0 if false
325  
326 This is true if {endep} is defined.
327  
328 =cut
329  
330 10 ▶sub is_multi_episode {
Subroutine is_multi_episode: called CC=2 SCAR=6.9
Pod documented
331  
332 10 my $self = shift;
333  
334 10 ▶ return 1 if defined $self->{endep};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"endep"} 3 7 10
335 7 return 0;
336  
337 }
338  
339 =head2 season_episode
340  
341 Return SXXEXX or SXXEXXEXX for single or multi episode files. Return '' if not
342 created
343  
344 This would only return an empty string if the show_name is not formated as
345 show_name.SXX.*
346  
347 =cut
348  
349 10 ▶sub season_episode {
Subroutine season_episode: called CC=5 SCAR=16.8
Pod documented
350  
351 10 my $self = shift;
352 10 my $s_e = '';
353  
354 # endep indicates that this is is_multi_episode file. SXXEXXEXX
355 10 ▶ if ((defined $self->{episode}) && (!defined $self->{endep})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'episode'} and not defined $self->{'endep'}) { } 7 3 10
elsif (defined $self->{'episode'} and defined $self->{'endep'}) { } 3 0 3
Condition66%2/3
defined $self->{"episode"} and not defined $self->{"endep"}
!ll&&!rl&&r
037
MC/DC50%1/2
defined $self->{"episode"} and not defined $self->{"endep"}
defined $self->{"episode"} not defined $self->{"endep"}
Truth table66%2/3
A and not(B)
A= defined $self->{"episode"}B= not defined $self->{"endep"}
ABresult
0X0
100
111
356 7 $s_e = sprintf("S%02dE%02d", $self->{season}, $self->{episode});
357 ▶ } elsif ((defined $self->{episode}) && (defined $self->{endep})) {
Condition33%1/3
defined $self->{"episode"} and defined $self->{"endep"}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $self->{"episode"} and defined $self->{"endep"}
defined $self->{"episode"} defined $self->{"endep"}
Truth table33%1/3
A and B
A= defined $self->{"episode"}B= defined $self->{"endep"}
ABresult
0X0
100
111
358 # This is a multi-Episde
359 $s_e = sprintf("S%02dE%02dE%02d", $self->{season}, $self->{episode},
360 3 $self->{endep});
361 };
362 10 return $s_e;
363  
364 }
365  
366 =head2 has_year
367  
368 Return 1 if year is defined else return 0
369  
370 =cut
371  
372 18 ▶sub has_year {
Subroutine has_year: called CC=2 SCAR=6.9
Pod documented
373  
374 18 my $self = shift;
375  
376 18 ▶ return 1 if defined $self->{year};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"year"} 8 10 18
377 10 return 0;
378  
379 }
380  
381 =head2 year
382  
383 Return the year found in the file name. Return '' if {year} is not defined.
384  
385 =cut
386  
387 4 ▶sub year {
Subroutine year: called CC=1 SCAR=0.0
Pod documented
388  
389 4 my $self = shift;
390 4 my $attr = 'year';
391 4 $self->__get_obj_attr($attr);
392 }
393  
394 =head2 month
395  
396 Return the month found in the file name. Return '' if {month} is not defined.
397  
398 =cut
399  
400 1 ▶sub month {
Subroutine month: called CC=1 SCAR=0.0
Pod documented
401  
402 1 my $self = shift;
403 1 my $attr = 'month';
404 1 $self->__get_obj_attr($attr);
405 }
406  
407 =head2 date
408  
409 Return the date found in the file name. Return '' if {date} is not defined.
410  
411 =cut
412  
413 1 ▶sub date {
Subroutine date: called CC=1 SCAR=0.0
Pod documented
414  
415 1 my $self = shift;
416 1 my $attr = 'date';
417 1 $self->__get_obj_attr($attr);
418 }
419  
420 =head2 ymd
421  
422 Return the complete date string as 'YYYY.MM.DD' Ruturn '' if attributes
423 {year}, {month}, and {date} are not defined.
424  
425 =cut
426  
427 1 ▶sub ymd {
Subroutine ymd: called CC=3 SCAR=14.2
Pod documented
428  
429 1 my $self = shift;
430  
431 return $self->{year} . "." . $self->{month} . "." . $self->{date}
432 1 ▶ if defined $self->{year} && defined $self->{month};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"year"} and defined $self->{"month"} 1 0 1
Condition33%1/3
defined $self->{"year"} and defined $self->{"month"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"year"} and defined $self->{"month"}
defined $self->{"year"} defined $self->{"month"}
Truth table33%1/3
A and B
A= defined $self->{"year"}B= defined $self->{"month"}
ABresult
0X0
100
111
433 0 return '';
434 }
435  
436 =head2 resolution
437  
438 Return resolution found in the file name. Return '' if {resolution} is not defined.
439  
440 =cut
441  
442 7 ▶sub resolution {
Subroutine resolution: called CC=1 SCAR=0.0
Pod documented
443  
444 7 my $self = shift;
445 7 my $attr = 'resolution';
446 7 $self->__get_obj_attr($attr);
447 }
448  
449 #=head2 network
450  
451 #Return network if found '' if not defined.
452  
453 #Networks: AMZN, HULU, ABC and so on.
454  
455 #=cut
456  
457 4 ▶sub _network {
Subroutine _network: called CC=1 SCAR=0.0
458  
459 4 my $self = shift;
460 4 my $attr = 'network';
461 4 $self->__get_obj_attr($attr);
462  
463  
464 }
465  
466 =head2 release_group
467  
468 Return release_group found in the file name. Return '' if {release_group} is not defined.
469  
470 =cut
471  
472 10 ▶sub release_group {
Subroutine release_group: called CC=1 SCAR=0.0
Pod documented
473  
474 10 my $self = shift;
475 10 my $attr = 'release_group';
476 10 $self->__get_obj_attr($attr);
477 }
478  
479 =head2 episode_name
480  
481 Return episode_name. Return '' if {extra_meta} is not defined or can not
482 determine episode name.
483  
484 Note: episode name MUST directly follow SXXEXX or it can not be found.
485  
486 =cut
487  
488 5 ▶sub episode_name {
Subroutine episode_name: called CC=1 SCAR=0.0
Pod documented
489  
490 5 my $self = shift;
491 5 my $attr = 'episode_name';
492 5 $self->__get_obj_attr($attr);
493 }
494  
495 =head2 strip_episode_name
496  
497 Return episode name without delimiters.
498  
499 =cut
500  
501 4 ▶sub strip_episode_name {
Subroutine strip_episode_name: called CC=2 SCAR=7.0
Pod documented
502  
503 4 my $self = shift;
504  
505 4 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 4 4
506  
507 4 (my $newString = $self->{episode_name}) =~ s/[\._-]/ /g;
508 4 return $newString;
509  
510 }
511  
512 =head2 country
513  
514 Return country found in {show_name}. Return '' if not defined
515  
516 =cut
517  
518 7 ▶sub country {
Subroutine country: called CC=1 SCAR=0.0
Pod documented
519  
520 7 my $self = shift;
521 7 my $attr = 'country';
522 7 $self->__get_obj_attr($attr);
523 }
524  
525 =head2 ext
526  
527 Return file extension. {ext}
528  
529 =cut
530  
531 10 ▶sub ext {
Subroutine ext: called CC=2 SCAR=8.1
Pod documented
532  
533 10 my $self = shift;
534  
535 10 ▶ return $self->{ext} if defined $self->{ext};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ext"} 10 0 10
536 # Return '' or undef? this sould never even happen.
537 0 return undef;
538  
539 }
540  
541 =head2 is_tv_show
542  
543 Return 1 if identified as a TV Show. Default is 0
544  
545 =cut
546  
547 502 ▶sub is_tv_show {
Subroutine is_tv_show: called CC=6 SCAR=18.2
Pod documented
548  
549 502 my ($self) = @_;
550  
551 502 ▶ if (defined $self->{season} && defined $self->{episode}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'season'} and defined $self->{'episode'}) { } 476 26 502
elsif (defined $self->{'year'} and $self->{'month'} and $self->{'date'}) { } 17 18 35
Condition66%2/3
defined $self->{"season"} and defined $self->{"episode"}
!ll&&!rl&&r
260476
MC/DC50%1/2
defined $self->{"season"} and defined $self->{"episode"}
defined $self->{"season"} defined $self->{"episode"}
Truth table66%2/3
A and B
A= defined $self->{"season"}B= defined $self->{"episode"}
ABresult
0X0
100
111
552 476 return 1;
553 ▶ } elsif (defined $self->{year} && $self->{month} && $self->{date}) {
Condition66%4/6
defined $self->{"year"} and $self->{"month"} and $self->{"date"}
!ll&&!rl&&r
9017
defined $self->{"year"} and $self->{"month"}
!ll&&!rl&&r
9017
MC/DC33%1/3
defined $self->{"year"} and $self->{"month"} and $self->{"date"}
defined $self->{"year"} $self->{"month"} $self->{"date"}
Truth table50%2/4
A and B and C
A= defined $self->{"year"}B= $self->{"month"}C= $self->{"date"}
ABCresult
0XX0
10X0
1100
1111
554 17 return 1;
555 }
556 # This is not a TVshow
557 9 return 0;
558 }
559  
560 =head2 is_tv_subtitle
561  
562 Return 1 if the file is a subtitle file, 0 if {is_subtitle} is not defined.
563  
564 The file must also return true for is_tv_show() or the result is 0
565  
566 =cut
567  
568 8 ▶sub is_tv_subtitle {
Subroutine is_tv_subtitle: called CC=3 SCAR=11.0
Pod documented
569  
570 8 my $self = shift;
571  
572 8 ▶ return 1 if (($self->is_tv_show()) && (defined $self->{is_subtitle}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_tv_show and defined $self->{"is_subtitle"} 6 2 8
Condition66%2/3
$self->is_tv_show and defined $self->{"is_subtitle"}
!ll&&!rl&&r
026
MC/DC50%1/2
$self->is_tv_show and defined $self->{"is_subtitle"}
$self->is_tv_show defined $self->{"is_subtitle"}
Truth table66%2/3
A and B
A= $self->is_tv_showB= defined $self->{"is_subtitle"}
ABresult
0X0
100
111
573 2 return 0;
574 }
575  
576 =head2 has_subtitle_lang
577  
578 Return 1 if subtitle language was found, Return 0 if {subtitle_lang} is not defined.
579  
580 Must also return 1 for is_tv_subtitle()
581  
582 =cut
583  
584 4 ▶sub has_subtitle_lang {
Subroutine has_subtitle_lang: called CC=3 SCAR=11.0
Pod documented
585  
586 4 my $self = shift;
587  
588 4 ▶ return 1 if (($self->is_tv_subtitle()) && (defined $self->{subtitle_lang}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_tv_subtitle and defined $self->{"subtitle_lang"} 2 2 4
Condition100%3/3
$self->is_tv_subtitle and defined $self->{"subtitle_lang"}
!ll&&!rl&&r
112
MC/DC100%2/2
$self->is_tv_subtitle and defined $self->{"subtitle_lang"}
$self->is_tv_subtitle defined $self->{"subtitle_lang"}
Truth table100%3/3
A and B
A= $self->is_tv_subtitleB= defined $self->{"subtitle_lang"}
ABresult
0X0
100
111
589 2 return 0;
590 }
591  
592 =head2 subtitle_lang
593  
594 Return the language of the subtitle file: eng or en. Return '' if {subtitle_lang} is not defined.
595  
596 =cut
597  
598 4 ▶sub subtitle_lang {
Subroutine subtitle_lang: called CC=1 SCAR=0.0
Pod documented
599  
600 4 my $self = shift;
601 4 my $attr = 'subtitle_lang';
602 4 $self->__get_obj_attr($attr);
603 }
604  
605 =head2 has_country
606  
607 Return 1 if country was found, Return 0 if {country} is not defined.
608  
609 Must also return 1 for is_tv_subtitle()
610  
611 =cut
612  
613 9 ▶sub has_country {
Subroutine has_country: called CC=3 SCAR=11.0
Pod documented
614  
615 9 my $self = shift;
616  
617 9 ▶ return 1 if (($self->is_tv_show()) && (defined $self->{country}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_tv_show and defined $self->{"country"} 5 4 9
Condition66%2/3
$self->is_tv_show and defined $self->{"country"}
!ll&&!rl&&r
045
MC/DC50%1/2
$self->is_tv_show and defined $self->{"country"}
$self->is_tv_show defined $self->{"country"}
Truth table66%2/3
A and B
A= $self->is_tv_showB= defined $self->{"country"}
ABresult
0X0
100
111
618 4 return 0;
619 }
620  
621 =head2 is_by_date
622  
623 Return 1 if by date. Default is 0
624  
625 This will be true where year, month and date are all defined. show_name.yyyy.mm.dd.ext
626  
627 =cut
628  
629 8 ▶sub is_by_date {
Subroutine is_by_date: called CC=4 SCAR=13.9
Pod documented
630  
631 8 my $self = shift;
632  
633 8 ▶ if (defined $self->{year} && defined $self->{month} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}) 1 7 8
Condition83%5/6
defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}
!ll&&!rl&&r
701
defined $self->{"year"} and defined $self->{"month"}
!ll&&!rl&&r
251
MC/DC66%2/3
defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}
defined $self->{"year"} defined $self->{"month"} defined $self->{"date"}
Truth table75%3/4
A and B and C
A= defined $self->{"year"}B= defined $self->{"month"}C= defined $self->{"date"}
ABCresult
0XX0
10X0
1100
1111
634 defined $self->{date}) {
635 1 return 1;
636 }
637 7 return 0;
638 }
639  
640 =head2 is_by_season
641  
642 Return 1 if by season. Default is 0
643  
644 Requires {season} and {episode} to be defined.
645  
646 =cut
647  
648 2 ▶sub is_by_season {
Subroutine is_by_season: called CC=3 SCAR=11.0
Pod documented
649  
650 2 my $self = shift;
651 2 ▶ if (defined $self->{season} && defined $self->{episode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"season"} and defined $self->{"episode"}) 1 1 2
Condition66%2/3
defined $self->{"season"} and defined $self->{"episode"}
!ll&&!rl&&r
101
MC/DC50%1/2
defined $self->{"season"} and defined $self->{"episode"}
defined $self->{"season"} defined $self->{"episode"}
Truth table66%2/3
A and B
A= defined $self->{"season"}B= defined $self->{"episode"}
ABresult
0X0
100
111
652 1 return 1;
653 }
654 1 return 0;
655 }
656  
657 54 ▶sub _set_tvshow_organize_name {
Subroutine _set_tvshow_organize_name: called CC=3 SCAR=11.1
658  
659 54 my $self = shift;
660  
661 # This is not a tv show file. Exit method now.
662 54 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 1 53 54
663  
664 53 ▶ $self->{organize_name} = $self->{show_name} if defined $self->{show_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"show_name"} 53 0 53
665 }
666  
667 62 ▶sub _isolate_name_year {
Subroutine _isolate_name_year: called CC=8 SCAR=21.5
668  
669 62 my $self = shift;
670  
671 # This is not a tv show file. Exit method now.
672 62 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 1 61 62
673  
674 61 my @exceptions = qw(The.4400);
675  
676 61 my $regex;
677 61 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 61 0 61
678 61 $regex = '(?<show_name>.*[^\s(_.])[\s(_.]+(?<year>\d{4})';
679 } else { # Perl versions below 5.10 do not have group support
680 0 $regex = '(.*[^\s(_.])[\s(_.]+(\d{4})';
681 }
682 # Skip isolation if {show_name} is in the array @exceptions
683 # We do not want to modify the file name.
684 61 foreach (@exceptions) {
685 61 ▶ if ($self->{show_name} =~ m/$_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$_/) 8 53 61
686 8 $self->{do_not_strip} = 1;
687 8 return;
688 }
689 }
690  
691 # break {show_name} from year
692 53 ▶ if ($self->{show_name} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$regex/gi) 12 41 53
693 # First copy {show_name} to new attr
694 12 $self->{original_show_name} = $self->{show_name};
695 # Support to handle either case of group or no groups in regex
696 12 ▶ $self->{year} = $+{year} || $2; #$2 equals group year
Condition33%1/3
$+{'year'} || $2
l!l&&r!l&&!r
1200
MC/DC0%0/2
$+{'year'} || $2
$+{'year'} $2
Truth table33%1/3
A || B
A= $+{'year'}B= $2
ABresult
1X1
011
000
697 12 ▶ $self->{show_name} = $+{show_name} || $1; # $1 equals group show_name
Condition33%1/3
$+{'show_name'} || $1
l!l&&r!l&&!r
1200
MC/DC0%0/2
$+{'show_name'} || $1
$+{'show_name'} $1
Truth table33%1/3
A || B
A= $+{'show_name'}B= $1
ABresult
1X1
011
000
698 }
699 }
700  
701 # TODO: Code _get_source (HTDV, AMZ ?)
702  
703 54 ▶sub _get_episode_name {
Subroutine _get_episode_name: called CC=8 SCAR=20.8
704  
705 54 my $self = shift;
706  
707 # This is not a tv show file. Exit method now.
708 54 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 9 45 54
Condition100%3/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
1845
MC/DC100%2/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table100%3/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
709  
710 # Dont bother search as there is no Episode Name extra_meta starts
711 # with 720p or AMZN or WEB
712 45 ▶ return if $self->{extra_meta} =~ /^([0-9]{3,4}(p|i)|AMZN|WEB)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"extra_meta"} =~ /^([0-9]{3,4}(p|i)|AMZN|WEB)/i 13 32 45
713  
714 # Loop through possible regex list to find suiable regex to use
715 32 for my $pat (@episode_name_patterns) {
716 56 ▶ if ($self->{extra_meta} =~ /$pat->{re}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$pat->{"re"}/i) 22 34 56
717 # We have a match we will exit after this loop
718 # Use this {re} as our regex
719 22 $self->{episode_name_regex} = $pat->{re};
720 # We have a match so we are skipping all other @filePatterns
721 22 last;
722 }
723 }
724 # Only do the extraction of we found a matching regex to use
725 32 ▶ if (defined $self->{episode_name_regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'episode_name_regex'}) { } 22 10 32
726 22 ▶ if ($self->{extra_meta} =~ /$self->{episode_name_regex}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$self->{"episode_name_regex"}/i) 22 0 22
727 22 $self->{episode_name} = $+{episode_name};
728 }
729 } else {
730 # This is only being set for use in testing.
731 # There might be an Episode name, but no regex match found
732 10 $self->{no_episode_name_regex} = 1;
733 }
734 }
735  
736 54 ▶sub _get_release_group {
Subroutine _get_release_group: called CC=6 SCAR=18.4
737  
738 54 my $self = shift;
739  
740 # This is not a tv show file. Exit method now.
741 54 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 9 45 54
Condition100%3/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
1845
MC/DC100%2/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table100%3/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
742  
743 45 my $regex;
744 45 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 45 0 45
745 45 $regex = '[\[]?(?P<release_group>fov|vtv|ettv|rmteam|eztv)[]]?';
746 } else { # Perl versions below 5.10 do not have group support
747 0 $regex = '[\[]?(fov|vtv|ettv|rmteam|eztv)[]]?';
748 }
749 45 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 35 10 45
750 35 ▶ $self->{release_group} = $+{release_group} || $1; # $1 equals group release_group
Condition33%1/3
$+{'release_group'} || $1
l!l&&r!l&&!r
3500
MC/DC0%0/2
$+{'release_group'} || $1
$+{'release_group'} $1
Truth table33%1/3
A || B
A= $+{'release_group'}B= $1
ABresult
1X1
011
000
751 }
752 }
753  
754 54 ▶sub _get_network {
Subroutine _get_network: called CC=4 SCAR=13.9
755  
756 54 my $self = shift;
757  
758 54 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 9 45 54
Condition100%3/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
1845
MC/DC100%2/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table100%3/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
759  
760 #Build REGEX from array of Networks
761 45 my $regex = '(?P<network>';
762 45 $regex .= join('|', @networks);
763 45 $regex .= ')';
764 #my $regex = '(?P<network>ABC|AMZN|BBC|CBS|CC|CW|DCU|DSNY|FBWatch|FREE|FOX|HULU|iP|LIFE|MTV|NBC|NICK|FC|RED|TF1|STZ)';
765 45 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 27 18 45
766 27 $self->{network} = $+{network};
767 }
768 }
769  
770 54 ▶sub _get_resolution {
Subroutine _get_resolution: called CC=6 SCAR=18.4
771  
772 54 my $self = shift;
773  
774 # This is not a tv show file. Exit method now.
775 54 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 9 45 54
Condition100%3/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
1845
MC/DC100%2/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table100%3/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
776  
777 45 my $regex;
778 45 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 45 0 45
779 45 $regex = '(?P<resolution>[0-9]{3,4}[p|i])';
780 } else { # Perl versions below 5.10 do not have group support
781 0 $regex = '([0-9]{3,4}[p|i])';
782 }
783 45 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 32 13 45
784 32 ▶ $self->{resolution} = $+{resolution} || $1; # $1 equals group resolution
Condition33%1/3
$+{'resolution'} || $1
l!l&&r!l&&!r
3200
MC/DC0%0/2
$+{'resolution'} || $1
$+{'resolution'} $1
Truth table33%1/3
A || B
A= $+{'resolution'}B= $1
ABresult
1X1
011
000
785 }
786  
787 }
788  
789 54 ▶sub _get_country {
Subroutine _get_country: called CC=6 SCAR=18.2
790  
791 54 my $self = shift;
792  
793 # This is not a tv show file. Exit method now.
794 54 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 1 53 54
795  
796 53 my $regex;
797 53 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 53 0 53
798 53 $regex = '[(]?(?P<country>\w{2})[)]?$';
799 } else { # Perl versions below 5.10 do not have group support
800 0 $regex = '[(]?(\w{2})[)]?$';
801 }
802 53 ▶ if ($self->{show_name} =~ /$regex/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$regex/g) 50 3 53
803 # Check if string at the end of {show_name} is in the array of accepted
804 # country strings. If not, we do not set {country}
805 50 ▶ if (grep { $_ eq $1 } @{$self->{valid_countries}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $1;} @{$$self{"valid_countries"};}) 7 43 50
806 7 ▶ $self->{country} = $+{country} || $1; # $1 equals group country
Condition33%1/3
$+{'country'} || $1
l!l&&r!l&&!r
700
MC/DC0%0/2
$+{'country'} || $1
$+{'country'} $1
Truth table33%1/3
A || B
A= $+{'country'}B= $1
ABresult
1X1
011
000
807 7 $self->{show_name} =~ s/\(?$1\)?//;
808 7 chop($self->{show_name});
809 }
810 }
811 }
812  
813 54 ▶sub _is_tv_subtitle {
Subroutine _is_tv_subtitle: called CC=3 SCAR=11.0
814  
815 54 my $self = shift;
816  
817 # This is not a tv show file. Exit method now.
818 54 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 1 53 54
819  
820 53 my @list_of_subtitle_ext = qw(srt smi ssa ass vtt);
821  
822 # Check if {ext} is a subtitle extension {is_subtitle} set to 1 if true.
823 53 ▶ if (grep { $_ eq $self->{ext}} @list_of_subtitle_ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $self->{"ext"};} @list_of_subtitle_ext) 4 49 53
824 4 $self->{is_subtitle} = 1;
825 }
826 }
827  
828 54 ▶sub _get_subtitle_lang {
Subroutine _get_subtitle_lang: called CC=5 SCAR=16.7
829  
830 54 my $self = shift;
831  
832 # This is not a subtitle file. Exit method now.
833 54 ▶ return if !defined $self->{is_subtitle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"is_subtitle"} 50 4 54
834  
835 4 my $regex;
836 4 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 4 0 4
837 4 $regex = '(?P<lang>[a-z]{2,})$';
838 } else { # Perl versions below 5.10 do not have group support
839 0 $regex = '([a-z]{2,})$';
840 }
841 4 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 3 1 4
842 3 ▶ $self->{subtitle_lang} = $+{lang} || $1; # $1 equals group lang
Condition33%1/3
$+{'lang'} || $1
l!l&&r!l&&!r
300
MC/DC0%0/2
$+{'lang'} || $1
$+{'lang'} $1
Truth table33%1/3
A || B
A= $+{'lang'}B= $1
ABresult
1X1
011
000
843 }
844 }
845  
846 78 ▶sub __get_obj_attr {
Subroutine __get_obj_attr: called CC=2 SCAR=6.9
847  
848 78 my ($self, $attr) = @_;
849  
850 78 ▶ return $self->{$attr} if defined $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$attr} 68 10 78
851 10 return '';
852  
853 }
854  
855 =head1 AUTHOR
856  
857 Adam Spann, C<< <bans at cpan.org> >>
858  
859 =head1 BUGS
860  
861 Please report any bugs or feature requests to C<bug-file-tvshow-info at rt.cpan.org>, or through
862 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-TVShow-Info>. I will be notified, and then you'll
863 automatically be notified of progress on your bug as I make changes.
864  
865  
866  
867  
868 =head1 SUPPORT
869  
870 You can find documentation for this module with the perldoc command.
871  
872 perldoc File::TVShow::Info
873  
874  
875 You can also look for information at:
876  
877 =over 4
878  
879 =item * RT: CPAN's request tracker (report bugs here)
880  
881 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=File-TVShow-Info>
882  
883 =item * AnnoCPAN: Annotated CPAN documentation
884  
885 L<http://annocpan.org/dist/File-TVShow-Info>
886  
887 =item * CPAN Ratings
888  
889 L<https://cpanratings.perl.org/d/File-TVShow-Info>
890  
891 =item * Search CPAN
892  
893 L<https://metacpan.org/release/File-TVShow-Info>
894  
895 =back
896  
897  
898 =head1 ACKNOWLEDGEMENTS
899  
900  
901 =head1 LICENSE AND COPYRIGHT
902  
903 Copyright 2019 Adam Spann.
904  
905 This program is free software; you can redistribute it and/or modify it
906 under the terms of either: the GNU General Public License as published
907 by the Free Software Foundation; or the Artistic License.
908  
909 See L<http://dev.perl.org/licenses/> for more information.
910  
911  
912 =cut
913  
914 14 1; # End of File::TVShow::Info
↑ Summary EpisodeName.pm »