#!/usr/bin/perl -w ################################################## use strict ; use Getopt::Std ; use LWP::UserAgent ; my ( %option ) ; getopts("pvhnaQ", \%option) ; if ($option{h}) { exec("perldoc " . $0) ; # exec terminates this script } else { while (@ARGV) { my $url = shift(@ARGV); my @mplayer = mplayer_command($url); run_command(@mplayer); if ($option{a}) { my @normalize = normalize_command(@mplayer); run_command(@normalize); } my @lame = lame_command(@mplayer); run_command(@lame); } } ################################################## ##### END MAIN ################################################## sub mplayer_command { my $url = $_[0]; my $filename = time() ; if ($url =~ /([^\/]+)$/) { $filename = $1 . "_" .$filename ; } $filename .= ".wav" ; my @command = ("mplayer", "-noconsolecontrols", "-ao", "pcm:file=" . $filename); push(@command, "-really-quiet") unless ($option{Q}); if ( ($option{p}) || ($url =~ /\.r[ap]m$/) ) { push(@command, "-playlist"); } push(@command, $url ); return @command ; } sub lame_command { my $input = "@_" ; print ("lame <- $input\n") if ($option{v}) ; my @command = ("echo", "\'no wav found\'") ; if ( $input =~ /=(\S+)(\.wav)/ ) { my $wav_file = $1 . $2 ; my $mp3_file = $1 . ".mp3" ; @command = ("lame", "--quiet", $wav_file, $mp3_file) ; } return @command ; } sub normalize_command { my $input = "@_" ; print ("normalize <- $input\n") if ($option{v}) ; my @command = ("echo", "\'no wav found\'") ; if ( $input =~ /=(\S+)(\.wav)/ ) { my $wav_file = $1 . $2 ; @command = ("normalize-audio", "-a", "20dB", $wav_file) ; } return @command ; } sub run_command { my @command = @_; print("CMD: @command\n"); system(@command) unless ($option{n}); } ################################################## ##### DOCUMENTATION ################################################## =head1 Options =over =item -h Print this help and quit. =item -v Increase verbosity. =item -a Normalize to -20dB. =item -p Force mplayer '-playlist' option (automatically used for *.ram and *.rpm files). =item -Q Don't add '-really-quiet' option to mplayer. =item -n Dry run. =back =cut ######################################################################