Initial.
This commit is contained in:
commit
52abe0dd3c
2 changed files with 318 additions and 0 deletions
24
README
Normal file
24
README
Normal file
|
@ -0,0 +1,24 @@
|
|||
mfgen.pl - a Perl script to generate makefiles to encode audio to different formats.
|
||||
(C)2006-2011, Dan Ponte <amigan@gmail.com>
|
||||
|
||||
Rationale:
|
||||
Generating makefiles allows you to use make -j, which allows you to utilize multiple CPUs in an SMP configuration to
|
||||
encode more than one file at once.
|
||||
|
||||
Help:
|
||||
|
||||
usage: mfgen.pl [-hmMOR] [-y year] [-g genre] [-A artist] [-L album] [-d disc#] [-p path]
|
||||
|
||||
-h : this help
|
||||
-m : album is part multi disc set (writes disc in filename)
|
||||
-y year : set year for album
|
||||
-g genre : set genre for album
|
||||
-A artist : set artist for album
|
||||
-L album : set title of album
|
||||
-d disc# : set disc number (default 1)
|
||||
-p path : path prefix (where to put output files)
|
||||
-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)
|
||||
-R : Rename (actually copy) and tag MP3 (see above notes)
|
||||
|
294
mfgen.pl
Executable file
294
mfgen.pl
Executable file
|
@ -0,0 +1,294 @@
|
|||
#!/usr/bin/perl
|
||||
use vars qw/ %opt /;
|
||||
our @ofls;
|
||||
our @fls;
|
||||
our $ppref;
|
||||
our $argc = $#ARGV + 1;
|
||||
our $genre, $outfile;
|
||||
our $do_ogg = 1, $do_mp3 = 0, $do_flac = 0, $do_rename = 0;
|
||||
our $disart, $disalb, $albdisc = 1, $yearstr, $multidisc = 0, $overart = 0, $overalb = 0;
|
||||
|
||||
$outfile = "Makefile";
|
||||
|
||||
#if($argc < 3) {
|
||||
# print STDERR "Usage: $0 <genre> <yearstr>\n";
|
||||
# exit 1;
|
||||
#}
|
||||
|
||||
#$genre = $ARGV[0];
|
||||
#$yearstr = $ARGV[1];
|
||||
sub optinit {
|
||||
use Getopt::Std;
|
||||
my $opts = 'y:g:mA:L:d:hp:MOFR';
|
||||
getopts($opts, \%opt) or usage();
|
||||
usage() if $opt{h};
|
||||
if($opt{y}) {
|
||||
$yearstr = $opt{y};
|
||||
}
|
||||
if($opt{M}) {
|
||||
if(!$opt{O}) {
|
||||
$do_ogg = 0;
|
||||
}
|
||||
$do_mp3 = 1;
|
||||
}
|
||||
if($opt{F}) {
|
||||
if(!$opt{O}) {
|
||||
$do_ogg = 0;
|
||||
}
|
||||
$do_flac = 1;
|
||||
}
|
||||
if($opt{R}) {
|
||||
if(!$opt{O}) {
|
||||
$do_ogg = 0;
|
||||
}
|
||||
$do_rename = 1;
|
||||
}
|
||||
if($opt{O}) {
|
||||
$do_ogg = 1;
|
||||
}
|
||||
if($opt{g}) {
|
||||
$genre = $opt{g};
|
||||
}
|
||||
if($opt{m}) {
|
||||
$multidisc = 1;
|
||||
}
|
||||
if($opt{A}) {
|
||||
$disart = $opt{A};
|
||||
$overart = 1; # artist override
|
||||
}
|
||||
if($opt{p}) {
|
||||
$ppref = $opt{p};
|
||||
}
|
||||
if($opt{L}) {
|
||||
$disalb = $opt{L};
|
||||
$overalb = 1; # album override
|
||||
}
|
||||
if($opt{d}) {
|
||||
$albdisc = $opt{d};
|
||||
}
|
||||
}
|
||||
|
||||
sub usage {
|
||||
print STDERR <<EOUSAGE;
|
||||
$0: generates makefiles to make importating pirated music easier
|
||||
|
||||
usage: $0 [-hmMOR] [-y year] [-g genre] [-A artist] [-L album] [-d disc#] [-p path]
|
||||
|
||||
-h : this help
|
||||
-m : album is part multi disc set (writes disc in filename)
|
||||
-y year : set year for album
|
||||
-g genre : set genre for album
|
||||
-A artist : set artist for album
|
||||
-L album : set title of album
|
||||
-d disc# : set disc number (default 1)
|
||||
-p path : path prefix (where to put output files)
|
||||
-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)
|
||||
-R : Rename (actually copy) and tag MP3 (see above notes)
|
||||
|
||||
(C)2006-2011, Dan Ponte. BSD license.
|
||||
EOUSAGE
|
||||
exit 1;
|
||||
}
|
||||
|
||||
optinit();
|
||||
|
||||
|
||||
opendir(DOT, ".");
|
||||
@fls = grep {/.*\.(flac|wav|mp3)$/} readdir(DOT);
|
||||
closedir(DOT);
|
||||
|
||||
foreach $g (@fls) {
|
||||
if($g =~ /^audio_([0-9]{2})\.wav$/) {
|
||||
my $tfn = sprintf("%02d", $1);
|
||||
my %tef = newfname("audio_" . $tfn . ".inf", $g);
|
||||
$tef{'fmt'} = 'wav';
|
||||
if($overart) {
|
||||
$tef{artist} = $disart;
|
||||
} else {
|
||||
$disart = $tef{'artist'};
|
||||
}
|
||||
if($overalb) {
|
||||
$tef{album} = $disalb;
|
||||
} else {
|
||||
$disalb = $tef{'album'};
|
||||
}
|
||||
# $newf =~ s/'/'\\''/g;
|
||||
# printf OUTFILE ("mv audio_%02d.wav '%s'\n", $tfn, $newf);
|
||||
push @ofls, \%tef;
|
||||
} elsif($g =~ /^(.+) - (.+) - ([0-9]{1,2})( -|) (.*)\.(wav|flac|mp3)$/) {
|
||||
my %tef;
|
||||
printf("Guessing that artist = '%s', album = '%s', track name = '%s', num = %d for %s\n", $1, $2, $5, $3, $g);
|
||||
%tef = (file => $g, fmt => $6, artist => ($overart ? $disart : $1), album => ($overalb ? $disalb : $2), track => $3, title => $5);
|
||||
$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})( - | )(.+)\.(wav|flac|mp3)$/) {
|
||||
my $artist, $album;
|
||||
if(length($disart) == 0) {
|
||||
$artist = askuser("artist", $g);
|
||||
} else {
|
||||
$artist = $disart;
|
||||
}
|
||||
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 => $1, title => $3);
|
||||
$disart = $tef{'artist'};
|
||||
$disalb = $tef{'album'};
|
||||
if($tef{'title'} eq "Fillmein") {
|
||||
$tef{'title'} = askuser("title", $g);
|
||||
}
|
||||
push @ofls, \%tef;
|
||||
} else {
|
||||
printf("I have no clue how to deal with '%s'! Manual metadata entry required.\n", $g);
|
||||
}
|
||||
}
|
||||
|
||||
if(@ofls < 1) {
|
||||
print STDERR "There were no files to work on, dying.\n";
|
||||
exit 2;
|
||||
}
|
||||
|
||||
open(OUTFILE, ">$outfile") or die("Cannot open $outfile for writing.");
|
||||
|
||||
print OUTFILE "# Generated by oge.pl\n";
|
||||
|
||||
if($do_ogg) {
|
||||
printf OUTFILE ("ogg: ");
|
||||
|
||||
for($i = 0; $i < @ofls; $i++) {
|
||||
printf OUTFILE ("tr%02dogg ", $i + 1);
|
||||
}
|
||||
printf OUTFILE ("\n");
|
||||
printf OUTFILE "# ogg stuff\n";
|
||||
}
|
||||
|
||||
if($do_mp3) {
|
||||
printf OUTFILE ("mp3: ");
|
||||
|
||||
for($i = 0; $i < @ofls; $i++) {
|
||||
printf OUTFILE ("tr%02dmp3 ", $i + 1);
|
||||
}
|
||||
printf OUTFILE ("\n");
|
||||
printf OUTFILE "# mp3 stuff\n";
|
||||
}
|
||||
|
||||
if($do_flac) {
|
||||
printf OUTFILE ("flac: ");
|
||||
|
||||
for($i = 0; $i < @ofls; $i++) {
|
||||
printf OUTFILE ("tr%02dflac ", $i + 1);
|
||||
}
|
||||
printf OUTFILE ("\n");
|
||||
printf OUTFILE "# flac stuff\n";
|
||||
}
|
||||
|
||||
if($do_rename) {
|
||||
printf OUTFILE ("rename: ");
|
||||
for($i = 0; $i < @ofls; $i++) {
|
||||
printf OUTFILE ("tr%02dren ", $i + 1);
|
||||
}
|
||||
printf OUTFILE ("\n");
|
||||
printf OUTFILE ("# rename stuff\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
$i = 1;
|
||||
|
||||
foreach $h (@ofls) {
|
||||
# $c =~ s/'/'\\''/g;
|
||||
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;
|
||||
$track = $tr;
|
||||
if($multidisc) {
|
||||
$ofn = sprintf("%s - %s - %02d-%02d %s", $artist, $album, $disc, $track, $title);
|
||||
} else {
|
||||
$ofn = sprintf("%s - %s - %02d %s", $artist, $album, $track, $title);
|
||||
}
|
||||
$ofn =~ s/\//-/g;
|
||||
if($do_ogg) {
|
||||
printf OUTFILE ("tr%02dogg:\n\toggenc -q 6 -o '%s' %s -G '%s' -a '%s' -t '%s' -l '%s' -N %d -c 'DISCNUMBER=%d' '%s'\n", $i, nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn) . ".ogg"),
|
||||
$yearstr ne '' ? "-d '" . nl($yearstr) . "'" : '',
|
||||
nl($genre), nl($artist), nl($title), nl($album), nl($track), nl($disc), 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,
|
||||
$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) {
|
||||
printf OUTFILE ("\tid3v2 --TPOS '%d' '%s'\n", nl($disc), nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn)) . ".mp3");
|
||||
}
|
||||
}
|
||||
if($do_rename) {
|
||||
my $tfpath = nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn)) . ".mp3";
|
||||
printf OUTFILE ("tr%02dren:\n\tcp -v '%s' '%s'\n\tid3tag -a '%s' -A '%s' -s '%s' -t '%s' %s '%s'\n"
|
||||
, $i, nl($c{'file'}), $tfpath, nl($artist), nl($album), nl($title), nl($track),
|
||||
$yearstr ne '' ? "-y '" . nl($yearstr) . "'" : '', $tfpath);
|
||||
if($multidisc) {
|
||||
printf OUTFILE ("\tid2v2 --TPOS '%d' '%s'\n", nl($disc), $tfpath);
|
||||
}
|
||||
}
|
||||
if($do_flac) {
|
||||
printf OUTFILE ("tr%02dflac:\n\tflac --best --replay-gain %s -T 'genre=%s' -T 'artist=%s' -T 'title=%s' -T 'album=%s' -T 'track=%d' -T 'TRACKNUMBER=%d' -T 'DISCNUMBER=%d' -o '%s' '%s'\n", $i,
|
||||
$yearstr ne '' ? "-T 'year=" . nl($yearstr) . "'" : '',
|
||||
nl($genre), nl($artist), nl($title), nl($album), nl($track), nl($track), nl($disc), nl(($ppref ne '' ? $ppref . '/' . $ofn : $ofn)) . ".flac", nl($c{'file'}));
|
||||
}
|
||||
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
close OUTFILE;
|
||||
print "Done! Saved to $outfile\n";
|
||||
|
||||
sub nl { #normalise for shell
|
||||
my $c = shift;
|
||||
$c =~ s/'/'\\''/g;
|
||||
return $c;
|
||||
}
|
||||
|
||||
sub newfname {
|
||||
my $ofn = shift;
|
||||
my $srcf = shift;
|
||||
open(INF, $ofn);
|
||||
my $artist, $album, $title, $tracknum, $ctn;
|
||||
my %tds;
|
||||
foreach $cl (<INF>) {
|
||||
if($cl =~ /^Performer=\s*'(.+)'$/) {
|
||||
$artist = $1;
|
||||
} elsif($cl =~ /^Albumtitle=\s*'(.+)'$/) {
|
||||
$album = $1;
|
||||
} elsif($cl =~ /^Tracktitle=\s*'(.+)'$/) {
|
||||
$title = $1;
|
||||
} elsif($cl =~ /^Tracknumber=\s*([0-9]+)$/) {
|
||||
$tracknum = $1;
|
||||
}
|
||||
}
|
||||
|
||||
close(INF);
|
||||
|
||||
%tds = (file => $srcf, artist => $artist, album => $album, track => $tracknum, title => $title);
|
||||
return %tds;
|
||||
}
|
||||
|
||||
sub askuser {
|
||||
my $field = shift;
|
||||
my $fn = shift;
|
||||
my $answer;
|
||||
|
||||
printf("What is the %s for '%s'?> ", $field, $fn);
|
||||
$answer = <>;
|
||||
chop $answer; # newline
|
||||
return $answer;
|
||||
}
|
Loading…
Reference in a new issue