-
Notifications
You must be signed in to change notification settings - Fork 0
/
ogg2m4a
executable file
·108 lines (98 loc) · 3.05 KB
/
ogg2m4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl
# vim: set expandtab:ts=4:sw=4
# This requires neroAacEnc and neroAacTag to be in your path
use strict;
use warnings;
use encoding "utf8";
use File::Find;
use File::Spec;
use Music::Tag;
my @aacencopts = qw(-q 0.40);
my $tempfile = File::Spec->tmpdir() . "/ogg2m4a.wav.$$";
foreach (@ARGV) {
if ( -d $_ ) {
find( \&process, $_ );
}
elsif ( -f $_ ) {
convert($_);
}
}
sub process {
return unless (/.ogg$/i);
convert($File::Find::name);
}
sub convert {
my $path = shift;
unless ( -f "$path" ) {
print $path. " is not a file. Skipped!\n";
return;
}
my $oggfile = Music::Tag->new($_, { quiet => 1 }, "OGG");
return unless ( defined $oggfile );
$oggfile->get_tag;
my $out = $path;
$out =~ s/\.ogg$/.m4a/i;
if ( $out eq $_ ) {
$out .= ".m4a";
}
my @aactagopts = ();
push @aactagopts, qq{-meta:track="} . $oggfile->track . qq{"}
if ( defined $oggfile->track );
push @aactagopts, qq{-meta:totaltracks="} . $oggfile->totaltracks . qq{"}
if ( defined $oggfile->totaltracks );
push @aactagopts, qq{-meta:title="} . $oggfile->title . qq{"}
if ( defined $oggfile->title );
push @aactagopts, qq{-meta:artist="} . $oggfile->artist . qq{"}
if ( defined $oggfile->artist );
push @aactagopts, qq{-meta:album="} . $oggfile->album . qq{"}
if ( defined $oggfile->album );
push @aactagopts, qq{-meta:year="} . $oggfile->releasetime . qq{"}
if ( defined $oggfile->releasetime );
push @aactagopts, qq{-meta:comment="} . $oggfile->comment . qq{"}
if ( defined $oggfile->comment );
push @aactagopts, qq{-meta:genre="} . $oggfile->genre . qq{"}
if ( defined $oggfile->genre );
my $ifname = ( File::Spec->splitpath($_) )[2];
my $ofname = ( File::Spec->splitpath($out) )[2];
print "Decoding $ifname... ";
if ( system( 'oggdec', '-Q', $path, '-o', $tempfile ) != 0 ) {
print "\nFailed to decode $path. Skipped!\n";
unlink $tempfile
if ( -e $tempfile )
or print "Couldn't unlink $tempfile: $!";
return;
}
else {
print "Done!\n";
}
print "Encoding $ofname... ";
if (
system(
"neroAacEnc @aacencopts -if \"$tempfile\" -of \"$out\" >/dev/null 2>&1"
) != 0
)
{
print "\nFailed to encode $_. Skipped!\n";
unlink $tempfile
if ( -e $tempfile )
or print "Couldn't unlink $tempfile: $!";
return;
}
else {
print "Done!\n";
print "Tagging $ofname... ";
if ( system("neroAacTag \"$out\" @aactagopts >/dev/null 2>&1") != 0 ) {
print "\nFailed to tag $_. Skipped!\n";
unlink $out
if ( -e $out )
or print "Couldn't unlink $out: $!";
return;
}
else {
print "Done\n";
}
}
unlink $tempfile
if ( -e $tempfile )
or print "Couldn't unlink $tempfile: $!\n";
}