DialAnMp3.agi 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. print STDERR "AGI Environment Dump:\n";
  15. foreach $i (sort keys %AGI) {
  16. print STDERR " -- $i = $AGI{$i}\n";
  17. }
  18. dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");;
  19. sub checkresult {
  20. my ($res) = @_;
  21. my $retval;
  22. $tests++;
  23. chomp $res;
  24. if ($res =~ /^200/) {
  25. $res =~ /result=(-?[\w\*\#]+)/;
  26. return $1;
  27. } else {
  28. return -1;
  29. }
  30. }
  31. #print STDERR "1. Playing beep...\n";
  32. #print "STREAM FILE beep \"\"\n";
  33. #$result = <STDIN>;
  34. #checkresult($result);
  35. print STDERR "2. Getting song name...\n";
  36. print "GET DATA demo-enterkeywords\n";
  37. $result = <STDIN>;
  38. $digitstr = checkresult($result);
  39. if ($digitstr < 0) {
  40. exit(1);
  41. }
  42. $digitstr =~ s/\*/ /g;
  43. print STDERR "Resulting songname is $digitstr\n";
  44. @searchwords = split (/\s+/, $digitstr);
  45. print STDERR "Searchwords: " . join(':', @searchwords) . "\n";
  46. foreach $key (sort keys %DIGITS) {
  47. @words = split(/\s+/, $DIGITS{$key});
  48. $match = 1;
  49. foreach $search (@searchwords) {
  50. $match = 0 unless grep(/$search/, @words);
  51. }
  52. if ($match > 0) {
  53. print STDERR "File $key matches\n";
  54. # Play a beep
  55. print "STREAM FILE beep \"\"\n";
  56. system("xmms", $key);
  57. $result = <STDIN>;
  58. if (&checkresult($result) < 0) {
  59. exit 0;
  60. }
  61. print "EXEC MP3Player \"$key\"\n";
  62. # print "WAIT FOR DIGIT 60000\n";
  63. $result = <STDIN>;
  64. if (&checkresult($result) < 0) {
  65. exit 0;
  66. }
  67. print STDERR "Got here...\n";
  68. }
  69. }
  70. print STDERR "4. Testing 'saynumber' of $digitstr...\n";
  71. print "STREAM FILE demo-nomatch\"\"\n";
  72. $result = <STDIN>;
  73. checkresult($result);