Debian Codegraph @

agi/DialAnMp3.agi

raw
1 #!/usr/bin/perl
2 #
3 # Simple AGI application to play mp3's selected by a user both using
4 # xmms and over the phone itself.
5 #
6 $|=1;
7 while(<STDIN>) {
8 chomp;
9 last unless length($_);
10 if (/^agi_(\w+)\:\s+(.*)$/) {
11 $AGI{$1} = $2;
12 }
13 }
14
15 print STDERR "AGI Environment Dump:\n";
16 foreach $i (sort keys %AGI) {
17 print STDERR " -- $i = $AGI{$i}\n";
18 }
19
20 dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");;
21
22 sub checkresult {
23 my ($res) = @_;
24 my $retval;
25 $tests++;
26 chomp $res;
27 if ($res =~ /^200/) {
28 $res =~ /result=(-?[\w\*\#]+)/;
29 return $1;
30 } else {
31 return -1;
32 }
33 }
34
35 #print STDERR "1. Playing beep...\n";
36 #print "STREAM FILE beep \"\"\n";
37 #$result = <STDIN>;
38 #checkresult($result);
39
40 print STDERR "2. Getting song name...\n";
41 print "GET DATA demo-enterkeywords\n";
42 $result = <STDIN>;
43 $digitstr = checkresult($result);
44 if ($digitstr < 0) {
45 exit(1);
46 }
47 $digitstr =~ s/\*/ /g;
48
49 print STDERR "Resulting songname is $digitstr\n";
50 @searchwords = split (/\s+/, $digitstr);
51 print STDERR "Searchwords: " . join(':', @searchwords) . "\n";
52
53 foreach $key (sort keys %DIGITS) {
54 @words = split(/\s+/, $DIGITS{$key});
55 $match = 1;
56 foreach $search (@searchwords) {
57 $match = 0 unless grep(/$search/, @words);
58 }
59 if ($match > 0) {
60 print STDERR "File $key matches\n";
61 # Play a beep
62 print "STREAM FILE beep \"\"\n";
63 system("xmms", $key);
64 $result = <STDIN>;
65 if (&checkresult($result) < 0) {
66 exit 0;
67 }
68 print "EXEC MP3Player \"$key\"\n";
69 # print "WAIT FOR DIGIT 60000\n";
70 $result = <STDIN>;
71 if (&checkresult($result) < 0) {
72 exit 0;
73 }
74 print STDERR "Got here...\n";
75 }
76 }
77
78 print STDERR "4. Testing 'saynumber' of $digitstr...\n";
79 print "STREAM FILE demo-nomatch\"\"\n";
80 $result = <STDIN>;
81 checkresult($result);
82