Add AAC and deco

This commit is contained in:
Dan Ponte 2023-01-15 12:48:53 -05:00
parent 52abe0dd3c
commit 65beb1fba6

137
mfgen.pl
View file

@ -2,12 +2,12 @@
use vars qw/ %opt /;
our @ofls;
our @fls;
our $reverse = 0;
our $ppref;
our $argc = $#ARGV + 1;
our $genre, $outfile;
our $do_ogg = 1, $do_mp3 = 0, $do_flac = 0, $do_rename = 0;
our $do_ogg = 1, $do_mp3 = 0, $do_flac = 0, $do_rename = 0, $do_aac = 0, $do_deco = 0;
our $disart, $disalb, $albdisc = 1, $yearstr, $multidisc = 0, $overart = 0, $overalb = 0;
$outfile = "Makefile";
#if($argc < 3) {
@ -19,7 +19,7 @@ $outfile = "Makefile";
#$yearstr = $ARGV[1];
sub optinit {
use Getopt::Std;
my $opts = 'y:g:mA:L:d:hp:MOFR';
my $opts = 'y:g:mA:L:d:hp:MOFRCrD';
getopts($opts, \%opt) or usage();
usage() if $opt{h};
if($opt{y}) {
@ -31,6 +31,12 @@ sub optinit {
}
$do_mp3 = 1;
}
if($opt{C}) {
if(!$opt{O}) {
$do_ogg = 0;
}
$do_aac = 1;
}
if($opt{F}) {
if(!$opt{O}) {
$do_ogg = 0;
@ -66,6 +72,13 @@ sub optinit {
if($opt{d}) {
$albdisc = $opt{d};
}
if($opt{D}) {
$do_deco = 1;
$do_ogg = 0;
}
if($opt{r}) {
$reverse = 1;
}
}
sub usage {
@ -85,9 +98,12 @@ usage: $0 [-hmMOR] [-y year] [-g genre] [-A artist] [-L album] [-d disc#] [-p pa
-M : generate MP3s (must be used with -O for MP3 and vorbis)
-O : generate Ogg Vorbis
-F : generate FLAC (must be used with -O for FLAC and vorbis, or -M)
-C : generate m4a (aac)
-D : decode FLAC to wav for cueburn
-R : Rename (actually copy) and tag MP3 (see above notes)
-r : Reverse title and artist in format (experimental)
(C)2006-2011, Dan Ponte. BSD license.
(C)2006-2023, Dan Ponte. BSD license.
EOUSAGE
exit 1;
}
@ -127,8 +143,16 @@ foreach $g (@fls) {
$tef{'title'} = askuser("title", $g);
}
push @ofls, \%tef;
} elsif($g =~ /([0-9]{1,2})( - | )(.+)\.(wav|flac|mp3)$/) {
my $artist, $album;
} elsif($g =~ /^([0-9]{1,2}-[0-9]{1,2}|[0-9]{1,2})\.{0,1} (.+) - (.+)\.(wav|flac|mp3)$/) {
my $artist, $album, $mtr = $1, $mds = 0;
my $fmt = $4, $ar, $tit;
if($reverse) {
$ar = ($overart ? $disart : $3);
$tit = $2;
} else {
$ar = ($overart ? $disart : $2);
$tit = $3;
}
if(length($disart) == 0) {
$artist = askuser("artist", $g);
} else {
@ -139,7 +163,41 @@ foreach $g (@fls) {
} else {
$album = $disalb;
}
my %tef = (file => $g, fmt => $4, artist => ($overart ? $disart : $1), album => ($overalb ? $disalb : $3), track => $1, title => $3);
if($mtr =~ /^([0-9]{1,2})-([0-9]{1,2})$/) {
$mds = $1;
$mtr = $2;
}
my %tef = (file => $g, fmt => $4, artist => $ar, album => ($overalb ? $disalb : $album), track => $mtr, title => $tit);
if($mds != 0) {
$tef{'disc'} = $mds;
}
$disart = $tef{'artist'};
$disalb = $tef{'album'};
if($tef{'title'} eq "Fillmein") {
$tef{'title'} = askuser("title", $g);
}
push @ofls, \%tef;
} elsif($g =~ /([0-9]{1,2}-[0-9]{1,2}|[0-9]{1,2})(\.? ?- ?| )(.+)\.(wav|flac|mp3)$/) {
my $artist, $album, $mtr = $1, $mds = 0;
if(length($disart) == 0) {
$artist = askuser("artist", $g);
} else {
$artist = $disart;
}
# if($mtr =~ /^([0-9]{1,2})-([0-9]{1,2})$/) {
# $mds = $1;
# $mtr = $2;
# }
if(length($disalb) == 0) {
$album = askuser("album", $g);
} else {
$album = $disalb;
}
my %tef = (file => $g, fmt => $4, artist => ($overart ? $disart : $1), album => ($overalb ? $disalb : $3), track => $mtr, title => $3);
# if($mds != 0) {
# $tef{'disc'} = $mds;
# }
$disart = $tef{'artist'};
$disalb = $tef{'album'};
if($tef{'title'} eq "Fillmein") {
@ -147,7 +205,22 @@ foreach $g (@fls) {
}
push @ofls, \%tef;
} else {
my $artist, $album, $trno, $tit;
printf("I have no clue how to deal with '%s'! Manual metadata entry required.\n", $g);
if(length($disart) == 0) {
$artist = askuser("artist", $g);
} else {
$artist = $disart;
}
if(length($disalb) == 0) {
$album = askuser("album", $g);
} else {
$album = $disalb;
}
$trno = askuser("track", $g);
$tit = askuser("title", $g);
my %tef = (file => $g, artist => ($overart ? $disart : $artist), album => ($overalb ? $disalb : $album), track => $trno, title => $tit);
push @ofls, \%tef;
}
}
@ -159,6 +232,16 @@ if(@ofls < 1) {
open(OUTFILE, ">$outfile") or die("Cannot open $outfile for writing.");
print OUTFILE "# Generated by oge.pl\n";
if($do_deco) {
printf OUTFILE "wav: ";
for($i = 0; $i < @ofls; $i++) {
printf OUTFILE ("tr%02dwav ", $i + 1);
}
printf OUTFILE ("\n");
printf OUTFILE "# wave decode stuff\n";
}
if($do_ogg) {
printf OUTFILE ("ogg: ");
@ -169,6 +252,15 @@ if($do_ogg) {
printf OUTFILE ("\n");
printf OUTFILE "# ogg stuff\n";
}
if($do_aac) {
printf OUTFILE ("aac: ");
for($i = 0; $i < @ofls; $i++) {
printf OUTFILE ("tr%02dm4a ", $i + 1);
}
printf OUTFILE "\n";
printf OUTFILE "# aac stuff\n";
}
if($do_mp3) {
printf OUTFILE ("mp3: ");
@ -208,9 +300,18 @@ foreach $h (@ofls) {
my %c = %{$h};
my ($artist, $album, $tdisc, $tr, $title) = ($c{'artist'}, $c{'album'}, $albdisc, $c{'track'}, $c{'title'});
# $tdisc =~ s/-//;
my $disc, $track, $ofn;
$disc = $albdisc;
my $disc, $track, $ofn, $odfn;
if(exists $c{'disc'}) {
$disc = $c{'disc'};
} else {
$disc = $albdisc;
}
$track = $tr;
if($do_deco) {
$odfn = $c{'file'};
$odfn =~ s:^.*/(.*)$:\1:;
$odfn =~ s/\.flac$/.wav/;
}
if($multidisc) {
$ofn = sprintf("%s - %s - %02d-%02d %s", $artist, $album, $disc, $track, $title);
} else {
@ -222,8 +323,24 @@ foreach $h (@ofls) {
$yearstr ne '' ? "-d '" . nl($yearstr) . "'" : '',
nl($genre), nl($artist), nl($title), nl($album), nl($track), nl($disc), nl($c{'file'}));
}
if($do_deco) {
printf OUTFILE ("tr%02dwav:\n\tflac -d -o '%s' '%s'\n", $i, nl(($ppref ne '' ? $ppref . '/' . $odfn : $odfn)), nl($c{'file'}));
}
if($do_aac) {
my $useflac = 0, $fapd;
if($c{'file'} =~ /.*\.flac$/) {
$useflac = 1;
$fapd = "flac -dc '" . nl($c{'file'}) . "' | ";
}
printf OUTFILE ("tr%02dm4a:\n\t%sfaac -o '%s' -w -s --artist '%s' --title '%s' --album '%s' --track '%s' --genre '%s' --disc '%s' %s '%s'\n",
$i,
($useflac ? $fapd : ''),
nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn) . ".m4a"), nl($artist) , nl($title), nl($album), nl($track), nl($genre), nl($disc),
$yearstr ne '' ? "--year '" . nl($yearstr) . "'" : '',
($useflac ? '-' : nl($c{'file'})));
}
if($do_mp3) {
printf OUTFILE ("tr%02dmp3:\n\tlame -V 2 %s --add-id3v2 --tg '%s' --ta '%s' --tt '%s' --tl '%s' --tn %d '%s' '%s'\n", $i,
printf OUTFILE ("tr%02dmp3:\n\tlame -V 3 %s --add-id3v2 --tg '%s' --ta '%s' --tt '%s' --tl '%s' --tn %d '%s' '%s'\n", $i,
$yearstr ne '' ? "--ty '" . nl($yearstr) . "'" : '',
nl($genre), nl($artist), nl($title), nl($album), nl($track), nl($c{'file'}), nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn)) . ".mp3");
if($multidisc) {