MP4Meta/Command/tv.pm

filter: Statementstmt 43.5% 17 / 39 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 38.4% 5 / 13 Podpod 100% 5 / 5 totaltotal 38.0% 27 / 71 CC 10 SCAR 27.0
CC
10
Cov
32%
validate_args
30.0
execute
30.0
__ANON__
6.0
CRAP 14.9
« MP4Meta/Base.pm ↑ Summary MP4Meta/Command/film.pm »
1 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package App::MP4Meta::Command::tv;
6 {
7 1 $App::MP4Meta::Command::tv::VERSION = '1.153340';
8 }
9  
10 # ABSTRACT: Apply metadata to a TV Series. Parses the filename in order to get the shows title and its season and episode number.
11  
12 1 ▶use App::MP4Meta -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 0 ▶sub usage_desc { "tv %o [file ...]" }
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
18  
19 0 ▶sub abstract {
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
20 0 'Apply metadata to a TV Series. Parses the filename in order to get the shows title and its season and episode number.';
21 }
22  
23 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
24 return (
25 0 [ "genre=s", "The genre of the TV Show" ],
26 [ "coverfile=s", "The location of the cover image" ],
27 [ "sources=s@", "The sources to search", { default => [qw/TVDB/] } ],
28 [ "title=s", "The title of the TV Show" ],
29 [ "series=s", "The series number" ],
30 [ "episode=s", "The episode number" ],
31 [ "noreplace", "Don't replace the file - creates a temp file instead" ],
32 [ "itunes", "adds to iTunes after applying meta data. Mac OSX only." ],
33 [ "verbose", "Print verbosely" ],
34 [
35 "withoutany",
36 "Continue to process even if we can not find any information on the internet"
37 ],
38 );
39 }
40  
41 0 ▶sub validate_args {
Subroutine validate_args: not called CC=5 SCAR=34.0
Pod documented
42 0 my ( $self, $opt, $args ) = @_;
43  
44 # we need at least one file to work with
45 0 ▶ $self->usage_error("too few arguments") unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 0 0
46  
47 # TODO: check we have a source
48  
49 # check each file
50 0 for my $f (@$args) {
51 0 ▶ unless ( -e $f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $f) 0 0 0
52 0 $self->usage_error("$f does not exist");
53 }
54 0 ▶ unless ( -r $f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $f) 0 0 0
55 0 $self->usage_error("can not read $f");
56 }
57  
58 # TODO: is $f an mp4?
59 }
60 }
61  
62 0 ▶sub execute {
Subroutine execute: not called CC=5 SCAR=34.0
Pod documented
63 0 my ( $self, $opt, $args ) = @_;
64  
65 0 require App::MP4Meta::TV;
66 my $tv = App::MP4Meta::TV->new(
67 {
68 noreplace => $opt->{noreplace},
69 genre => $opt->{genre},
70 sources => $opt->{sources},
71 title => $opt->{title},
72 cover => $opt->{coverfile},
73 itunes => $opt->{itunes},
74 verbose => $opt->{verbose},
75 continue_without_any => $opt->{withoutany},
76 }
77 0 );
78  
79 0 ▶ say sprintf( 'processing %d files', scalar @$args ) if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
80  
81 0 for my $file (@$args) {
82 0 ▶ say "processing $file" if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
83 0 my $error;
84 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 0 $error = $tv->apply_meta($file);
86 }
87 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 $error = "Error applying meta to $file: $_";
89 }
90 0 ▶ finally {
Subroutine __ANON__: not called CC=2 SCAR=17.9
91 0 ▶ say $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
92 0 };
93 }
94  
95 0 ▶ say 'done' if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
96 }
97  
98 1 1;
99  
100 __END__
« MP4Meta/Base.pm ↑ Summary MP4Meta/Command/film.pm »