Rivendell: Simple perl podcatcher and importer

This is a perl script written by REC with the sole mission of obtaining a podcast RSS XML code and finding the first listing, downloading the file and then importing it into a cart slot in Rivendell.

To use this code, you will need to obtain XML::Smart and File::Fetch from CPAN.

The usage is:

perl rdrss.pl cart_number group_name normalization_level rss_url

For example, to obtain the Amateur Radio Newsline podcast and write it to cart #200005 in group SHOWS using a normalization level of -8 dB use:

perl rdrss.pl 200005 SHOWS -8 http://www.arnewsline.org/news/rss.xml

and this code will do the rest!

 

#/usr/bin/perl
use     XML::Smart;
use     File::Fetch;

# command line parameters
my $cart = $ARGV[0];            # Rivendell cart ID
my $group = $ARGV[1];           # Rivendell group ID
my $norm = $ARGV[2];            # Normalization level
my $rss = $ARGV[3];             # Podcast RSS URL

die "Usage: $0 CART GROUP NORMALIZATION RSS-URL\n" if @ARGV != 4;


# searching for the first listing on the podcast RSS file
my $XML = XML::Smart->new($rss);
$XML = $XML->cut_root;
my $attachment = $XML->{channel}{item}[0]{enclosure}{url};
my $version = $XML->{version};
die "Attachment file not found.\n" if $attachment eq "";
print "Found podcast file at: $attachment\n";


# fetch the downloaded file
my $ff = File::Fetch->new(uri => $attachment);
my $where = $ff->fetch() or die $ff->error;
my $lfile = $ff->file;


# delete the local file it is on from before
unlink("$cart.mp3";);


# rename the downloaded file to the file name that will be imported
rename $lfile,"$cart.mp3";


# build and execute the RDimport function
$rdimport = "rdimport --delete-cuts --normalization-level=$norm --to-cart=$cart $group $cart.mp3";
system($rdimport);