#!/usr/bin/perl -w # # tiny browser for podcasts/RSS # # Copyright Jeff R. Allen # Licensed under the Artistic License use LWP::Simple qw(!head); use CGI qw(:standard); use XML::Simple; use Data::Dumper; my $gAud = 0; my $gVid = 0; my $url = param('url'); if ($url) { print header(-charset=>'utf-8'), start_html(); my $podcast = get($url); my $p = XMLin($podcast); my $c = $p->{'channel'}; print "

$c->{'title'}

\n"; my @i; if (ref($c->{'item'}) eq 'HASH') { @i = ( $c->{'item'} ); } else { @i = @{$c->{'item'}}[0 .. 9]; } foreach (@i) { print "

{'link'}\">$_->{'title'}

"; print "

", firstExisting($_, 'itunes:subtitle', 'description'); if ($_->{'media:group'}) { my @c = @{$_->{'media:group'}->{'media:content'}}; foreach (@c) { if ($_->{'type'} eq 'video/x-flv') { my $w = $_->{'width'}; my $h = $_->{'height'}; my $u = $_->{'url'}; print vPlayer($u, $w, $h); } } } elsif ($_->{'enclosure'}) { if ($_->{'enclosure'}->{'type'} eq 'video/flv') { print vPlayer($_->{'enclosure'}->{'url'}); } elsif ($_->{'enclosure'}->{'type'} eq 'audio/mp3' || $_->{'enclosure'}->{'type'} eq 'audio/mpeg') { print "

", aPlayer($_->{'enclosure'}->{'url'}); } } my $dump = param('dump'); if ($dump) { my $x = Dumper($_); #$x =~ s//>/g; #$x =~ s/&/&/g; print "

$x
"; } } print footer(), end_html; } else { print header(), start_html(), start_form(-method=>'get'), "URL of RSS or Podcast: ", textfield(-name => 'url'), end_form, footer(), end_html; } sub aPlayer { my $x = ''; if ($gAud == 0) { $x .= ""; } $gAud++; return " "; } sub vPlayer { my($u, $w, $h) = @_; $w = $w || 320; $h = $h || 200; # for the controls $h += 55; my $x = ''; if ($gVid == 0) { $x .= ""; } $gVid++; $x .= "

"; return $x; } sub footer { return "


World's smallest podcast reader: source. By Jeff R. Allen <jra\@nella.org>."; } sub firstExisting { my $x = shift @_; foreach (@_) { if (exists($x->{$_})) { if (ref($x->{$_}) ne 'HASH') { return $x->{$_}; } } } }