#! /usr/bin/perl ### ------------------------------------------------------------------------- ### Program: bbc.pl: ### Author : Robin Gilks ### Date : Aug 2005 ### ### This is a MythStream parser or harvester (not sure if there's a diff). ### The idea is to get the RealPlayer historic content from the various ### radio stations that the BBC runs. Most programs are available for streaming ### for up to 7 days after broadcast. ### MythStream passes in the URL which is specified in streams.res ### or the database so we get eg ### streams.res = radio/aod/networks/radio4/audiolist.shtml ### get http://www.bbc.co.uk/radio/aod/networks/radio4/audiolist.shtml ### we parse out the lines with 'bbcplayer' in them eg. ###
  • The Archers
  • ###
  • Just a Minute
  • ###
  • Afternoon Play
  • ### We keep the tag as the name and if there is anything after the ### then we use that as the description. We then pass back with a ### handler=level2 to display the list we have eg. ### ### Afternoon Play ### aod.shtml?radio4/afternoonplay ### bbc_l2 ### ### When the user selects a show we parse the page returned to ### find the 'var AudioStream = "...." url and extract it eg. ### var AudioStream = "/radio/aod/shows/rpms/radio4/archers"; ### Append '.rpm' and get that eg. ### get http://www.bbc.co.uk/radio/aod/shows/rpms/radio4/archers.rpm ### The contents of the rpm file is the rtsp url we want which ### we return!! eg. ### ### Dummy ### rtsp://rmv8.bbc.net.uk/radio4/archers/archers_mon.ra ### ### This is thankfully played immediately :-)) ### ------------------------------------------------------------------------- use English; use XML::DOM; use HTML::TokeParser; #------------------------------------------------------------------------------ # Init #------------------------------------------------------------------------------ &read_parse(); # get commandline parameters into @in $source = $in[0]; # source filename from command line my $doc = XML::DOM::Document->new; my $head = $doc->createXMLDecl ('1.0'); my $root = $doc->createElement('items'); sub newNode { local $name = shift; local $value = shift; local $node = $doc->createElement($name); local $text = $doc->createTextNode($value); $node->appendChild($text); return $node; } #------------------------------------------------------------------------------ # read file into $data #------------------------------------------------------------------------------ $datafile = $source; open( INFO, "<$datafile" ); # Open file for reading undef $/; $data = ; # Read all close(INFO) ; #------------------------------------------------------------------------------ # search url's in $data and create XML #------------------------------------------------------------------------------ my $p = HTML::TokeParser->new(\$data); while (my $token = $p->get_tag("a")) { my $url = $token->[1]{href}; my $name = $p->get_trimmed_text("/a"); my $target = $token->[1]{target}; if ($target =~ /bbcplayer/ ) { $item = $doc->createElement('item'); $root->appendChild($item); $item->appendChild( newNode('name', $name) ); $item->appendChild( newNode('url', $url ) ); $item->appendChild( newNode('handler', "bbc_l2") ); } } print $head->toString; print $root->toString; print "\n"; #-------------------------------------------------------------------------------- # get command line parameters #-------------------------------------------------------------------------------- sub read_parse { local (*in) = @_ if @_; local ($i); push(@in, @ARGV); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g;} return scalar(@in); }