| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Build a database linking filenames to their numerical representations |
| 4 |
# using a keypad for the DialAnMp3 application |
| 5 |
# |
| 6 |
|
| 7 |
$mp3dir="/usr/media/mpeg3"; |
| 8 |
|
| 9 |
dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");; |
| 10 |
sub process_dir { |
| 11 |
my ($dir) = @_; |
| 12 |
my $file; |
| 13 |
my $digits; |
| 14 |
my @entries; |
| 15 |
opendir(DIR, $dir); |
| 16 |
@entries = readdir(DIR); |
| 17 |
closedir(DIR); |
| 18 |
foreach $_ (@entries) { |
| 19 |
if (!/^\./) { |
| 20 |
$file = "$dir/$_"; |
| 21 |
if (-d "$file") { |
| 22 |
process_dir("$file"); |
| 23 |
} else { |
| 24 |
$digits = $_; |
| 25 |
$digits =~ s/[^ \w]+//g; |
| 26 |
$digits =~ s/\_/ /g; |
| 27 |
$digits =~ tr/[a-z]/[A-Z]/; |
| 28 |
$digits =~ tr/[A-C]/2/; |
| 29 |
$digits =~ tr/[D-F]/3/; |
| 30 |
$digits =~ tr/[G-I]/4/; |
| 31 |
$digits =~ tr/[J-L]/5/; |
| 32 |
$digits =~ tr/[M-O]/6/; |
| 33 |
$digits =~ tr/[P-S]/7/; |
| 34 |
$digits =~ tr/[T-V]/8/; |
| 35 |
$digits =~ tr/[W-Z]/9/; |
| 36 |
$digits =~ s/\s+/ /; |
| 37 |
print "File: $file, digits: $digits\n"; |
| 38 |
$DIGITS{$file} = $digits; |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
process_dir($mp3dir); |