#!/usr/bin/perl -w -- -*-perl-*- # (c) 2004 Dj Padzensky / PadzNet, Inc. All rights reserved. # Proxy server to allow basic XM streaming service connectivity. # This proxy will allow channel selection through the XM window, but # any audio controls must be made through the Windows Media Player # window. # For more information, see the home page at # http://www.padz.net/~djpadz/xm/ use strict; use HTTP::Proxy; use HTTP::Proxy::HeaderFilter::simple; use HTTP::Proxy::BodyFilter::simple; use LWP::UserAgent; use HTTP::Request; # Upon clicking a channel, the browser will generate a request to # playerindex.jsp with the channel number and speed in the request. # This filter traps that request, makes the ASX request to XM, and # uses the media URL as a parameter to the open command, which should # open it in Windows Media Player. It also replaces the User-Agent # header for all requests, making XM believe that we're using a # compatible browser. my $reqfilter = HTTP::Proxy::HeaderFilter::simple->new( sub { my ($self, $headers, $message) = @_; $headers->header(User_Agent => "Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)"); if ($message->uri() =~ /playerindex.jsp\?ch=(\d+)\&speed=([^\&]+)/) { my $request = HTTP::Request->new("GET", "http://www.xmradio.com/xstream/service/playlist/metafile.jsp?ch=$1&speed=$2", $headers); my $ua = LWP::UserAgent->new(); my $resp = $ua->request($request); if ($resp->is_success()) { system "open $1" if $resp->content() =~ /new( sub { ${ $_[1] } =~ s/application\/x-oleobject/text\/plain/; } ); # Set up the proxy server. my $proxy = HTTP::Proxy->new(); $proxy->port(1025); $proxy->push_filter(host => 'www.xmradio.com', request => $reqfilter); $proxy->push_filter(host => 'www.xmradio.com', response => $respfilter); $proxy->start();