Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2006, 9:47 PM   #1
glimmy
Programmer
 
glimmy's Avatar
 
Join Date: May 2005
Location: Minnesota
Posts: 42
Rep Power: 0 glimmy is on a distinguished road
Send a message via AIM to glimmy
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
glimmy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:53 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC