#!/usr/bin/perl use Asterisk::AGI; use File::Basename; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $dir = '/home/tom/echoradio/'; # get and sort all of the gsm files generated by the cron opendir(DIR, $dir); @files = grep(/\.gsm$/,readdir(DIR)); closedir(DIR); @files = sort(@files); my $selection = -1; my $total_loops = 0; # set up a master loop that repeats 10 times at most while(($selection<=0)&&($total_loops<10)) { # play the welcome message $selection = $AGI->stream_file($dir . 'lib/welcome','0123456789'); # if a key was pressed during the welcome message, break out of the loop if($selection!=0) { last; } # iterate through the files we found, playing each one my $i = 0; foreach $file (@files) { if(-e ($dir . $file)) { $selection = $AGI->stream_file(($dir . basename($file,'.gsm')),'0123456789'); } if(($selection!=0)||($i>9)) { last; } $i++; } # if a button was pressed, let the break percolate up out of this loop, too if($selection>0) { last; } # once we've gone through all the options, wait 3 seconds then loop # (until we've looped ten times; then hang up) $selection = $AGI->wait_for_digit(3000); $total_loops++; } # the value we get back is ascii; transform it into a digit $selection = $selection - 48; # if it was a valid digit, play the corresponding mp3 if(($selection>=0)&&($selection<(@files))) { my $fileroot = $files[$selection]; $fileroot =~ s/^\d\d\-//igx; $fileroot =~ s/\.gsm$//igx; my $mp3 = basename(basename($fileroot),'.mp3'); $AGI->exec('MP3Player',($dir.$mp3.'.mp3')); } exit(0);