File Coverage

blib/lib/App/MP4Meta/Command/musicvideo.pm
Criterion Covered Total %
statement 21 35 60.0
branch 3 12 25.0
condition n/a
subroutine 8 13 61.5
pod 5 5 100.0
total 37 65 56.9


line stmt bran cond sub pod time code
1 1     1   827 use 5.010;
  1         4  
2 1     1   6 use strict;
  1         2  
  1         23  
3 1     1   6 use warnings;
  1         2  
  1         58  
4              
5             package App::MP4Meta::Command::musicvideo;
6             {
7             $App::MP4Meta::Command::musicvideo::VERSION = '1.153340';
8             }
9              
10             # ABSTRACT: Apply metadata to a music video. Parses the filename in order to get its artist and title.
11              
12 1     1   6 use App::MP4Meta -command;
  1         2  
  1         7  
13              
14 1     1   389 use Try::Tiny;
  1         2  
  1         437  
15              
16              
17 2     2 1 10680 sub usage_desc { "musicvideo %o [file ...]" }
18              
19             sub abstract {
20 0     0 1 0 'Apply metadata to a music video. Parses the filename in order to get its artist and title.';
21             }
22              
23             sub opt_spec {
24             return (
25 2     2 1 24 [ "genre=s", "The genre of the music video" ],
26             [ "coverfile=s", "The location of the cover image" ],
27             [ "title=s", "The title of the music video" ],
28             [ "noreplace", "Don't replace the file - creates a temp file instead" ],
29             [ "itunes", "adds to iTunes after applying meta data. Mac OSX only." ],
30             [ "verbose", "Print verbosely" ],
31             );
32             }
33              
34             sub validate_args {
35 2     2 1 2875 my ( $self, $opt, $args ) = @_;
36              
37             # we need at least one file to work with
38 2 100       14 $self->usage_error("too few arguments") unless @$args;
39              
40             # check each file
41 1         3 for my $f (@$args) {
42 1 50       35 unless ( -e $f ) {
43 1         8 $self->usage_error("$f does not exist");
44             }
45 0 0         unless ( -r $f ) {
46 0           $self->usage_error("can not read $f");
47             }
48              
49             # TODO: is $f an mp4?
50             }
51             }
52              
53             sub execute {
54 0     0 1   my ( $self, $opt, $args ) = @_;
55              
56 0           require App::MP4Meta::MusicVideo;
57             my $mv = App::MP4Meta::MusicVideo->new(
58             {
59             noreplace => $opt->{noreplace},
60             genre => $opt->{genre},
61             title => $opt->{title},
62             coverfile => $opt->{coverfile},
63             itunes => $opt->{itunes},
64             verbose => $opt->{verbose},
65             }
66 0           );
67              
68 0           for my $file (@$args) {
69 0 0         say "processing $file" if $opt->{verbose};
70 0           my $error;
71             try {
72 0     0     $error = $mv->apply_meta($file);
73             }
74             catch {
75 0     0     $error = "Error applying meta to $file: $_";
76             }
77             finally {
78 0 0   0     say $error if $error;
79 0           };
80             }
81              
82 0 0         say 'done' if $opt->{verbose};
83             }
84              
85             1;
86              
87             __END__