| 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::film; | ||||||||||
| 6 | { | ||||||||||
| 7 | 1 | $App::MP4Meta::Command::film::VERSION = '1.153340'; | |||||||||
| 8 | } | ||||||||||
| 9 | |||||||||||
| 10 | # ABSTRACT: Apply metadata to a film. Parses the filename in order to get the films title and (optionally) year. | ||||||||||
| 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 { "film %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 film. Parses the filename in order to get the films title and (optionally) year.'; | |||||||||
| 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 Film" ], | |||||||||
| 26 | [ "coverfile=s", "The location of the cover image" ], | ||||||||||
| 27 | [ "sources=s@", "The sources to search", { default => [qw/OMDB/] } ], | ||||||||||
| 28 | [ "title=s", "The title of the Film" ], | ||||||||||
| 29 | [ "noreplace", "Don't replace the file - creates a temp file instead" ], | ||||||||||
| 30 | [ "itunes", "adds to iTunes after applying meta data. Mac OSX only." ], | ||||||||||
| 31 | [ "verbose", "Print verbosely" ], | ||||||||||
| 32 | [ | ||||||||||
| 33 | "withoutany", | ||||||||||
| 34 | "Continue to process even if we can not find any information on the internet" | ||||||||||
| 35 | ], | ||||||||||
| 36 | ); | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 40 | 0 | my ( $self, $opt, $args ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | # we need at least one file to work with | ||||||||||
| 43 | 0 | ▶ | $self->usage_error("too few arguments") unless @$args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | |||||||||||
| 45 | # check each file | ||||||||||
| 46 | 0 | for my $f (@$args) { | |||||||||
| 47 | 0 | ▶ | unless ( -e $f ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $self->usage_error("$f does not exist"); | |||||||||
| 49 | } | ||||||||||
| 50 | 0 | ▶ | unless ( -r $f ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | $self->usage_error("can not read $f"); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | # TODO: is $f an mp4? | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 59 | 0 | my ( $self, $opt, $args ) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 0 | require App::MP4Meta::Film; | |||||||||
| 62 | my $film = App::MP4Meta::Film->new( | ||||||||||
| 63 | { | ||||||||||
| 64 | noreplace => $opt->{noreplace}, | ||||||||||
| 65 | genre => $opt->{genre}, | ||||||||||
| 66 | sources => $opt->{sources}, | ||||||||||
| 67 | title => $opt->{title}, | ||||||||||
| 68 | coverfile => $opt->{coverfile}, | ||||||||||
| 69 | itunes => $opt->{itunes}, | ||||||||||
| 70 | verbose => $opt->{verbose}, | ||||||||||
| 71 | continue_without_any => $opt->{withoutany}, | ||||||||||
| 72 | } | ||||||||||
| 73 | 0 | ); | |||||||||
| 74 | |||||||||||
| 75 | 0 | for my $file (@$args) { | |||||||||
| 76 | 0 | ▶ | say "processing $file" if $opt->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 0 | my $error; | |||||||||
| 78 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 79 | 0 | $error = $film->apply_meta($file); | |||||||||
| 80 | } | ||||||||||
| 81 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 82 | 0 | $error = "Error applying meta to $file: $_"; | |||||||||
| 83 | } | ||||||||||
| 84 | 0 | ▶ | finally { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 85 | 0 | ▶ | say $error if $error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | }; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | say 'done' if $opt->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 1 | 1; | |||||||||
| 93 | |||||||||||
| 94 | __END__ | ||||||||||