#! /usr/bin/perl # created by Daniel R. Anderson (2005) # trompelamort KOALA gmail.com =~ s/marsupial/@/; # this code protected under the GPL use strict; use warnings; # VARIABLES # these variables are needed to process the files my $filelist = shift @ARGV; my $genre = shift @ARGV; my $artist = shift @ARGV; my $album = shift @ARGV; my $encoding = (shift (@ARGV)) || "mp3"; # quality for the ogg encoder on a scale of 1 to 10 # 10 being best my $ogg_quality = 10; # quality for the mp3 encoder (lame) on a scale of 0 to 9 # 0 being the best # a quick and dirty test says that you do not want to use 0 # a 9 seems to be CD quality sound # since you can't get better than CD quality sound # stick with the 9 my $mp3_quality = 9; # shall we print debug messages? my $debug = 1; #error checking unless ($filelist and $artist and $album) { die ("Usage: ./ogger.pl filelist artist album\n"); } elsif (not (-e $filelist)) { die ("Filename $filelist does not exist!\n"); } elsif (not (-r $filelist)) { die ("We do not have sufficient permission to read $filelist\n"); } print "Using $filelist as file list.\n"; # open the file list for reading open ("FILELIST", "< ./$filelist") or die ("Cannot open $filelist because $!\n"); # grab all the filenames my @filenames = ; if ($debug) { print "DEBUG INFO:\n\n"; print "filenames:\n"; my @filecopy = @filenames; while (@filecopy) { print (shift @filecopy); } } # my $filename = ; # while ($filename) { # $filename = chomp $filename; # print "filename $filename\n"; # if ($filename) { # push @filenames, $filename; # } # $filename = # } # clean up our mess close (FILELIST) or die ("Cannot close FILELIST due to $!\n"); # we've got the filenames, set up the encodings my $encoder = ""; my $switches = ""; # set up the data we need to encode the files if ($encoding eq "ogg") { # encode the wav files using the Ogg Vorbis encoding $encoder = "oggenc"; $switches = "--genre \"$genre\" --tracknum \"??track??\" --title \"??trackname??\"" . " --album \"$album\" --artist \"$artist\" --quality=$ogg_quality -o \"??output_file??.ogg\" " . "\"??input_file??\""; } elsif ($encoding eq "mp3") { # encode the wav files using the mp3 encoding # make use of LAME # first convert the quality from oggenc to lame $encoder = "lame"; $switches = "-q $mp3_quality \"??input_file??\" \"??output_file??.mp3\" "; } else { die ("We should never get here!"); } unless ($encoder) { die ("No encoder specified!\n"); } elsif (not $switches) { die ("No switches specified!\n"); } if ($debug) { print "DEBUG INFO\n\n"; print "Encoder: $encoder\n"; print "Switches: $switches\n\n"; } my $counter = 1; while (@filenames) { my $filename = shift (@filenames); chomp $filename; next unless $filename; print "Encoding filename $filename\n"; my $tempcounter = $counter; if ($counter < 10) { $tempcounter = '0' . $counter; } my $input_file = "track" . $tempcounter . ".cdda.wav"; my $output_file = $tempcounter . ". $artist -- $album -- $filename"; # although an array/while-loop may seem superfluous, # it is important because it allows for multiple # commands... i.e. encode this file # then move it to a prespecified directory. my @to_execute = ( "$encoder $switches", ); while (@to_execute) { my $execute_me = shift (@to_execute); $execute_me =~ s[\?\?output_file\?\?][$output_file]; $execute_me =~ s[\?\?input_file\?\?][$input_file]; $execute_me =~ s[\?\?track\?\?][$tempcounter]; $execute_me =~ s[\?\?trackname\?\?][$filename]; next unless $execute_me; if ($debug) { print "DEBUG INFO:\n\n"; print "Executing command:\n$execute_me\n\n"; } `$execute_me`; } $counter++; }