use strict; use warnings; use POE qw(Component::RSSAggregator); ################################################################# my $wantedShowsPattern = join ('|', 'sinner', 'soulville', 'Laura Cantrell', 'mister c', 'billy jam', # will get "unshackled..." too? 'coffee', # does this feed include coffee2go als +o? 'Dave Emory', # 7 Second Delay? # Ken's show? # Pseu Braun? # Irwin (calypso 2-3PM)? ); my $downloadDir = 'E:/wfmu/'; my @feeds = ( { url => "http://wfmu.org/archivefeed/mp3.xml", name => "wfmu_mp3", delay => 3600, }, ); ################################################################# -d $downloadDir or die("download dir $downloadDir must be created.\n") +; -w $downloadDir or die("download dir $downloadDir must be writable.\n" +); POE::Session->create( inline_states => { _start => \&init_session, handle_feed => \&handle_feed, }, ); $poe_kernel->run(); sub init_session { my ( $kernel, $heap, $session ) = @_[ KERNEL, HEAP, SESSION ]; $heap->{rssagg} = POE::Component::RSSAggregator->new( alias => 'rssagg', debug => 1, callback => $session->postback("handle_feed"), tmpdir => 'f:/cgi/wfmu/', ); $kernel->post( 'rssagg', 'add_feed', $_ ) for @feeds; } sub handle_feed { my ( $kernel, $feed ) = ( $_[KERNEL], $_[ARG1]->[0] ); printf "\n========= %s ===============\n", scalar(localtime); for my $headline ( $feed->late_breaking_news ) { print $headline->headline() . "\n"; next unless parseHeadline($headline->headline())->{'show'} =~ m/ +$wantedShowsPattern/i; print "\n----- DOWNLOADING ... ---------------------\n"; print " url: " . $headline->url() . "\n"; processUrl($headline->url()); print "\n"; } } sub processUrl { my $url = shift; if ($url !~ /\.m3u/i) { print "Invalid playlist url?\n"; return; } use LWP::Simple; print "retrieving m3u file...\n"; my $mp3Url = LWP::Simple::get($url); print "mp3 url: $mp3Url\n"; if ($mp3Url !~ /mp3$/s) { print "Either the get failed or the content is unusable?\n"; return; } # example url: # http://archive.wfmu.org:5555/archive/BJ/bj070119.mp3 use URI; my $uriObj = URI->new($mp3Url); my $uriPath = $uriObj->path(); use File::Basename; my $baseFileName = basename($uriPath); if ($baseFileName eq '') { print "Botched processing of filename?\n"; return; } my $mp3File = $downloadDir . $baseFileName; print "file: $mp3File\n"; if (-e $mp3File) { print "File already exists!\n"; return; } print "SAVING MP3 TO FILE...\n"; my $responseCode = getstore($mp3Url, $mp3File); print "done saving.\n"; } sub parseHeadline { my $headline = shift; return if $headline eq ''; $headline =~ s/^WFMU\sMP3\sArchive:\s+//; if ($headline =~ s{ \sfrom \s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|D +ec) \s(\d+), \s(\d{4}) $ }{}six) { ($mon, $mday, $year) = ($1, $2, $3); my $show = $headline; return {'show' => $show}; # (I might eventually with the date, but not yet.) } else { print "parse error on headline?\n ( $_[0] )\n"; } return; }

In reply to download mp3s listed in RSS feed by blahblahblah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.