[ubuntu-uk] Recording web audio in Dapper
Adam Funk
a24061 at yahoo.com
Mon Sep 18 08:26:29 BST 2006
On 2006-09-17, Llywelyn Owen <linux at spamtracker.co.uk> wrote:
> Whilst I'm in a enquiring frame of mind, how easy is it to record to
> mp3/ogg/other some web streamed audio. I am thinking specifically of BBC
> programs which don't seem to have a download option, just a stream option. I
> used to use Total Recorder under windows, and would love to find a similar
> app in linux. TR used to intercept the stream before the audio card so was
> able to record anything that was heard on the PC speakers.
Here's a script I've "developed" and used for recording RealPlayer
URLs. I'm open to comments (good, bad or ugly).
Requires: perl, mplayer, lame
##################################################
#!/usr/bin/perl -w
use strict ;
use Getopt::Std ;
use LWP::UserAgent ;
my ( %option ) ;
getopts("pvhna", \%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 .= ".wav" ;
my $command = "mplayer -noconsolecontrols -really-quiet -ao pcm:file=" . $filename ;
if ( ($option{p}) || ($url =~ /\.r[ap]m$/) ) {
$command .= " -playlist ";
}
$command .= " \'" . $url . "\'" ;
return $command ;
}
sub lame_command {
my $input = $_[0] ;
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 = $_[0] ;
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 = $_[0];
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 -n
Dry run.
=back
=cut
######################################################################
More information about the ubuntu-uk
mailing list