App-MP4Meta
view release on metacpan or search on metacpan
lib/App/MP4Meta/Base.pm view on Meta::CPAN
use 5.010;
use strict;
use warnings;
package App::MP4Meta::Base;
{
$App::MP4Meta::Base::VERSION = '1.153340';
}
# ABSTRACT: Base class. Contains common functionality.
use Module::Load ();
use Try::Tiny;
use AtomicParsley::Command;
sub new {
my $class = shift;
my $args = shift;
my $self = {};
# file suffixes we support
my @suffixes = qw/mp4 m4a m4p m4v m4b/;
$self->{suffixes} = \@suffixes;
# the path to AtomicParsley
$self->{'ap'} = AtomicParsley::Command->new( { ap => $args->{'ap'} } );
# if true, replace file
$self->{'noreplace'} = $args->{'noreplace'};
# if true, add to itunes
$self->{'itunes'} = $args->{'itunes'};
# if true, print verbosely
$self->{'verbose'} = $args->{'verbose'};
# internet sources
$self->{'sources'} = $args->{'sources'};
# common attributes for a media file
$self->{'genre'} = $args->{'genre'};
$self->{'title'} = $args->{'title'};
$self->{'coverfile'} = $args->{'coverfile'};
bless( $self, $class );
# create sources now so they are in scope for as long as we are
$self->{'sources_objects'} = [];
for my $source ( @{ $self->{'sources'} } ) {
try {
push( @{ $self->{'sources_objects'} },
$self->_new_source($source) );
}
catch {
say STDERR "could not load source: $_";
};
}
return $self;
}
# Calls AtomicParsley and writes the tags to the file
sub _write_tags {
my ( $self, $path, $tags ) = @_;
my $tempfile = $self->{ap}->write_tags( $path, $tags, !$self->{noreplace} );
if ( !$self->{ap}->{success} ) {
return $self->{ap}->{'stdout_buf'}[0] // $self->{ap}->{'full_buf'}[0];
}
if ( !$tempfile ) {
return "Error writing to file";
( run in 1.789 second using v1.01-cache-2.11-cpan-39bf76dae61 )