#! /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 = <FILELIST>; if ($debug) { print "DEBUG INFO:\n\n"; print "filenames:\n"; my @filecopy = @filenames; while (@filecopy) { print (shift @filecopy); } } # my $filename = <FILELIST>; # while ($filename) { # $filename = chomp $filename; # print "filename $filename\n"; # if ($filename) { # push @filenames, $filename; # } # $filename = <FILELIST> # } # 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_quali +ty -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??.mp +3\" "; } 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 -- $filenam +e"; # 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++; }

In reply to Automatically Encode Ogg / MP3s by Vautrin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.