#!/fellow/monks.pl

I've written a podcatcher in perl before, but this time I thought of doing it a bit tighter, using a few more modules, and simplifying it.

#!/usr/bin/perl use strict; use XML::Simple; use LWP::Simple; my $config = "$0.conf"; # The config file that contains all the +RSS feeds my $state = "$0.state"; # The file to keep track what we've down +loaded my $target_dir = substr($0,0,rindex($0,"/")+rindex($0,"\\")); # +The directory where to dump the podcasts open(IN,"$config") || die "Cannot read the config file : $config"; while(<IN>) { chomp; my $data = eval { XMLin(get($_)) }; print "\n$data->{channel}->{title} ($_)\n"; if (ref($data->{channel}->{item}) ne 'ARRAY') { &enclosure($data->{channel}->{item}->{enclosure}->{url +},$data->{channel}->{item}->{enclosure}->{length}); } else { foreach my $item ( @{ $data->{channel}->{item} }) { &enclosure($item->{enclosure}->{url},$item->{e +nclosure}->{length}); } } } close IN; exit(0); sub enclosure { my ($url,$len) = $_; open(STATE,"$state"); while(<STATE>) { chomp; if($url eq $_) { close STATE; return; } } close STATE; my $rawfile = get($url); if(length($rawfile) == $len) { open(OUT,">$target_dir/" . substr($url,rindex($url,"/")+1)); print OUT get($url); close OUT; open(OUT,">>$state"); print OUT "$url\n"; close OUT; } }

In reply to Slim Podcatcher by Massyn

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.