I wanted to listen to some Internode radio stations today but was annoyed that they serve each radio station up as a .pls with no Title in it, so you have to manually add each radio station.
So, I wrote this quick hacky script to download the entire list of radio stations and output a formatted .pls file that will add them all in one go.
Instructions
You will need to use the Terminal, here.
1. Copy this script to a file, called "downloadPlaylist.pl". Just cut and paste it into a textedit document, and save as plain text.
2. Mark the script as executable with
chmod u+x downloadPlaylist.pl. You will need to cd to the directory that you saved the script.
3. Run the script with
./downloadPlaylist.pl. It will print some output while it's processing to show you it's progress.
4. It will have created an InternodeRadio.pls file in the same directory. You can now just drag this file into iTunes and it will create an entry for each of Internode's radio stations.
If Internode update their webpage, you should just rerun the script and it'll grab the latest stations. If they at some point change their HTML formatting, then it will break. But it was a 5 minute script.
Code:
#!/usr/bin/perl -w
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
use strict;
my $html = `curl -sL http://www.internode.on.net/residential/entertainment/broadband_radio/`;
my $title = "";
my $url = "";
my $output = "";
my $count = 1;
my @list = split "\n", $html;
foreach (@list) {
if (/warning\(\);\"><b>(.*)<\/b>/) {
$title = $1;
}
if (/<strong><a href='(.*)'>Listen<\/a><\/strong>/ && $title ne "") {
$url = `curl -sL $1`;
$output .= "File$count=$url\nTitle=$title\n\n";
print STDERR "$title - $url\n";
$title = "";
$count++;
}
}
open OUTPUT, ">InternodeRadio.pls";
print OUTPUT "[playlist]\nNumberOfEntries=$count\n\n$output";
print OUTPUT "Version=2\n";
close OUTPUT;
print STDERR "Done!\n";