PDA

View Full Version : Recording Live Streams onto Mp3


Undesired Walrus
21st July 2008, 07:36 AM
Listening to live radio stations, I wish to record a few of them for future listens.

I am not good with computers, so any help would be appreciated (The more layman the better).

Wudang
21st July 2008, 08:10 AM
http://radio.about.com/od/softwareplayerstolisten/gr/blFrecordTool.htm

Not tried it but looks simple enough.

bokonon
24th July 2008, 09:53 AM
Audacity will record whatever the sound card's playing. You can go here (http://audacity.sourceforge.net/download/windows) to get the Windows installer for it, and a link to the encoder which enables it to export MP3 files.

Dave_46
24th July 2008, 10:19 AM
I bought a copy of Audio Cleaning Lab years ago to transfer audio from vinyl. I use it most of the time now to record internet streams. My version is 3, I think its up to 12 now. I am happy with using it.

Dave

wuschel
25th July 2008, 05:42 PM
Google: "CastRipper". The advantage over the other proposed solutions is that it does not rely on your soundcard at all and avoids having to re-encode the originally encoded stream, which frequently means a loss in audio quality.

Plus, you can rip multiple streams in parallel.

Plus, it can auto-split the stream into individual songs with the proper ID3 tags added if the station changes the stream title along with the song (works only "somewhat")

jj
25th July 2008, 05:55 PM
Whoa there, now, that's not a good idea.

The station is most likely encoded with something to start with. SAVE IT IN THE DOWNLOADED FORMAT before conversion to PCM. You do NOT NOT NOT NOT NOT want to decode/recode the signal.

Every decode/recode makes it sound worse. OFten for low rates, much, much worse.

For more information than you possibly wanted in your life on how it works, (as opposed to how you might do it, sorry), see http://www.aes.org/sections/pnw/ppt/other/perceptual_coding.ppt

For a distinct statement to "don't do that", please see slide 97 of that presentation, followed by slide 98

wuschel
26th July 2008, 06:56 AM
Whoa there, now, that's not a good idea.
Was that a reply to _my_ post and - if so - how does essentially re-stating what I wrote about transcoding make what I wrote "not a good idea"?

BenBurch
26th July 2008, 07:25 PM
I do this semi-professionally.

On the Mac, I recommend "Audio Hijack Pro" from http://www.rogueamoeba.com

On the PC, I recommend "Total Recorder Pro" from http://www.highcriteria.com

jj
26th July 2008, 11:41 PM
Was that a reply to _my_ post and - if so - how does essentially re-stating what I wrote about transcoding make what I wrote "not a good idea"?

Eh?

It's a reply to the OP.

wuschel
27th July 2008, 05:49 AM
It's a reply to the OP.
Considering the sequence and timing involved (your post showed up only minutes after mine and even contained an edit, so you must have seen mine, this wasn't particularly obvious, but thanks for clearing it up!

But as a reply to the OP IMHO it makes no sense either, since the MP3 format is not exactly "uncommon" for internet radio streams.

So, how does saving a stream as MP3 necessarily imply transcoding? To the degree of it (=saving as mp3) being "not a good idea"?

BenBurch
27th July 2008, 09:10 AM
This perl script will do an OK job of capturing an MP3 stream. Its not perfect, just a quick hack;


#!/usr/bin/perl

# socket based hypertext version of UNIX cat


use strict;
use Socket; # include Socket module

use vars qw( $time $in_time $url $out $verbose);
no strict 'refs';
use Getopt::Long;
#my $in_time = time;
#$in_time += 20;

#### Main

# parse command line arguments
#getopts('hHrdt');

# print out usage if needed
#if (defined $opt_h || $#ARGV<0) { help(); }


# if it wasn't an option, it was a URL
#while($_ = shift @ARGV) {
# hcat($_, $opt_r, $opt_H, $opt_d);
#}

GetOptions (
'url=s' => \$url,
'time=s' => \$in_time,
'out=s' => \$out,
# 'verbose' => \$verbose;
);

help() if !defined $url or !defined $in_time or !defined $out;

hcat ($url, $in_time, $out);

#####

# Subroutine to print out usage information


sub usage {
print "usage: $0 --url=... --time=... --out=...\n";
print " --url=http://some_valid_url\n";
print " --time=some integer (minutes)\n";
print " --out=/path-to/output_filename\n";
print " --verbose\n";
exit(-1);
}


# Subroutine to print out help text along with usage information


sub help {
print "Get MP3 help\n\n";
print "Based on hcat (Hypertext cat) from the O'REILLY Web Clients book,\n";
print "this simple program gets the data stream from a remote web server\n";
print "for a period of time and writes it to a file. \n";
print "It takes arguments --url, --time --out.\n\n";


usage();
}


# Given a URL, print out the data there


sub hcat {

my ($full_url, $time_stop, $out_name)=@_;

my $start_time;

if ( -e $out_name ) {
my ($base_name, $base_path, $file, $ext);
$base_name = $2, $base_path = $1 if $out_name =~ /(.*)\/([\w\.\_\-]+)$/;

if ( $base_name =~ /(.*)\.(.*)/ ) {
$file = $1;
$ext = $2;
}
else {
$file = $base_name;
}

my $counter = 1;
while ( -e $out_name ) {
$out_name = "$base_path/$file-$counter.$ext" if defined $ext;
$out_name = "$base_path/$file-$counter" if ! defined $ext;
$counter++;
}
print "\nWill write to $out_name\n";
}

open OUT, ">$out_name" or die "$!: $out_name";
binmode OUT;

# if the URL isn't a full URL, assume that it is a http request
$full_url="http://$full_url" if ($full_url !~
m/(\w+):\/\/([^\/:]+)(:\d*)?([^#]*)/);

# break up URL into meaningful parts
my @the_url = parse_URL($full_url);
if (!defined @the_url) {
print "Please use fully qualified valid URL\n";
exit(-1);
}

# we're only interested in HTTP URL's
return if ($the_url[0] !~ m/http/i);

# connect to server specified in 1st parameter
if (!defined open_TCP('F', $the_url[1], $the_url[2])) {
print "Error connecting to web server: $the_url[1]\n";
exit(-1);
}

else {
$time_stop = $time_stop * 60;
$time_stop += time;
}

# request the path of the document to get
print F "GET $the_url[3] HTTP/1.0\n";
print F "Accept: */*\n";
print F "User-Agent: funGetter/1.0\n\n";

# skip the header data
my $the_response=<F>;

if ( $the_response !~ /200/) {
print "Server said: \"$the_response\" for $full_url\nQuitting\n\n";
exit;
}

while ( <F> =~ m/^(\S+):\s+(.+)/ ) {
next;
}

# get the entity body
while ( <F> ) {
print OUT $_;
$time = time;
last if $time > $time_stop;
}


# close the network connection
close(F);
close(OUT);
}



sub open_TCP
{
# get parameters
my ($FS, $dest, $port) = @_;

my $proto = getprotobyname('tcp');
socket($FS, PF_INET, SOCK_STREAM, $proto);
my $sin = sockaddr_in($port,inet_aton($dest));
connect($FS,$sin) || return undef;

my $old_fh = select($FS);
$| = 1; # don't buffer output
select($old_fh);
1;
}


sub parse_URL {

# put URL into variable
my ($URL) = @_;

# attempt to parse. Return undef if it didn't parse.
(my @parsed =$URL =~ m@(\w+)://([^/:]+)(:\d*)?([^#]*)@) || return undef;

# remove colon from port number, even if it wasn't specified in the URL
if (defined $parsed[2]) {
$parsed[2]=~ s/^://;
}

# the path is "/" if one wasn't specified
$parsed[3]='/' if ($parsed[0]=~/http/i && (length $parsed[3])==0);

# if port number was specified, we're done
return @parsed if (defined $parsed[2]);

# otherwise, assume port 80, and then we're done.
$parsed[2] = 80;

@parsed;
}


1;



example usage;

/usr/local/bin/hcat --url=server2.whiterosesociety.org:8000/HeadOnRadio --time=122 --out="/home/dburch/currentSC.mp3"

And normally, you would embed it into a crontab;

00 20 * * 1-5 /usr/local/bin/hcat --url=server2.whiterosesociety.org:8000/HeadOnRadio --time=122 --out="/home/dburch/currentSC.mp3"

Which would run it every weekday (1-5) at 8 PM (20)