#!/usr/bin/perl use XML::Simple; use Asterisk::AGI; use LWP::Simple; $AGI = new Asterisk::AGI; $xml = new XML::Simple; $noext = "/tmp/twiar"; $resampled = "/tmp/twiar.mp3"; $AGI->verbose("Getting XML file\n"); $data = $xml->XMLin(get("http://www.twiar.org/twiaripodcast.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/twiar*.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 2.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); exit;