#!/usr/bin/perl # # rip'n'code # cd digital audio to mp3 converter by mao & the symbolic LynX # # if you're lucky this script runs without modification, # otherwise go ahead and tweak it # # tested on solaris and linux # # requires cdda2wav or cdparanoia or galette # may find lame, l3enc or bladeenc useful # also eject or cd-console # # obtain beautiful mp3 music from http://symbolic.pages.de require 'getopt.pl'; &Getopt('q'); # TUNE OPTIONS # lame: # # forget everything i say about l3enc and bladeenc in the lines below # lame is by far the better encoder of all, so use it whenever you can! # # also forget everything you heard about files with constant 128 bitrate # being close to cd quality. you should always use VBR unless you really # know what you are doing and want it that way. it also perfectly safe # to use 32 as minimum bitrate with all non-historic versions of lame. # # old lame 3.5 configuration #$lameopts = $opt_m ? '-a -m m ': '-m s '; #$lameopts .= '-c -v -b 32 -V '; #$lameopts .= $opt_q ? $opt_q : '6'; #$hqlameopts = $lameopts . ' -h'; #$lameopts = $hqlameopts if $opt_q && $opt_q < 5; # # lame 3.9 configuration # -m default: we use automatic j/s depending on bitrate #$lameopts = $opt_m ? '-da -mm ': ''; $lameopts = $opt_m ? '-mm ': ''; $lameopts .= '-v ' unless $opt_s; $lameopts .= '--nspsytune -c -V'; # the lowpass actually makes more high tones pass, since the default # lame config filters everything over 17 kHz if ($opt_q) { $lameopts .= $opt_q; if ($opt_q and $opt_q < 4) { $lameopts .= ' -q1 --lowpass 19.5'; } elsif ($opt_q and $opt_q < 7) { $lameopts .= ' -q3 --lowpass 19'; } else { $lameopts .= ' --lowpass 18'; } } else { # let's use r3mix by default! $lameopts .= '--r3mix'; # $lameopts .= '6 --lowpass 18'; } # l3enc: # # l3enc's 112k is okay for many 90s music recordings and the output files are # very small. only some sounds, mixes and vocals may be engineered in a way # that the weaknesses of mp3 appear audible to the ear. in that case you will # probably be successful if you call this program with the '-h' switch, this # will put l3enc into "high quality" mode. # # l3enc with -h takes about 3 times as much time to code, which is painstaking, # but in the end you have an extremely small file with amazing quality, # optimal for website publishing. -h seems to have more impact than just # raising the bitrate to 128k or 160k, but this differs for every music # recording, apparently. # # if you're encoding speech or things you recorded off a tv or radio, you # might want to reduce the bitrate and think of appending -dm for mono downmix. # # very high quality, very large files. #$l3encopts = '-br 192000'; # # ok quality, medium files. #$l3encopts = '-br 128000'; # # good quality, medium files. l3enc does not provide this bitrate. #$l3encopts = '-br 160000'; # # popular quality, small files. $l3encopts = ''; # # low quality and mono: extremely small files #$l3encopts = '-dm -br 64000'; # # what to do when -h is given, append l3enc's -hq flag. $hql3encopts = "$l3encopts -hq"; # bladeenc: # # to my surprise i found out that l3enc's 112 encodings usually sound better # than bladeenc's 128k encodings! so it may be stated that bladeenc is only # useful for encoding with bitrates around 256k (as the author admits in the # documentation). haven't compared l3enc's 192k quality to bladeenc's # yet, but i have tried blade's 160k against l3enc's 112k with hq. depending # on the music sometimes one or the other algorhythm will produce better # sounding files. higher bitrates are no final guarantee for higher quality, # just for higher disk space consumption. # # that's why we encode with 160k by default when using bladeenc $blencopts = '-br 160000'; # # what to do when -h is given, raise the rate to 192k $hqblencopts = '-br 192000'; # where do we put temporary files? # will default to /tmp if this directory does not exist # $tempdir = '/fat/windows/temp'; $tempdir = '/tmp' unless -d $tempdir; # # END OF TUNABLES $debug = ' - debug mode' if $opt_d; print <&1 |"); while() { print unless /\|/o; # || /^\s*$/o || /\*\*\*/o; } close E; } else { &system("$encocmd \"$src\" \"$trg.mp3\" $encopts"); } } # do disc listing or at least find out how many tracks are on it sub do_discinfo { local($loud) = @_; print <&1 |") || die "cannot execute $listcmd"; if ($listcmd =~ /galette/i) { while() { chop; s/^CDROM://o; $tracks = $1 if /^ \| +(\d+) \|/o; s/( SIZE \|)$/\1 MP3 SIZE/o; if (m/ (\d+\.\d\d) MB \|$/o) { $_ .= sprintf(' %2.2f MB', $1/12.5); } print $_,"\n" if $loud; } } elsif ($listcmd =~ /paranoia/i) { while() { $tracks = $1 if /^\s*(\d+)\.\s+\d+ \[\d+/o; print if $loud; } } elsif ($listcmd =~ /cdda2wav/i) { while() { # $tracks = $1 if /\s*(\d+)\.\(\s*\d+\)\s*$/; # $tracks = $1 if /\s*(\d+)\.\(\s*\d+\), lead-out/; $tracks = $1 if / total tracks:(\d+)\b/; $totalTime = $1 if /total time (\d+:\d\d\S*?)\b/; last if /Error/i; print if $loud; } } else { print while ; } close G; print "\n" if $loud; print <$temp; mv -f $temp $final) &"); } else { &system("$rippcmd $i >$final"); } } else { if ($temp) { &system("($rippcmd $i $temp; mv -f $temp $final) &"); } else { &system("$rippcmd $i $final"); } } } # MAIN CODE THAT SHOULDN'T NEED ANY TWEAKING $tempdir = '/tmp' unless -d $tempdir; $encowav = "$tempdir/cd2mp3-being-encoded.wav"; $rippwav = "$tempdir/cd2mp3-being-ripped.wav"; $waitwav = "$tempdir/cd2mp3-next-in-line.wav"; if ($opt_f) { print < ] X &common_options; } while (@ARGV) { my $in = shift; my $out = $in; if ($out =~ s/\.wav$//i) { print $has_lame ? "\n" : <= 0; last MODE; } if ($#ARGV < 0) { &syntax unless $opt_l || $opt_f; exit; } if ($opt_x) { $exclude = ' ' . join(' ', @ARGV) . ' '; print <" . &outputname($i) . '.wav'); &do_rip($i, &outputname($i).'.wav'); $tetime = time(); $riptime = $tetime - $trtime; printf "track $j: RipTime: $riptime secs\n"; next; } if (!$j) { if (-r $rippwav) { print < $rippwav"); &do_rip($i, $rippwav); while (-r $waitwav) { print < $rippwav;mv -f $rippwav $waitwav) &"); &do_rip($i, $waitwav, $rippwav); until (-r $waitwav) { print < quality setting for variable bitrate: 9 worst, 1 best -s(ilent) do not show encoding progress -m(ono) mono, not stereo, makes file half its usual size general options: -d(ebug) do not actually perform actions -v(erbose) show commands being executed X } sub syntax { print < ] (-a | -i | -x) [ ] commands: -a(ll) encode all tracks -i(nclude) encode only following space-seperated list of tracks -x(clude) encode all except the following space-seperated list of tracks -c(ode) encode only, see $0 -c for syntax ripper options: -l(ist) show listing of loaded disc -r(ip only) do not encode, just rip the tracks into current dir -o(ffline) do not attempt CDDB lookups -f(orce) remove temporary files, even if they are still being used -M(onitor) hear audio data as it is being ripped (cdda2wav only) -e(ject) eject disc when done (when available) -p(aranoid) use cdparanoia in paranoid ripping mode, if available X &common_options; exit; }