diff --git a/agc_2-X/trunk/bin/ADMIN_audio_store_sync.pl b/agc_2-X/trunk/bin/ADMIN_audio_store_sync.pl index 07d38c01..09997068 100644 --- a/agc_2-X/trunk/bin/ADMIN_audio_store_sync.pl +++ b/agc_2-X/trunk/bin/ADMIN_audio_store_sync.pl @@ -6,7 +6,7 @@ # syncronizes audio between audio store and this server # # -# Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2014 Matt Florell LICENSE: AGPLv2 # # CHANGELOG # 90513-0458 - First Build @@ -17,6 +17,7 @@ # 101217-2137 - Small fix for admin directories not directly off of the webroot # 121019-0729 - Added audio_store_purge feature # 141124-2309 - Fixed Fhour variable bug +# 141125-1555 - Added audio_store_details audio file info gathering and DB population # # constants @@ -65,6 +66,7 @@ if (length($ARGV[0])>1) print " [--force-upload] = force upload of all local audio files to the audio store\n"; print " [--settings-override] = ignore database settings and run sync anyway\n"; print " [--force-moh-rebuild] = ignore database settings and rebuild Music On Hold\n"; + print " [--gather-details] = gathers audio file details and populates audio_store_details table\n"; print "\n"; exit; } @@ -100,6 +102,11 @@ if (length($ARGV[0])>1) $force_moh_rebuild=1; if ($DB) {print "\n----- FORCE MUSIC ON HOLD REBUILD -----\n\n";} } + if ($args =~ /--gather-details/i) + { + $gather_details=1; + if ($DB) {print "\n----- GATHER AUDIO FILE DETAILS -----\n\n";} + } if ($args =~ /--debugX/i) { $DBX=1; @@ -191,10 +198,10 @@ if ($sthArows > 0) $sounds_web_directory = $aryA[2]; $admin_web_directory = $aryA[3]; if ($admin_web_directory =~ /\//) - { - $web_prefix = $admin_web_directory; - $web_prefix =~ s/\/.*/\//gi; - } + { + $web_prefix = $admin_web_directory; + $web_prefix =~ s/\/.*/\//gi; + } } $sthA->finish(); @@ -432,6 +439,109 @@ if ($uploaded > 0) +###### BEGIN GATHER AUDIO FILE DETAILS ##### +if ($gather_details > 0) + { + $gsm_count=0; + $wav_count=0; + $new_count=0; + $old_count=0; + $update_count=0; + $i=0; + while ($i <= $#list) + { + chomp($list[$i]); + @file_data = split(/\t/, $list[$i]); + $filename = $file_data[1]; + $filedate = $file_data[2]; + $filesize = $file_data[3]; + $fileepoch = $file_data[4]; + if ($DB > 0) {print "$i $filename $filedate $filesize $fileepoch\n";} + + $allowed_format=0; + if ($filesize > 0) + { + if ($filename =~ /\.wav$/) + { + $allowed_format++; + $wav_count++; + $audio_format='wav'; + $audio_length = ($filesize / 16000); + $audio_length = sprintf("%.0f", $audio_length); + } + if ($filename =~ /\.gsm$/) + { + $allowed_format++; + $gsm_count++; + $audio_format='gsm'; + $audio_length = ($filesize / 1650); + $audio_length = sprintf("%.0f", $audio_length); + } + + if ($allowed_format > 0) + { + $stmtA = "SELECT audio_format,audio_filesize,audio_length FROM audio_store_details where audio_filename = '$filename';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $asd_format = $aryA[0]; + $asd_filesize = $aryA[1]; + $asd_length = $aryA[2]; + + if ( ($asd_format eq "$audio_format") && ($asd_filesize eq "$filesize") && ($asd_length eq "$audio_length") ) + { + $old_count++; + if ($DB > 0) {print "$i audio file details unchanged: $filename - |$audio_format|$filesize|$audio_length|\n";} + } + else + { + $update_count++; + $stmtA="UPDATE audio_store_details SET audio_format='$audio_format',audio_filesize='$filesize',audio_length='$audio_length',audio_epoch='$fileepoch' where audio_filename='$filename';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX > 0) {print " $affected_rows|$stmtA|\n";} + } + } + else + { + $new_count++; + $stmtA="INSERT INTO audio_store_details SET audio_filename='$filename',audio_format='$audio_format',audio_filesize='$filesize',audio_length='$audio_length',audio_epoch='$fileepoch';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX > 0) {print " $affected_rows|$stmtA|\n";} + } + $sthA->finish(); + } + else + { + if ($DB > 0) {print "$i format is not allowed: $filename\n";} + } + } + else + { + if ($DB > 0) {print "$i filesize is zero: $filename ($filesize)\n";} + } + $i++; + } + + if($DB) + { + print "Gather Details Summary:\n"; + print "GSM files: $gsm_count\n"; + print "WAV files: $wav_count\n"; + print "NEW entries: $new_count\n"; + print "OLD entries: $old_count\n"; + print "UPDATED entries: $update_count\n"; + print "TOTAL: $i\n"; + print "\n"; + } + } +###### END GATHER AUDIO FILE DETAILS ##### + + + + ###### BEGIN Music on hold rebuild ##### $wav = '.wav'; diff --git a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl index 9d7bac38..803cd2db 100644 --- a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl +++ b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl @@ -95,9 +95,10 @@ # 140214-1519 - Added reload_timestamp value to conf files # 140619-1001 - Added new ASTplay loop IAX trunk # 141113-1555 - Changed FILL process screen from ASTVDautoFILL to ASTVDadFILL for easier admin +# 141125-1710 - Added gather_stats_flag for audio sync script launch on voicemail server # -$build = '140619-1001'; +$build = '141125-1710'; $DB=0; # Debug flag @@ -3428,8 +3429,11 @@ if ( ($active_asterisk_server =~ /Y/) && ( ($sounds_update =~ /Y/) || ($upload_a { if ($sounds_central_control_active > 0) { + $gather_stats_flag=''; + if ($THISserver_voicemail > 0) + {$gather_stats_flag='--gather-details';} if ($DB) {print "running audio store sync process...\n";} - `/usr/bin/screen -d -m -S AudioStore $PATHhome/ADMIN_audio_store_sync.pl $upload_flag 2>/dev/null 1>&2`; + `/usr/bin/screen -d -m -S AudioStore $PATHhome/ADMIN_audio_store_sync.pl $upload_flag $gather_stats_flag 2>/dev/null 1>&2`; } } ################################################################################ diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index 3e8ce3d0..a95c555e 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -3069,6 +3069,15 @@ parent_rank VARCHAR(2) default '', index (avatar_id) ) ENGINE=MyISAM; +CREATE TABLE audio_store_details ( +audio_filename VARCHAR(255) NOT NULL, +audio_format VARCHAR(10) default 'unknown', +audio_filesize BIGINT(20) UNSIGNED default '0', +audio_epoch BIGINT(20) UNSIGNED default '0', +audio_length INT(10) UNSIGNED default '0', +unique index (audio_filename) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -3312,4 +3321,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1391',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1392',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.10.sql b/agc_2-X/trunk/extras/upgrade_2.10.sql index 616e4557..e3e693e4 100644 --- a/agc_2-X/trunk/extras/upgrade_2.10.sql +++ b/agc_2-X/trunk/extras/upgrade_2.10.sql @@ -81,3 +81,14 @@ ALTER TABLE vicidial_comments MODIFY user_id VARCHAR(20) NOT NULL; ALTER TABLE vicidial_comments MODIFY campaign_id VARCHAR(8) NOT NULL; UPDATE system_settings SET db_schema_version='1391',db_schema_update_date=NOW() where db_schema_version < 1391; + +CREATE TABLE audio_store_details ( +audio_filename VARCHAR(255) NOT NULL, +audio_format VARCHAR(10) default 'unknown', +audio_filesize BIGINT(20) UNSIGNED default '0', +audio_epoch BIGINT(20) UNSIGNED default '0', +audio_length INT(10) UNSIGNED default '0', +unique index (audio_filename) +) ENGINE=MyISAM; + +UPDATE system_settings SET db_schema_version='1392',db_schema_update_date=NOW() where db_schema_version < 1392;