File Coverage

blib/lib/App/MP4Meta/Command/tv.pm
Criterion Covered Total %
statement 21 36 58.3
branch 3 14 21.4
condition n/a
subroutine 8 13 61.5
pod 5 5 100.0
total 37 68 54.4


line stmt bran cond sub pod time code
1 1     1   779 use 5.010;
  1         3  
2 1     1   5 use strict;
  1         3  
  1         21  
3 1     1   5 use warnings;
  1         3  
  1         55  
4              
5             package App::MP4Meta::Command::tv;
6             {
7             $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     1   5 use App::MP4Meta -command;
  1         2  
  1         7  
13              
14 1     1   285 use Try::Tiny;
  1         2  
  1         490  
15              
16              
17 2     2 1 26245 sub usage_desc { "tv %o [file ...]" }
18              
19             sub abstract {
20 0     0 1 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             sub opt_spec {
24             return (
25 2     2 1 31 [ "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             sub validate_args {
42 2     2 1 4472 my ( $self, $opt, $args ) = @_;
43              
44             # we need at least one file to work with
45 2 100       16 $self->usage_error("too few arguments") unless @$args;
46              
47             # TODO: check we have a source
48              
49             # check each file
50 1         4 for my $f (@$args) {
51 1 50       33 unless ( -e $f ) {
52 1         6 $self->usage_error("$f does not exist");
53             }
54 0 0         unless ( -r $f ) {
55 0           $self->usage_error("can not read $f");
56             }
57              
58             # TODO: is $f an mp4?
59             }
60             }
61              
62             sub execute {
63 0     0 1   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 0         say sprintf( 'processing %d files', scalar @$args ) if $opt->{verbose};
80              
81 0           for my $file (@$args) {
82 0 0         say "processing $file" if $opt->{verbose};
83 0           my $error;
84             try {
85 0     0     $error = $tv->apply_meta($file);
86             }
87             catch {
88 0     0     $error = "Error applying meta to $file: $_";
89             }
90             finally {
91 0 0   0     say $error if $error;
92 0           };
93             }
94              
95 0 0         say 'done' if $opt->{verbose};
96             }
97              
98             1;
99              
100             __END__