![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
|
Perl Podcast Retriever
This is a podcast retriever I wrote in perl. It goes through each feed extracting urls and downloading them using LWP:
imple.It is designed to be somewhat non-interactive, and it is written for linux, but should work on windows or other OSes with a little tweaking. (Note: I used regular expressions to parse the xml file; so some feeds might not work.) Command Line Options: -s Simulate mode. Downloads RSS feed and extracts Urls but does not download the files or log them. -v Verbose mode. Makes program more verbose. Displays the urls to be downloaded and the file to be made -d Daemon mode. Not really daemon mode, but it forks off the process. Probably doesn't work in windows The urls of the RSS feed go under the __DATA__ token at the bottom. #! /usr/bin/perl
#use warnings;
use LWP::Simple;
use Getopt::Std;
getopts( "dvs" );
fork && exit if ($opt_d);
##############Config################
my $home = "/home/nathan/"; #home directory
my $psd = "$home/.perlsynd"; #logfile directory
my $log = "$psd/podcast.log"; #logfile
my $music = "$home/music"; #music directory
####################################
mkdir $psd unless -d $psd;
unless (-e $log) {
open(CREATE, "> $log") or die("Couldn't make $log: $!");
print CREATE "#perlsynd log#";
close(CREATE);
}
#set date for making directory
($day, $month, $year) = (localtime)[3..5];
$year += 1900;
$month++;
$date = "$year-$month-$day";
$dir = "$music/podcasts/$date";
#open file to create an array to test against
open FILE, "< $log" or die("Can't open podcast.log for reading:$!");
@test=<FILE>;
close FILE;
#open file to add to log file
open(CONF, ">> $log") or die("Can't open podcast.log for writing");
#making directory and chdir to it
mkdir($dir) unless -d $dir;
chdir($dir) or die("Can't change directory: $!");
#basic extraction of urls
foreach (<DATA>) {
$rss = get($_) or warn("Cant get $_: $!");
while ($rss =~ /url\s*=\s*["']?[^ '">]+/gi) {
($url = $&)=~ s/^url=['"]?([^'" >]+?)['"]?/$1/gi;
#added for lugradio
$url =~ s/\?podcast$//;
($url =~ m#[^/ >]+?$#i);
#creating scalar to test against
$line = join( $", @test) or die("Join failed:$!");
if ($opt_v) {
#Verbose
print "Getting: $url\n\t" unless $line =~ /$&/;
print "as: $&\n\n" unless $line =~ /$&/;
}
unless (defined($opt_s)) {
#downloading file
#print "Downloading ...\n" unless $line =~ /$&/;
getstore($url, $&) unless $line =~ /$&/;
#entering file into log
print CONF "$&\n" unless $line =~ /$&/;
}
}
}
__DATA__
http://www.thelinuxlink.net/tllts/tllts_ogg.rss |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|