diff options
author | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-14 06:00:11 +0000 |
---|---|---|
committer | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-14 06:00:11 +0000 |
commit | 7dc232beda6ba9c8ad5231c10a8e3c13cb735cd8 (patch) | |
tree | 4d5b29650be4cacf2c29710581941f0e84cfd431 /agi | |
parent | 54b168a25414b0994fa47dc2d79408ce9586000a (diff) |
Fri Feb 14 07:00:01 CET 2003
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@614 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'agi')
-rwxr-xr-x | agi/DialAnMp3.agi | 82 | ||||
-rwxr-xr-x | agi/numeralize | 44 |
2 files changed, 126 insertions, 0 deletions
diff --git a/agi/DialAnMp3.agi b/agi/DialAnMp3.agi new file mode 100755 index 000000000..59a54265e --- /dev/null +++ b/agi/DialAnMp3.agi @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# +# Simple AGI application to play mp3's selected by a user both using +# xmms and over the phone itself. +# +$|=1; +while(<STDIN>) { + chomp; + last unless length($_); + if (/^agi_(\w+)\:\s+(.*)$/) { + $AGI{$1} = $2; + } +} + +print STDERR "AGI Environment Dump:\n"; +foreach $i (sort keys %AGI) { + print STDERR " -- $i = $AGI{$i}\n"; +} + +dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");; + +sub checkresult { + my ($res) = @_; + my $retval; + $tests++; + chomp $res; + if ($res =~ /^200/) { + $res =~ /result=(-?[\w\*\#]+)/; + return $1; + } else { + return -1; + } +} + +#print STDERR "1. Playing beep...\n"; +#print "STREAM FILE beep \"\"\n"; +#$result = <STDIN>; +#checkresult($result); + +print STDERR "2. Getting song name...\n"; +print "GET DATA demo-enterkeywords\n"; +$result = <STDIN>; +$digitstr = checkresult($result); +if ($digitstr < 0) { + exit(1); +} +$digitstr =~ s/\*/ /g; + +print STDERR "Resulting songname is $digitstr\n"; +@searchwords = split (/\s+/, $digitstr); +print STDERR "Searchwords: " . join(':', @searchwords) . "\n"; + +foreach $key (sort keys %DIGITS) { + @words = split(/\s+/, $DIGITS{$key}); + $match = 1; + foreach $search (@searchwords) { + $match = 0 unless grep(/$search/, @words); + } + if ($match > 0) { + print STDERR "File $key matches\n"; + # Play a beep + print "STREAM FILE beep \"\"\n"; + system("xmms", $key); + $result = <STDIN>; + if (&checkresult($result) < 0) { + exit 0; + } + print "EXEC MP3Player \"$key\"\n"; +# print "WAIT FOR DIGIT 60000\n"; + $result = <STDIN>; + if (&checkresult($result) < 0) { + exit 0; + } + print STDERR "Got here...\n"; + } +} + +print STDERR "4. Testing 'saynumber' of $digitstr...\n"; +print "STREAM FILE demo-nomatch\"\"\n"; +$result = <STDIN>; +checkresult($result); + diff --git a/agi/numeralize b/agi/numeralize new file mode 100755 index 000000000..5ca51913d --- /dev/null +++ b/agi/numeralize @@ -0,0 +1,44 @@ +#!/usr/bin/perl +# +# Build a database linking filenames to their numerical representations +# using a keypad for the DialAnMp3 application +# + +$mp3dir="/usr/media/mpeg3"; + +dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");; +sub process_dir { + my ($dir) = @_; + my $file; + my $digits; + my @entries; + opendir(DIR, $dir); + @entries = readdir(DIR); + closedir(DIR); + foreach $_ (@entries) { + if (!/^\./) { + $file = "$dir/$_"; + if (-d "$file") { + process_dir("$file"); + } else { + $digits = $_; + $digits =~ s/[^ \w]+//g; + $digits =~ s/\_/ /g; + $digits =~ tr/[a-z]/[A-Z]/; + $digits =~ tr/[A-C]/2/; + $digits =~ tr/[D-F]/3/; + $digits =~ tr/[G-I]/4/; + $digits =~ tr/[J-L]/5/; + $digits =~ tr/[M-O]/6/; + $digits =~ tr/[P-S]/7/; + $digits =~ tr/[T-V]/8/; + $digits =~ tr/[W-Z]/9/; + $digits =~ s/\s+/ /; + print "File: $file, digits: $digits\n"; + $DIGITS{$file} = $digits; + } + } + } +} + +process_dir($mp3dir); |