All pastes #352334 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-12 19:27 UTC
rendered paste body
#!/usr/bin/perl

use XML::Simple;
use Asterisk::AGI;
use LWP::Simple;

$AGI = new Asterisk::AGI;
$xml = new XML::Simple;
$noext = "/tmp/newscnn";
$resampled = "/tmp/newscnn.mp3";

$AGI->verbose("Getting XML file\n");
$data = $xml->XMLin(get("http://www.cnn.com/services/podcasting/newscast/rss.xml"));
$url = $data->{channel}->{item}->[0]->{link};
$AGI->verbose("Extracted URL $url from XML file");
$url =~ m#(?:.*/)(.*)$#;
$podcast = "/tmp/" . $1;
if ((-s $podcast) && (-s $resampled))
{
$AGI->verbose("$podcast already exists - skipping download\n");
}
else
{
system("rm /tmp/newscnn*.mp3");
$AGI->verbose("Getting $url\n");
getstore("$url", "$podcast") or die "Could not retrieve podcast";
$AGI->verbose("$podcast retrived\n");
system("lame --silent --mp3input --scale 5 --abr 32 -m m -h $podcast $resampled")==0 or die "Could not convert file";
$AGI->verbose("$pd converted to $resampled\n");
}
$AGI->answer;
$AGI->exec('Playback',$noext);
$AGI->hangup;
exit;