August 2005
Beginner
464 pages
12h 36m
English
Using Perl, you can quickly build a command-line podcatcher for yourself.
Rolling your own command-line podcatcher, like the one shown here, gives you ultimate flexibility in what podcasts you download and when you fetch them. You can also hook up this script to a cron job or to a Windows batch file and download new podcasts overnight.
Save this code as spc.pl:
#!/usr/bin/perl -w use Storable qw ( store retrieve ); use FileHandle; use LWP::Simple qw( get ); use strict; # The path to the history file that remembers # what we have downloaded. use constant HISTORY_FILE => ".history"; # The file that includes the URLs of all of the feedsuse constant FEEDS_FILE => "#The directory to use for output of the enclosure filesfeeds.txt";use constant OUTPUT_DIR => "# Loads all of the feeds from the feeds file and returns # an array. sub feeds_load() { my $feeds = []; my $fh = new FileHandle( FEEDS_FILE ); while( <$fh> ) { chomp; push @$feeds, $_; } $fh->close(); return $feeds; } # Returns the filename from a URL sub parse_filename($) { my ( $fname ) = @_; # Remove the arguments portion of the URL $fname =~ s/\?.*$//; # Trim anything up to the final slash $fname =~ s/.*\///; return $fname; } # Parses a feed and finds the title of the feed and the # URLs for all of the enclosures sub parse_feed($) { my ( $rss ) = @_; my $info = {}; my $urls = [];enclosures";while( $rss =~ /(\<item\>.*?\<\/item\>)/sg ){my $item = $1;if ( $item =~ /(\<enclosure.*?\>)/ ) ...
Read now
Unlock full access