Recording Audio streams and Listening to them in iTunes
We have mentioned recording XM satellite radio MP3s in the past
http://www.tiplabs.com/modules.php?name=News&file=article&sid=101
but that requires still a subscription to XM radio and the purchase of hardware.
However with the large list of internet music broadcasters out there
there is a large amount of free music for your listening pleasure. Some
folks will go and buy an expensive Denon receiver and grab those streams
and listen to them as they like. However you dont get a copy of the
songs to listen to later.
Streamripper is an open source (GPL) application that lets you record
streaming audio directly to your hard drive. It will allow you to record
streaming internet radio stations automatically and store off the title
and artist of each MP3 to your hard drive. When you come back after it
runs for hours you will see your music collection increase drastically.
If you get into this it will start to make sense to get a home NAS
eventually.
One implementation we are going to discuss here is using the linux version
of streamripper (there is a windows version) and storing off the music and
then allowing you to broadcast it to iTunes. This is something that works
well in a work environment where many folks can just start listening to
music that has been piling up overnight.
Grab a copy of Streamripper here:
http://streamripper.sourceforge.net
Next install it on your favorite linux box. One internet music streaming
location we use is Radio Paradise. Here is a sample bash script to start
it up with that radio station:
===== START CUT ======
#!/bin/bash
URL="http://www.radioparadise.com/musiclinks/rp_128.m3u"
DIR="/export/streams"
DURATION_HOURS=8
DURATION_SECS=$[60*60*$DURATION_HOURS]
MAX_MEGS=1024
streamripper $URL -d $DIR -l $DURATION_SECS -M $MAX_MEGS &
===== END CUT ======
This script will start recording all the music played from Radio Paradise
for 8 hours (good for running during the night at the office to not use
critical bandwidth during office hours). It will also store off just 1GB
of music. Simply setup a cron job to run this every night to get a nice
collection of music for everyone at the office the following day.
What you will get is in your /export/streams directory a collection of
.mp3 files with artists and title set in the tags.
This may be sufficient for most folks however we have determined that some
music we could do without and dont want it even shared. So we have
another script that runs at 7am to clean up the music directory and
deletes unwanted artists. Also it is important to note that streamripper
will put duplicates into an \'incomplete\' directory, so it is easy to
delete any duplicate songs. This script is written in perl so you may
need to install perl if you dont already have it.
===== START CUT ======
#!/usr/bin/perl
@pattern_list = (
"incomplete",
".*Beatles.*",
"Talking Heads.*",
"Ladysmith.*",
"Bering Strait.*",
"Elvis Costello.*",
"Jethro Tull.*",
);
$verbose = 1;
$debug = 0;
$dryrun = 0;
$total_dirs = 0;
$total_files = 0;
@files_to_delete = ();
if ($ARGV[0] eq "-n") {
$dryrun = 1;
}
foreach(@pattern_list) {
&delete_files($_);
}
&perform_delete if (!$dryrun);
sub delete_files {
my($pattern) = @_;
my(@filelist, @files, @dirs);
@filelist = &find_files(".", $pattern, 0);
push(@files_to_delete, @filelist);
#print "For pattern \'$pattern\' found ".@filelist." filelist:\n@filelist\n";
foreach (@filelist) {
if (-d $_) {
$total_dirs++;
push(@dirs, $_);
} else {
$total_files++;
push(@files, $_);
}
}
if ($verbose) {
print "Pattern \'$pattern\' will:\n";
print " delete ".@dirs." directories...\n" if (@dirs);
if ($verbose > 1) {
foreach (@dirs) {
print " $_\n";
}
}
print " delete ".@files." files...\n" if (@files);
if ($verbose > 1) {
foreach (@files) {
print " $_\n";
}
}
}
}
sub perform_delete {
$| = 1;
if ($verbose) {
print "Total files to delete: $total_files\n";
print "Total directories to delete: $total_dirs\n";
}
if (@files_to_delete) {
print "Deleting..." if ($verbose);
foreach (reverse sort @files_to_delete) {
if (-d $_) {
rmdir $_ or die "Couldn\'t remove directory: $_";
} else {
unlink $_ or die "Couldn\'t delete file: $_";
}
}
}
print "done!\n" if ($verbose);
}
sub find_files {
my($basedir, $pattern, $recursive) = @_;
my($entry, @entries, @subfiles);
my(@files) = ();
print "find_files($basedir, $pattern, $recursive) called\n" if $debug;
opendir THISDIR, $basedir;
@entries = grep !/^(CVS|\..*)$/, readdir THISDIR;
closedir THISDIR;
print "Found these entries @entries\n" if $debug;
foreach $entry (@entries) {
print "...checking entry \n" if $debug;
if ( $entry =~ /^$pattern$/ ) {
push(@files, $entry);
if ( -d "$basedir/$entry" ) {
@subfiles = &find_files("$basedir/$$ntry", ".*", 1);
@subfiles = map "$entry/$_", @subfiles;
print "In $basedir/$entry, found these files @subfiles\n" if $debug;
push(@files, @subfiles);
}
} elsif ( -d "$basedir/$entry" ) {
if ($recursive) {
@subfiles = &find_files("$basedir/", $pattern, $recursive);
@subfiles = map "$entry/$_", @subfiles;
print "In $basedir/$entry, found these files @subfiles\n" if $debug;
push(@files, @subfiles);
}
}
}
print "find_files($basedir, $pattern, $recursive) returned @files\n" if $debug;
return (@files);
}
===== END CUT ======
Finally now that you have your MP3s all nice in one location you setup
iTunes to share your files. Here are the steps for doing this in iTunes:
* Open iTunes preferences.
* Select the check box "Share my Music" and select a library that you
created using the directory of your streamripper songs into.
* Change the shared name to whatever you like.
* If you want to password protect the share, select "Require password" and
put in a password.
Final comments
--------------
There is also a winamp plugin for streamripper that will allow you to
store streams to file as well which is handily. Here is a tutorial on
that here:
http://streamripper.sourceforge.net/tutorialplugin.php
--> Thanks goes to topprospect for submitting this tip.
--
* Got a tip? Let us know at info@tiplabs.com.
* Not on this list and want to get on it? Send email to here:
majordomo@tiplabs.com and put "subscribe nerdlist" in body.
=============================================================
tipLabs _____====---> www.tiplabs.com <---====_____ tipLabs
=============================================================
|