Difference between revisions of "Batch download of audio for 1000+ CDRs"
Jump to navigation
Jump to search
(Created page with " Example is for download all audio from CDRs where caller number starts with 0012345 and call started in time range 2019-01-01 00:00:00 - 2019-02-01 00:00:00) (beware that scr...") |
|||
Line 1: | Line 1: | ||
Example is for download all audio from CDRs where caller number starts with 0012345 and call started in time range 2019-01-01 00:00:00 - 2019-02-01 00:00:00) | Example is for download all audio from CDRs where caller number starts with 0012345 and call started in time range 2019-01-01 00:00:00 - 2019-02-01 00:00:00) | ||
− | (beware that script not tests errors in paths credentials etc - | + | (beware that script not tests errors in paths credentials etc - just outputs which file is currently processed and total of observed CDRs to process) |
+ | |||
+ | = audio filenames will be CDRid.wav = | ||
<?php | <?php | ||
Line 19: | Line 21: | ||
echo ("processing CDRid $result ".($n+1)."/$items\n"); | echo ("processing CDRid $result ".($n+1)."/$items\n"); | ||
exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$result.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$result.'.wav',$ret2,$rv2); | exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$result.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$result.'.wav',$ret2,$rv2); | ||
+ | } | ||
+ | } | ||
+ | ?> | ||
+ | |||
+ | |||
+ | = audio filenames will be calldate__caller__called.wav = | ||
+ | Beware that in case there is in resulted filename any of following characters "*",":"," ","#" will be replaced to underscore (change the line toreplace) | ||
+ | |||
+ | <?php | ||
+ | $guiDir="/var/www/html"; | ||
+ | $batchDir="/backup/batch2"; | ||
+ | $user="admin"; | ||
+ | $pass="adminPassw"; | ||
+ | exec('echo \'{"task": "getVoipCalls", "user": "'.$user.'", "password": "'.$pass.'", "params": {"startTime": "2019-01-01 00:00:00", "startTimeTo": "2019-09-13 00:00:00","caller": "5555%", "onlyConnected": "1"}}\' | php '.$guiDir.'/php/api.php',$ret,$rv); | ||
+ | if (!$rv) { | ||
+ | $tmpres=(json_decode($ret[0])); | ||
+ | foreach($tmpres->cdr as $record) { | ||
+ | $cdrids[]=$record->cdrId; | ||
+ | $cdrcallers[]=$record->caller; | ||
+ | $cdrcalleds[]=$record->called; | ||
+ | $cdrcalldates[]=$record->calldate; | ||
+ | var_dump($record); | ||
+ | } | ||
+ | $items=count($cdrids); | ||
+ | foreach ($cdrids as $n => $cdrId) { | ||
+ | $filenametmp=$cdrcalldates[$n]."__".$cdrcallers[$n]."__".$cdrcalleds[$n];// 2 x _ is delimiter in filename between date caller called | ||
+ | $toreplace=array(':', ' ', '*', '#'); //what chars in filename to replace: space * # : | ||
+ | $filename= str_replace($toreplace, "_", $filenametmp); //for what to replace the above chars _ | ||
+ | echo ("processing CDRid $cdrId ".($n+1)."/$items as $filename.wav\n"); | ||
+ | exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$cdrId.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$filename.'.wav',$ret2,$rv2); | ||
} | } | ||
} | } | ||
?> | ?> |
Revision as of 18:54, 13 September 2019
Example is for download all audio from CDRs where caller number starts with 0012345 and call started in time range 2019-01-01 00:00:00 - 2019-02-01 00:00:00) (beware that script not tests errors in paths credentials etc - just outputs which file is currently processed and total of observed CDRs to process)
audio filenames will be CDRid.wav
<?php $guiDir="/var/www/html"; $batchDir="/backup/batch"; $user="myGuiUser"; $pass="myGuiPass"; exec('echo \'{"task": "getVoipCalls", "user": "'.$user.'", "password": "'.$pass.'", "params": {"startTime": "2019-01-01 00:00:00", "startTimeTo": "2019-02-01 00:00:00","caller": "0012345%", "onlyConnected": "1"}}\' | php '.$guiDir.'/php/api.php',$ret,$rv); if (!$rv) { $tmpres=(json_decode($ret[0])); foreach($tmpres->cdr as $record) { $results[]=$record->cdrId; } $items=count($results); foreach ($results as $n => $result) { echo ("processing CDRid $result ".($n+1)."/$items\n"); exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$result.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$result.'.wav',$ret2,$rv2); } } ?>
audio filenames will be calldate__caller__called.wav
Beware that in case there is in resulted filename any of following characters "*",":"," ","#" will be replaced to underscore (change the line toreplace)
<?php $guiDir="/var/www/html"; $batchDir="/backup/batch2"; $user="admin"; $pass="adminPassw"; exec('echo \'{"task": "getVoipCalls", "user": "'.$user.'", "password": "'.$pass.'", "params": {"startTime": "2019-01-01 00:00:00", "startTimeTo": "2019-09-13 00:00:00","caller": "5555%", "onlyConnected": "1"}}\' | php '.$guiDir.'/php/api.php',$ret,$rv); if (!$rv) { $tmpres=(json_decode($ret[0])); foreach($tmpres->cdr as $record) { $cdrids[]=$record->cdrId; $cdrcallers[]=$record->caller; $cdrcalleds[]=$record->called; $cdrcalldates[]=$record->calldate; var_dump($record); } $items=count($cdrids); foreach ($cdrids as $n => $cdrId) { $filenametmp=$cdrcalldates[$n]."__".$cdrcallers[$n]."__".$cdrcalleds[$n];// 2 x _ is delimiter in filename between date caller called $toreplace=array(':', ' ', '*', '#'); //what chars in filename to replace: space * # : $filename= str_replace($toreplace, "_", $filenametmp); //for what to replace the above chars _ echo ("processing CDRid $cdrId ".($n+1)."/$items as $filename.wav\n"); exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$cdrId.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$filename.'.wav',$ret2,$rv2); } } ?>