Info.pm

filter: Statementstmt 8.2% 20 / 242 Branchbran 0.0% 0 / 120 Conditioncond 0.0% 0 / 69 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 13.0% 6 / 46 Podpod 100% 29 / 29 totaltotal 10.0% 55 / 550 SCAR 88.5
CC
89
Cov
5%
new
210.0
_isolate_name_year
72.0
_get_episode_name
72.0
CRAP 6957.7
↑ 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.01 qw (@episode_name_patterns);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use File::TVShow::Networks 0.01 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.0.1
18  
19 =cut
20  
21 14 our $VERSION = '0.01.0.1';
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 sub new {
131 0 ▶ my $class = shift;
Subroutine new: not called CC=14 SCAR=53.5
Pod documented
132 0 my $self = {};
133 0 bless $self, $class;
134 # Set default attributes
135 0 @{$self->{valid_countries}} = qw( US UK KR);
136  
137 # Read default values
138 0 for my $key (qw(file name season episode part options)) {
139 0 ▶ last unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
140 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
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 0 $self->{$key} = shift;
147 }
148 }
149  
150 0 $self->{filename} = $self->{file};
151  
152 # Run filename through list of patterns
153 0 for my $pat (@filePatterns) {
154 0 ▶ if ($] >= 5.010000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
155 0 ▶ if ($self->{file} =~ /$pat->{re}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"} =~ /$pat->{"re"}/i) 0 0 0
156 # We have a match we will exit after this loop
157 0 $self->{regex} = $pat->{re};
158 0 ▶ while (my ($key, $data) = each %-) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %-) 0 0 0
159 0 ▶ $self->{$key} = $data->[0] if defined $data->[0] && !defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->[0] and not defined $self->{$key} 0 0 0
Condition0%0/3
defined $data->[0] and not defined $self->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data->[0] and not defined $self->{$key}
defined $data->[0] not defined $self->{$key}
Truth table0%0/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 0 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 0 $self->_set_tvshow_organize_name();
179 0 $self->_isolate_name_year();
180 0 $self->_get_resolution();
181 0 $self->_get_network();
182 0 $self->_get_release_group();
183 0 $self->_is_tv_subtitle();
184 0 $self->_get_subtitle_lang();
185 0 $self->_get_country();
186 0 $self->_get_episode_name();
187 0 return $self;
188 }
189  
190 =head2 show_name
191  
192 Return the show name found in the file name.
193  
194 =cut
195  
196 sub show_name {
197  
198 0 ▶ my $self = shift;
Subroutine show_name: not called CC=1 SCAR=6.9
Pod documented
199 0 my $attr = 'show_name';
200 0 $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 sub strip_show_name {
210  
211 0 ▶ my $self = shift;
Subroutine strip_show_name: not called CC=3 SCAR=24.8
Pod documented
212  
213 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
214  
215 0 ▶ return $self->{show_name} if defined $self->{do_not_strip};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"do_not_strip"} 0 0 0
216 0 (my $newString = $self->{show_name}) =~ s/[\._-]/ /g;
217 0 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 sub clean_show_name {
229  
230 0 ▶ my $self = shift;
Subroutine clean_show_name: not called CC=4 SCAR=30.0
Pod documented
231  
232 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
233  
234 0 my $newString = $self->strip_show_name();
235 0 ▶ if ($self->has_year()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_year) { } 0 0 0
elsif ($self->has_country) { } 0 0 0
236 0 $newString .= ' (' . $self->year() . ')';
237 } elsif ($self->has_country()) {
238 0 $newString .= ' (' . $self->country() . ')';
239 }
240 0 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 sub original_show_name {
255  
256 0 ▶ my $self = shift;
Subroutine original_show_name: not called CC=2 SCAR=17.9
Pod documented
257  
258 0 ▶ return $self->{original_show_name} if defined $self->{original_show_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"original_show_name"} 0 0 0
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 sub season {
269  
270 0 ▶ my $self = shift;
Subroutine season: not called CC=1 SCAR=6.9
Pod documented
271 0 my $attr = 'season';
272 0 $self->__get_obj_attr($attr);
273 }
274  
275 =head2 season_to_int
276  
277 Return season as an integer
278  
279 =cut
280  
281 sub season_to_int {
282  
283 0 ▶ my $self = shift;
Subroutine season_to_int: not called CC=2 SCAR=17.9
Pod documented
284 0 ▶ return int($self->season()) if defined $self->{season};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"season"} 0 0 0
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 sub episode {
295  
296 0 ▶ my $self = shift;
Subroutine episode: not called CC=1 SCAR=6.9
Pod documented
297 0 my $attr = 'episode';
298 0 $self->__get_obj_attr($attr);
299 }
300  
301 =head2 episode_to_int
302  
303 Return episode as an integer
304  
305 =cut
306  
307 sub episode_to_int {
308  
309 0 ▶ my $self = shift;
Subroutine episode_to_int: not called CC=2 SCAR=17.9
Pod documented
310 0 ▶ return int($self->episode()) if defined $self->{episode};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"episode"} 0 0 0
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 sub is_multi_episode {
331  
332 0 ▶ my $self = shift;
Subroutine is_multi_episode: not called CC=2 SCAR=17.9
Pod documented
333  
334 0 ▶ return 1 if defined $self->{endep};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"endep"} 0 0 0
335 0 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 sub season_episode {
350  
351 0 ▶ my $self = shift;
Subroutine season_episode: not called CC=5 SCAR=34.0
Pod documented
352 0 my $s_e = '';
353  
354 # endep indicates that this is is_multi_episode file. SXXEXXEXX
355 0 ▶ if ((defined $self->{episode}) && (!defined $self->{endep})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'episode'} and not defined $self->{'endep'}) { } 0 0 0
elsif (defined $self->{'episode'} and defined $self->{'endep'}) { } 0 0 0
Condition0%0/3
defined $self->{"episode"} and not defined $self->{"endep"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"episode"} and not defined $self->{"endep"}
defined $self->{"episode"} not defined $self->{"endep"}
Truth table0%0/3
A and not(B)
A= defined $self->{"episode"}B= not defined $self->{"endep"}
ABresult
0X0
100
111
356 0 $s_e = sprintf("S%02dE%02d", $self->{season}, $self->{episode});
357 ▶ } elsif ((defined $self->{episode}) && (defined $self->{endep})) {
Condition0%0/3
defined $self->{"episode"} and defined $self->{"endep"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"episode"} and defined $self->{"endep"}
defined $self->{"episode"} defined $self->{"endep"}
Truth table0%0/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 0 $self->{endep});
361 };
362 0 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 sub has_year {
373  
374 0 ▶ my $self = shift;
Subroutine has_year: not called CC=2 SCAR=17.9
Pod documented
375  
376 0 ▶ return 1 if defined $self->{year};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"year"} 0 0 0
377 0 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 sub year {
388  
389 0 ▶ my $self = shift;
Subroutine year: not called CC=1 SCAR=6.9
Pod documented
390 0 my $attr = 'year';
391 0 $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 sub month {
401  
402 0 ▶ my $self = shift;
Subroutine month: not called CC=1 SCAR=6.9
Pod documented
403 0 my $attr = 'month';
404 0 $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 sub date {
414  
415 0 ▶ my $self = shift;
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
416 0 my $attr = 'date';
417 0 $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 sub ymd {
428  
429 0 ▶ my $self = shift;
Subroutine ymd: not called CC=3 SCAR=24.8
Pod documented
430  
431 return $self->{year} . "." . $self->{month} . "." . $self->{date}
432 0 ▶ if defined $self->{year} && defined $self->{month};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"year"} and defined $self->{"month"} 0 0 0
Condition0%0/3
defined $self->{"year"} and defined $self->{"month"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"year"} and defined $self->{"month"}
defined $self->{"year"} defined $self->{"month"}
Truth table0%0/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 sub resolution {
443  
444 0 ▶ my $self = shift;
Subroutine resolution: not called CC=1 SCAR=6.9
Pod documented
445 0 my $attr = 'resolution';
446 0 $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 sub _network {
458  
459 0 ▶ my $self = shift;
Subroutine _network: not called CC=1 SCAR=6.9
460 0 my $attr = 'network';
461 0 $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 sub release_group {
473  
474 0 ▶ my $self = shift;
Subroutine release_group: not called CC=1 SCAR=6.9
Pod documented
475 0 my $attr = 'release_group';
476 0 $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 sub episode_name {
489  
490 0 ▶ my $self = shift;
Subroutine episode_name: not called CC=1 SCAR=6.9
Pod documented
491 0 my $attr = 'episode_name';
492 0 $self->__get_obj_attr($attr);
493 }
494  
495 =head2 strip_episode_name
496  
497 Return episode name without delimiters.
498  
499 =cut
500  
501 sub strip_episode_name {
502  
503 0 ▶ my $self = shift;
Subroutine strip_episode_name: not called CC=2 SCAR=17.9
Pod documented
504  
505 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
506  
507 0 (my $newString = $self->{episode_name}) =~ s/[\._-]/ /g;
508 0 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 sub country {
519  
520 0 ▶ my $self = shift;
Subroutine country: not called CC=1 SCAR=6.9
Pod documented
521 0 my $attr = 'country';
522 0 $self->__get_obj_attr($attr);
523 }
524  
525 =head2 ext
526  
527 Return file extension. {ext}
528  
529 =cut
530  
531 sub ext {
532  
533 0 ▶ my $self = shift;
Subroutine ext: not called CC=2 SCAR=17.9
Pod documented
534  
535 0 ▶ return $self->{ext} if defined $self->{ext};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ext"} 0 0 0
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 sub is_tv_show {
548  
549 0 ▶ my ($self) = @_;
Subroutine is_tv_show: not called CC=6 SCAR=37.4
Pod documented
550  
551 0 ▶ if (defined $self->{season} && defined $self->{episode}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'season'} and defined $self->{'episode'}) { } 0 0 0
elsif (defined $self->{'year'} and $self->{'month'} and $self->{'date'}) { } 0 0 0
Condition0%0/3
defined $self->{"season"} and defined $self->{"episode"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"season"} and defined $self->{"episode"}
defined $self->{"season"} defined $self->{"episode"}
Truth table0%0/3
A and B
A= defined $self->{"season"}B= defined $self->{"episode"}
ABresult
0X0
100
111
552 0 return 1;
553 ▶ } elsif (defined $self->{year} && $self->{month} && $self->{date}) {
Condition0%0/6
defined $self->{"year"} and $self->{"month"} and $self->{"date"}
!ll&&!rl&&r
000
defined $self->{"year"} and $self->{"month"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"year"} and $self->{"month"} and $self->{"date"}
defined $self->{"year"} $self->{"month"} $self->{"date"}
Truth table0%0/4
A and B and C
A= defined $self->{"year"}B= $self->{"month"}C= $self->{"date"}
ABCresult
0XX0
10X0
1100
1111
554 0 return 1;
555 }
556 # This is not a TVshow
557 0 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 sub is_tv_subtitle {
569  
570 0 ▶ my $self = shift;
Subroutine is_tv_subtitle: not called CC=3 SCAR=24.8
Pod documented
571  
572 0 ▶ 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"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"is_subtitle"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"is_subtitle"}
$self->is_tv_show defined $self->{"is_subtitle"}
Truth table0%0/3
A and B
A= $self->is_tv_showB= defined $self->{"is_subtitle"}
ABresult
0X0
100
111
573 0 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 sub has_subtitle_lang {
585  
586 0 ▶ my $self = shift;
Subroutine has_subtitle_lang: not called CC=3 SCAR=24.8
Pod documented
587  
588 0 ▶ 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"} 0 0 0
Condition0%0/3
$self->is_tv_subtitle and defined $self->{"subtitle_lang"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_subtitle and defined $self->{"subtitle_lang"}
$self->is_tv_subtitle defined $self->{"subtitle_lang"}
Truth table0%0/3
A and B
A= $self->is_tv_subtitleB= defined $self->{"subtitle_lang"}
ABresult
0X0
100
111
589 0 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 sub subtitle_lang {
599  
600 0 ▶ my $self = shift;
Subroutine subtitle_lang: not called CC=1 SCAR=6.9
Pod documented
601 0 my $attr = 'subtitle_lang';
602 0 $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 sub has_country {
614  
615 0 ▶ my $self = shift;
Subroutine has_country: not called CC=3 SCAR=24.8
Pod documented
616  
617 0 ▶ return 1 if (($self->is_tv_show()) && (defined $self->{country}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_tv_show and defined $self->{"country"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"country"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"country"}
$self->is_tv_show defined $self->{"country"}
Truth table0%0/3
A and B
A= $self->is_tv_showB= defined $self->{"country"}
ABresult
0X0
100
111
618 0 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 sub is_by_date {
630  
631 0 ▶ my $self = shift;
Subroutine is_by_date: not called CC=4 SCAR=30.0
Pod documented
632  
633 0 ▶ if (defined $self->{year} && defined $self->{month} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}) 0 0 0
Condition0%0/6
defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}
!ll&&!rl&&r
000
defined $self->{"year"} and defined $self->{"month"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"year"} and defined $self->{"month"} and defined $self->{"date"}
defined $self->{"year"} defined $self->{"month"} defined $self->{"date"}
Truth table0%0/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 0 return 1;
636 }
637 0 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 sub is_by_season {
649  
650 0 ▶ my $self = shift;
Subroutine is_by_season: not called CC=3 SCAR=24.8
Pod documented
651 0 ▶ if (defined $self->{season} && defined $self->{episode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"season"} and defined $self->{"episode"}) 0 0 0
Condition0%0/3
defined $self->{"season"} and defined $self->{"episode"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"season"} and defined $self->{"episode"}
defined $self->{"season"} defined $self->{"episode"}
Truth table0%0/3
A and B
A= defined $self->{"season"}B= defined $self->{"episode"}
ABresult
0X0
100
111
652 0 return 1;
653 }
654 0 return 0;
655 }
656  
657 sub _set_tvshow_organize_name {
658  
659 0 ▶ my $self = shift;
Subroutine _set_tvshow_organize_name: not called CC=3 SCAR=24.8
660  
661 # This is not a tv show file. Exit method now.
662 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
663  
664 0 ▶ $self->{organize_name} = $self->{show_name} if defined $self->{show_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"show_name"} 0 0 0
665 }
666  
667 sub _isolate_name_year {
668  
669 0 ▶ my $self = shift;
Subroutine _isolate_name_year: not called CC=8 SCAR=42.8
670  
671 # This is not a tv show file. Exit method now.
672 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
673  
674 0 my @exceptions = qw(The.4400);
675  
676 0 my $regex;
677 0 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
678 0 $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 0 foreach (@exceptions) {
685 0 ▶ if ($self->{show_name} =~ m/$_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$_/) 0 0 0
686 0 $self->{do_not_strip} = 1;
687 0 return;
688 }
689 }
690  
691 # break {show_name} from year
692 0 ▶ if ($self->{show_name} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$regex/gi) 0 0 0
693 # First copy {show_name} to new attr
694 0 $self->{original_show_name} = $self->{show_name};
695 # Support to handle either case of group or no groups in regex
696 0 ▶ $self->{year} = $+{year} || $2; #$2 equals group year
Condition0%0/3
$+{'year'} || $2
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'year'} || $2
$+{'year'} $2
Truth table0%0/3
A || B
A= $+{'year'}B= $2
ABresult
1X1
011
000
697 0 ▶ $self->{show_name} = $+{show_name} || $1; # $1 equals group show_name
Condition0%0/3
$+{'show_name'} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'show_name'} || $1
$+{'show_name'} $1
Truth table0%0/3
A || B
A= $+{'show_name'}B= $1
ABresult
1X1
011
000
698 }
699 }
700  
701 # TODO: Code _get_source (HTDV, AMZ ?)
702  
703 sub _get_episode_name {
704  
705 0 ▶ my $self = shift;
Subroutine _get_episode_name: not called CC=8 SCAR=42.8
706  
707 # This is not a tv show file. Exit method now.
708 0 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table0%0/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 0 ▶ 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 0 0 0
713  
714 # Loop through possible regex list to find suiable regex to use
715 0 for my $pat (@episode_name_patterns) {
716 0 ▶ if ($self->{extra_meta} =~ /$pat->{re}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$pat->{"re"}/i) 0 0 0
717 # We have a match we will exit after this loop
718 # Use this {re} as our regex
719 0 $self->{episode_name_regex} = $pat->{re};
720 # We have a match so we are skipping all other @filePatterns
721 0 last;
722 }
723 }
724 # Only do the extraction of we found a matching regex to use
725 0 ▶ if (defined $self->{episode_name_regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'episode_name_regex'}) { } 0 0 0
726 0 ▶ if ($self->{extra_meta} =~ /$self->{episode_name_regex}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$self->{"episode_name_regex"}/i) 0 0 0
727 0 $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 0 $self->{no_episode_name_regex} = 1;
733 }
734 }
735  
736 sub _get_release_group {
737  
738 0 ▶ my $self = shift;
Subroutine _get_release_group: not called CC=6 SCAR=37.4
739  
740 # This is not a tv show file. Exit method now.
741 0 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table0%0/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
742  
743 0 my $regex;
744 0 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
745 0 $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 0 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 0 0 0
750 0 ▶ $self->{release_group} = $+{release_group} || $1; # $1 equals group release_group
Condition0%0/3
$+{'release_group'} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'release_group'} || $1
$+{'release_group'} $1
Truth table0%0/3
A || B
A= $+{'release_group'}B= $1
ABresult
1X1
011
000
751 }
752 }
753  
754 sub _get_network {
755  
756 0 ▶ my $self = shift;
Subroutine _get_network: not called CC=4 SCAR=30.0
757  
758 0 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table0%0/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 0 my $regex = '(?P<network>';
762 0 $regex .= join('|', @networks);
763 0 $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 0 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 0 0 0
766 0 $self->{network} = $+{network};
767 }
768 }
769  
770 sub _get_resolution {
771  
772 0 ▶ my $self = shift;
Subroutine _get_resolution: not called CC=6 SCAR=37.4
773  
774 # This is not a tv show file. Exit method now.
775 0 ▶ return if !$self->is_tv_show() || !defined $self->{extra_meta};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show and defined $self->{"extra_meta"} 0 0 0
Condition0%0/3
$self->is_tv_show and defined $self->{"extra_meta"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_tv_show and defined $self->{"extra_meta"}
$self->is_tv_show defined $self->{"extra_meta"}
Truth table0%0/3
A and B
A= $self->is_tv_showB= defined $self->{"extra_meta"}
ABresult
0X0
100
111
776  
777 0 my $regex;
778 0 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
779 0 $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 0 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 0 0 0
784 0 ▶ $self->{resolution} = $+{resolution} || $1; # $1 equals group resolution
Condition0%0/3
$+{'resolution'} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'resolution'} || $1
$+{'resolution'} $1
Truth table0%0/3
A || B
A= $+{'resolution'}B= $1
ABresult
1X1
011
000
785 }
786  
787 }
788  
789 sub _get_country {
790  
791 0 ▶ my $self = shift;
Subroutine _get_country: not called CC=6 SCAR=37.4
792  
793 # This is not a tv show file. Exit method now.
794 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
795  
796 0 my $regex;
797 0 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
798 0 $regex = '[(]?(?P<country>\w{2})[)]?$';
799 } else { # Perl versions below 5.10 do not have group support
800 0 $regex = '[(]?(\w{2})[)]?$';
801 }
802 0 ▶ if ($self->{show_name} =~ /$regex/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_name"} =~ /$regex/g) 0 0 0
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 0 ▶ if (grep { $_ eq $1 } @{$self->{valid_countries}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $1;} @{$$self{"valid_countries"};}) 0 0 0
806 0 ▶ $self->{country} = $+{country} || $1; # $1 equals group country
Condition0%0/3
$+{'country'} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'country'} || $1
$+{'country'} $1
Truth table0%0/3
A || B
A= $+{'country'}B= $1
ABresult
1X1
011
000
807 0 $self->{show_name} =~ s/\(?$1\)?//;
808 0 chop($self->{show_name});
809 }
810 }
811 }
812  
813 sub _is_tv_subtitle {
814  
815 0 ▶ my $self = shift;
Subroutine _is_tv_subtitle: not called CC=3 SCAR=24.8
816  
817 # This is not a tv show file. Exit method now.
818 0 ▶ return if !$self->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_tv_show 0 0 0
819  
820 0 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 0 ▶ if (grep { $_ eq $self->{ext}} @list_of_subtitle_ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $self->{"ext"};} @list_of_subtitle_ext) 0 0 0
824 0 $self->{is_subtitle} = 1;
825 }
826 }
827  
828 sub _get_subtitle_lang {
829  
830 0 ▶ my $self = shift;
Subroutine _get_subtitle_lang: not called CC=5 SCAR=34.0
831  
832 # This is not a subtitle file. Exit method now.
833 0 ▶ return if !defined $self->{is_subtitle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"is_subtitle"} 0 0 0
834  
835 0 my $regex;
836 0 ▶ if ($] >= 5.010000) { # Perl 5.10 > has regex group support
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.01) { } 0 0 0
837 0 $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 0 ▶ if ($self->{extra_meta} =~ /$regex/gi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_meta"} =~ /$regex/gi) 0 0 0
842 0 ▶ $self->{subtitle_lang} = $+{lang} || $1; # $1 equals group lang
Condition0%0/3
$+{'lang'} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{'lang'} || $1
$+{'lang'} $1
Truth table0%0/3
A || B
A= $+{'lang'}B= $1
ABresult
1X1
011
000
843 }
844 }
845  
846 sub __get_obj_attr {
847  
848 0 ▶ my ($self, $attr) = @_;
Subroutine __get_obj_attr: not called CC=2 SCAR=17.9
849  
850 0 ▶ return $self->{$attr} if defined $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$attr} 0 0 0
851 0 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 »