| 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 AtomicParsley::Command; | ||||||||||||||||||||
| 6 | 1 | $AtomicParsley::Command::VERSION = '1.153400'; | |||||||||||||||||||
| 7 | # ABSTRACT: Interface to the Atomic Parsley command | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use AtomicParsley::Command::Tags; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use IPC::Cmd '0.76', (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use File::Spec '3.33'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use File::Copy; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use File::Glob qw{ bsd_glob }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||||||||
| 17 | 0 | my $args = shift; | |||||||||||||||||||
| 18 | 0 | my $self = {}; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # the path to AtomicParsley | ||||||||||||||||||||
| 21 | 0 | ▶ | my $ap = $args->{'ap'} // 'AtomicParsley'; | ||||||||||||||||||
|
Condition0%0/2
$args->{"ap"} // "AtomicParsley"
MC/DC0%0/1
$args->{"ap"} // "AtomicParsley"
$args->{"ap"}
Truth table0%0/2
A
A= $args->{"ap"}
| |||||||||||||||||||||
| 22 | 0 | ▶ | $self->{'ap'} = IPC::Cmd::can_run($ap) or die "Can not run $ap"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | ▶ | $self->{'verbose'} = $args->{'verbose'} // 0; | ||||||||||||||||||
|
Condition0%0/2
$args->{"verbose"} // 0
MC/DC0%0/1
$args->{"verbose"} // 0
$args->{"verbose"}
Truth table0%0/2
A
A= $args->{"verbose"}
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | $self->{'success'} = undef; | |||||||||||||||||||
| 26 | 0 | $self->{'error_message'} = undef; | |||||||||||||||||||
| 27 | 0 | $self->{'full_buf'} = undef; | |||||||||||||||||||
| 28 | 0 | $self->{'stdout_buf'} = undef; | |||||||||||||||||||
| 29 | 0 | $self->{'stderr_buf'} = undef; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | bless( $self, $class ); | |||||||||||||||||||
| 32 | 0 | return $self; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | sub read_tags { | ||||||||||||||||||
|
Subroutine
read_tags: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 36 | 0 | my ( $self, $path ) = @_; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | $path = File::Spec->rel2abs($path); | |||||||||||||||||||
| 39 | 0 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | my $cmd = [ $self->{ap}, $path, '-t' ]; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # run the command | ||||||||||||||||||||
| 44 | 0 | $self->_run($cmd); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # parse the output and create new AtomicParsley::Command::Tags object | ||||||||||||||||||||
| 47 | 0 | my $tags = $self->_parse_tags( $self->{'stdout_buf'}[0] ); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # $tags | ||||||||||||||||||||
| 50 | 0 | return $tags; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub write_tags { | ||||||||||||||||||
|
Subroutine
write_tags: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 54 | 0 | my ( $self, $path, $tags, $replace ) = @_; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | my $cmd = [ $self->{ap}, $path, $tags->prepare ]; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | # run the command | ||||||||||||||||||||
| 61 | 0 | $self->_run($cmd); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # return the temp file | ||||||||||||||||||||
| 64 | 0 | my $tempfile = $self->_get_temp_file( $directories, $file ); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | if ($replace) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # move | ||||||||||||||||||||
| 69 | 0 | move( $tempfile, $path ); | |||||||||||||||||||
| 70 | 0 | return $path; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||
| 73 | 0 | return $tempfile; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # Run the command | ||||||||||||||||||||
| 78 | 0 | ▶ | sub _run { | ||||||||||||||||||
|
Subroutine
_run: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 79 | 0 | my ( $self, $cmd ) = @_; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | local $IPC::Cmd::ALLOW_NULL_ARGS = 1; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | ||||||||||||||||||||
| 84 | 0 | IPC::Cmd::run( command => $cmd, verbose => $self->{'verbose'} ); | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | $self->{'success'} = $success; | |||||||||||||||||||
| 87 | 0 | $self->{'error_message'} = $error_message; | |||||||||||||||||||
| 88 | 0 | $self->{'full_buf'} = $full_buf; | |||||||||||||||||||
| 89 | 0 | $self->{'stdout_buf'} = $stdout_buf; | |||||||||||||||||||
| 90 | 0 | $self->{'stderr_buf'} = $stderr_buf; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # Parse the tags from AtomicParsley's output. | ||||||||||||||||||||
| 94 | # Returns a new AtomicParsley::Command::Tags object | ||||||||||||||||||||
| 95 | 0 | ▶ | sub _parse_tags { | ||||||||||||||||||
|
Subroutine
_parse_tags: not called CC=5 SCAR=34.0
| |||||||||||||||||||||
| 96 | 0 | my ( $self, $output ) = @_; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | my %tags; | |||||||||||||||||||
| 99 | my $intag; | ||||||||||||||||||||
| 100 | 0 | for my $line ( split( /\n/, $output ) ) { | |||||||||||||||||||
| 101 | 0 | ▶ | if ( $line =~ /^Atom \"(.+)\" contains: (.*)$/ ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 102 | 0 | my $key = $1; | |||||||||||||||||||
| 103 | 0 | my $value = $2; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | given ($key) { | |||||||||||||||||||
| 106 | 0 | when (/alb$/) { | |||||||||||||||||||
| 107 | 0 | $tags{'album'} = $value; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | 0 | when ('aART') { | |||||||||||||||||||
| 110 | 0 | $tags{'albumArtist'} = $value; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | 0 | when (/ART$/) { | |||||||||||||||||||
| 113 | 0 | $tags{'artist'} = $value; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | 0 | when ('catg') { | |||||||||||||||||||
| 116 | 0 | $tags{'category'} = $value; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | 0 | when (/cmt$/) { | |||||||||||||||||||
| 119 | 0 | my $tag = 'comment'; | |||||||||||||||||||
| 120 | 0 | $intag = $tag; | |||||||||||||||||||
| 121 | 0 | $tags{$tag} = $value; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | 0 | when ('cpil') { | |||||||||||||||||||
| 124 | 0 | $tags{'compilation'} = $value; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | 0 | when ('cprt') { | |||||||||||||||||||
| 127 | 0 | my $tag = 'copyright'; | |||||||||||||||||||
| 128 | 0 | $intag = $tag; | |||||||||||||||||||
| 129 | 0 | $tags{$tag} = $value; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | 0 | when (/day$/) { | |||||||||||||||||||
| 132 | 0 | $tags{'year'} = $value; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | 0 | when ('desc') { | |||||||||||||||||||
| 135 | 0 | my $tag = 'description'; | |||||||||||||||||||
| 136 | 0 | $intag = $tag; | |||||||||||||||||||
| 137 | 0 | $tags{$tag} = $value; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | 0 | when ('ldes') { | |||||||||||||||||||
| 140 | 0 | my $tag = 'longdesc'; | |||||||||||||||||||
| 141 | 0 | $intag = $tag; | |||||||||||||||||||
| 142 | 0 | $tags{$tag} = $value; | |||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | 0 | when ('disk') { | |||||||||||||||||||
| 145 | 0 | $value =~ s/ of /\//; | |||||||||||||||||||
| 146 | 0 | $tags{'disk'} = $value; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | 0 | when (/ge?n(|re)$/) { | |||||||||||||||||||
| 149 | 0 | $tags{'genre'} = $value; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | 0 | when (/grp$/) { | |||||||||||||||||||
| 152 | 0 | $tags{'grouping'} = $value; | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | 0 | when ('keyw') { | |||||||||||||||||||
| 155 | 0 | $tags{'keyword'} = $value; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | 0 | when (/lyr$/) { | |||||||||||||||||||
| 158 | 0 | $tags{'lyrics'} = $value; | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | 0 | when (/nam$/) { | |||||||||||||||||||
| 161 | 0 | $tags{'title'} = $value; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | 0 | when ('rtng') { | |||||||||||||||||||
| 164 | 0 | $tags{'advisory'} = _get_advisory_value($value); | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | 0 | when ('stik') { | |||||||||||||||||||
| 167 | 0 | $tags{'stik'} = $value; | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | 0 | when ('tmpo') { | |||||||||||||||||||
| 170 | 0 | $tags{'bpm'} = $value; | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | 0 | when ('trkn') { | |||||||||||||||||||
| 173 | 0 | $value =~ s/ of /\//; | |||||||||||||||||||
| 174 | 0 | $tags{'tracknum'} = $value; | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | 0 | when ('tven') { | |||||||||||||||||||
| 177 | 0 | $tags{'TVEpisode'} = $value; | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | 0 | when ('tves') { | |||||||||||||||||||
| 180 | 0 | $tags{'TVEpisodeNum'} = $value; | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | 0 | when ('tvsh') { | |||||||||||||||||||
| 183 | 0 | $tags{'TVShowName'} = $value; | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | 0 | when ('tvnn') { | |||||||||||||||||||
| 186 | 0 | $tags{'TVNetwork'} = $value; | |||||||||||||||||||
| 187 | } | ||||||||||||||||||||
| 188 | 0 | when ('tvsn') { | |||||||||||||||||||
| 189 | 0 | $tags{'TVSeasonNum'} = $value; | |||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | 0 | when (/too$/) { | |||||||||||||||||||
| 192 | 0 | $tags{'encodingTool'} = $value; | |||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | 0 | when (/wrt$/) { | |||||||||||||||||||
| 195 | 0 | $tags{'composer'} = $value; | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | } | ||||||||||||||||||||
| 199 | ▶ | elsif ( $intag && defined $tags{$intag} ) { | |||||||||||||||||||
|
Condition0%0/3
$intag and defined $tags{$intag}
MC/DC0%0/2
$intag and defined $tags{$intag}
$intag
defined $tags{$intag}
Truth table0%0/3
A and B
A= $intagB= defined $tags{$intag}
| |||||||||||||||||||||
| 200 | 0 | $tags{$intag} .= "\n$line"; | |||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | } | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 0 | return AtomicParsley::Command::Tags->new(%tags); | |||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | # Try our best to get the name of the temp file. | ||||||||||||||||||||
| 208 | # Unfortunately. the temp file contains a random number, | ||||||||||||||||||||
| 209 | # so this is a best guess. | ||||||||||||||||||||
| 210 | 0 | ▶ | sub _get_temp_file { | ||||||||||||||||||
|
Subroutine
_get_temp_file: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 211 | 0 | my ( $self, $directories, $file ) = @_; | |||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | # remove suffix | ||||||||||||||||||||
| 214 | 0 | $file =~ s/(\.\w+)$/-temp-/; | |||||||||||||||||||
| 215 | 0 | my $suffix = $1; | |||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | # search directory | ||||||||||||||||||||
| 218 | 0 | for my $tempfile ( bsd_glob("$directories*$suffix") ) { | |||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | # return the first match | ||||||||||||||||||||
| 221 | 0 | ▶ | if ( $tempfile =~ /^$directories$file.*$suffix$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 222 | 0 | return $tempfile; | |||||||||||||||||||
| 223 | } | ||||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | } | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | # Get the advisory value of an mp4 file, if present. | ||||||||||||||||||||
| 228 | 0 | ▶ | sub _get_advisory_value { | ||||||||||||||||||
|
Subroutine
_get_advisory_value: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 229 | 0 | my $advisory = shift; | |||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | # TODO: check all values | ||||||||||||||||||||
| 232 | 0 | given ($advisory) { | |||||||||||||||||||
| 233 | 0 | when ('Clean Content') { | |||||||||||||||||||
| 234 | 0 | return 'clean'; | |||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | } | ||||||||||||||||||||
| 237 | } | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | 1 | 1; | |||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | __END__ | ||||||||||||||||||||