I've had a perl script located at http://ordorica.org/tune.pl that can get a Clear Channel stream, like KFI 640AM, and send you the .asx file for streaming. This way I can avoid Clear Channel websites which want to show ads during the stream, and also use a different audio player that supports windows media format.
They recently made an update to their website so the web based player now authenticates with javascript instead of just using HTML. So today I worked on updating my tune.pl code to support their new contrived authentication and "station id."
To use the script, just provide the channel's website. For example:
http://ordorica.org/tune.pl?station=kfi640
http://ordorica.org/tune.pl?station=kiisfm
The script returns an asx stream, which works with VLC, foobar with mslive plugin, and others.
You can get the script here:
Updates: 1/9/2010 - Many improvements to the script, which I have detailed in the script itself.
#!/usr/bin/perl
# Genasx Grabber
# Grabs the asx file from the auth-encoded ClearChannel radio stream.
# by hector@ucsd.edu, Licensed under GPL 3
# Why?
#
# So you can listen to ClearChannel radio streams without using CC radio's
# flash player. It seems ClearChannel usually supports this for people who have
# players without flash, or various operating systems. Sometimes CC breaks this
# method by not offering any asx stream and using their flash rtmp protocol,
# but usually it starts working again.
# Version 0.9: Remove extra whitespace around generated asx
# Version 0.8: Clean up ClearChannel's asx to be more standards compliant (to work with foobar2000 v. 1.0)
# Version 0.7: Add in URL redirection option for players that support it
# Version 0.6: Added lots of commented debugging to print to terminal
# Version 0.5: Format change by clearchannel, fix the script
# Version 0.4: Speed up using better regex's
# Version 0.3: Clean up the perl code
# Version 0.2: Port to perl to work anywhere
# Version 0.1: Initial implementation as a bash script
# GPL3 Notice
# -----------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use LWP::Simple qw(!head);
use CGI qw(:standard);
#the call paramater in the command line, #tune.pl station=kfi640 in a terminal, or tune.pl?station= on a website
my($station) = param('station');
#print a blank page if the station param isn't given
print "Content-type: text/htmlnn" if(! $station);
#so far all ClearChannel streams seem to be .com
$content = get("http://www.$station.com/cc-common/ondemand/player2.html?world=st");
die "Couldn't get it@!" unless defined $content;
#find the streaming_token line, and match the token into variable $1 and the stream_id into $2
if($content =~ m/streaming_token = '(w+)'.*'(d+)'/) {
#the token has an extra character at the beginning, remove this character
$token = substr $1, 1;
$station_id = $2;
$content = get("http://www.$station.com/cc-common/universal_player/services/1_4_1_4/getstationlist2.php?dontcacheme=1&site_id=$station_id");
die "Couldn't get the station id!" unless defined $content;
#extract the station id
if($content =~ m/stream_id" : (d+)/) {
$station_id = $1;
}
#print our genasx call in the terminal for debuging
#print "nOur HTTP request (returns asx): nn http://www.$station.com/cc-common/universal_player/services/genasx.php?ua=$token&id=$station_idn";
#now get the asx file
$asx = get("http://www.$station.com/cc-common/universal_player/services/genasx.php?ua=$token&id=$station_id");
# global lookup hash
my %ESCAPES = (
'&' => '&',
'<' => '<',
'>' => '>',
'"' => '"',
);
# xml encoding subroutine
sub xml_encode {
my ($str) = @_;
#original string: $str =~ s/([&<>"])/$ESCAPES{$1}/ge;
$str =~ s/([&])/$ESCAPES{$1}/ge;
return $str;
}
#clean up the asx to be more standards compliant
$asx = xml_encode($asx);
#clean up leading and trailing whitespace
$asx =~ s/^s+//;
$asx =~ s/s+$//;
#create the asx with type asf.
open (MYFILE, '>tune.asx');
print MYFILE $asx;
close (MYFILE);
#debug to console
#print "Location: $1nn";
#302 redirect
#the location of your generated tune.asx. Usually the same as this file.
#my $URL = "http://ordorica.org/tune.asx";
#redirect the player to tune.asx. I have to do this because my webserver doesn't allow me to use
#.asx as a cgi program. If your's does, then you can simply use tune.asx as the script by
#uncommenting the text below. Then you have to comment out the above .asx file creator.
#
#print "Status: 302 MovednLocation: $URLnn";
#301 redirect
#$q = new CGI;
#print $q->redirect("http://ordorica.org/tune.asx");
#print "Content-Type: video/x-ms-as; charset=iso-8859-1nn";
#print "Content-Type: video/x-ms-asnn";
#print the asx to the browser/music player
print<
Although not exactly the same, the following PHP script spits out the ASX of a streaming Clear Channel station, requiring just the path to the "cc-common" directory (in case they have their player in a non-standard spot and just the first part of the domain doesn't do the trick, like in yours.
I found your page on Google, only after I created mine already, so I figured I'd share the wealth:
PHP Clear Channel Streaming Radio ASX Grabber
Posted by: Anonymous on Friday May 15th, 2009 4:49 pm
EditWow, cool! I just knew something like this had to be available and I would find a solution if I searched hard enough. After my local ClearChannel affiliate quit broadcasting "Coast to Coast AM", I began to listen online. But then my computer broke and I decided to buy a Mac because Vista is so buggy and unstable. It got to the point where I could not even add or remove Windows components without an error. This is a widespread problem but Microsoft does not know any solution besides reinstalling the OS (and all of your applications). Since nobody knows what causes this problem, I was not about to risk having to go through that nightmare again. I paid for this crappy version of Windows when I bought the computer and here they were asking me to pay for it again with the replacement PC. I wanted Linux, but that was not an option. PC manufacturers are just forcing people to buy Windows regardless of whether you want it or not... and now they want to screw me over again. As the old saying goes, "fool me once, shame on you--fool me twice, shame on me". No way am I going to pay twice for something I did not want in the first place. So as I was saying, I bought a Mac. I don't think you should have to buy a Mac to get Mac OS, but that's beside the point. I simply wanted a Unix-type OS that was stable and reliable. I chose the Mac Mini because it is 10 times more power efficient than many PC's. So here's where your project comes into the picture: Those ClearChannel streams with DRM keys just don't play on my Mac. Oh yeah, I know about Flip4mac and all of that--but even this doesn't work reliably in Safari or Firefox. I know it's supposed to, but for whatever reason it doesn't... and I don't have the time to troubleshoot it right now. I want something that just works, and your script does the job. It's not an elegant or long-term solution to the problem, but it's far better than no solution. I hope at some point this functionality will be integrated into VLC, or a QuickTime plugin will materialize... but if ClearChannel really cared about doing things right they would not use this proprietary Microsoft streaming crap, they would use an open standard that works on any computer. I really don't care whether I hear the extra internet advertising when the stream launches or not, I just want to be able to hear the show and right now I can NOT hear the show by using their stupid mandatory browser plug-in. I would also like to record a show but I will never pay ClearChannel a fee for that (i.e. StreamLink). It's just wrong to charge people money to hear the show simply because they sleep at night. If I want to record the stream and play it later, I should be allowed to do so. Furthermore, I recently picked up an older Mac that runs OS 9, to use as an audio server in my home. This way I don't miss anything if I need to restart my work computer. It turns on at the appropriate time, launches a media player, and starts playing the shows I want to hear. After the show is over, the computer turns itself off. I can use iTunes or Audion in this configuration but of course they cannot play these infernal ClearChannel streams with DRM authorization keys that change every 15 minutes... and none of the browsers available for OS 9 can play this stream either. So if it's not possible to play the stream in an external media player, it's not possible to play the stream at all. By using proprietary Microsoft streams which require a browser plug-in, ClearChannel is alienating millions of listeners with old and new computers alike, and various mobile devices too. The browser plug-in just doesn't work on my computers, and I know I am not alone, but no way am I ever going back to Windows; it's just too much work to maintain. What ClearChannel does not seem to grasp is that if I cannot use an external player I will not be able to listen. Instead of giving them the finger, by writing these scripts you guys are doing them a favor. ;-) But anyway, I just figured you might want to know who needs this script and why... and I wanted to say Muchas Gracias. There are many people with dedicated WiFi radios who could probably use this too. I imagine the script could even be hosted on a home router; especially on equipment which runs open firmware like DD-WRT. Obviously then, people would not have to rely on some external server for this trick to work--and from the standpoint of reliability that is even more appealing.
Posted by: Anonymous on Wednesday July 15th, 2009 4:40 am
EditFYI: It appears that cookies must be enabled for the anti-bot code to work; it should say so below the image.
Posted by: Anonymous on Wednesday July 15th, 2009 4:51 am
EditIt appears KFI switched to streaming using the rtmp protocol, using a flash only interface. They removed their mms stream recently, so my script doesn't work for KFI. However, other clearchannel sites still work. I will try to hack together a new script, but it will require a player that supports the rtmp format, a flash format.
Posted by: Anonymous on Wednesday July 29th, 2009 11:02 am
EditWell, I just tried my script again, 10/12/2009, and KFI now works again. Perhaps it was a temporary problem on their end, or they decided to re-enable the asx stream.
Posted by: Anonymous on Monday October 12th, 2009 7:45 pm
EditCould you help me. The problem with people who have no vices is that generally you can be pretty sure they're going to have some pretty annoying virtues. Help me! Can not find sites on the: Graduate student health insurance. I found only this - health insurance online. The one can exceed this insurance on bizarre language and for bill, health insurance. Health insurance, this is because rights gotten outside the authority may be cured to above systems. THX :rolleyes:, Rhiannon from Spain.
Posted by: Anonymous on Saturday February 20th, 2010 5:17 pm
Edit