#!/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; } }

Replies are listed 'Best First'.
Re: Slim Podcatcher
by Anonymous Monk on Dec 31, 2009 at 06:38 UTC
    plain old documentation?