function get_file_type($path) { $result = FALSE; if ($path) { $result = get_file_info('type', $path); if (!$result) { $mime = get_file_info('Content-Type', $path); if ($mime) { $result = array_shift(explode('/', $mime)); if ($result) { set_file_info($path, 'type', $result); } } } } return $result; }
function addMeta($path, $key, $value = '') { return set_file_info($path, $key, $value); }
function __buildAudio($file_path) { if (!empty($this->_options['EncoderAudioExtension'])) { if (get_file_info('audio', $file_path, $this->_options['PathFFmpeg'])) { $this->_progressStep('EncodeAudio', 5, 'Encoding Audio ' . $file_path); $media_path = media_file_path($file_path); $audio_path = $media_path . 'audio.' . $this->_options['EncoderAudioExtension']; $switches = array(); if (!safe_path($audio_path)) { throw new RuntimeException('Could not create path: ' . $audio_path); } $cmd = ''; $cmd .= $this->_options['PathFFmpeg'] . ' -i '; $cmd .= $file_path; $cmd .= ' -ab ' . $this->_options['EncoderAudioBitrate'] . 'k'; $cmd .= ' -ar ' . $this->_options['EncoderAudioFrequency']; //$cmd .= ' -acodec ' . $this->_options['EncoderAudioExtension']; $cmd .= ' -vn ' . $audio_path; $response = $this->_shellExecute($cmd); if (!$response) { throw new RuntimeException('Problem with audio command: ' . $cmd); } if (!file_exists($audio_path)) { throw new RuntimeException('Could not build audio: ' . $response); } $cached_wav = cache_file_wav($file_path, $switches, $this->_options['PathFFmpeg']); if (!$cached_wav) { throw new RuntimeException('Could not determine path to audio wav file: ' . $file_path); } if (!empty($this->_options['Verbose'])) { $this->log($cached_wav['command']); } if (!$cached_wav['path']) { throw new RuntimeException('Could not build audio wav file: ' . $file_path); } $wav_file_path = $cached_wav['path']; // get a more accurate duration reading from WAV file if (!($meta_path = meta_file_path('blah', $wav_file_path))) { throw new RuntimeException('Could not determine meta path for ' . $wav_file_path); } if (!($meta_dir = dir_path($meta_path))) { throw new RuntimeException('Could not determine dir path of ' . $meta_path); } if (!($duration = get_file_info('duration', $wav_file_path, $this->_options['PathFFmpeg']))) { throw new RuntimeException('Could not determine duration of ' . $wav_file_path); } if (!set_file_info($file_path, 'duration', $duration)) { throw new RuntimeException('Could not set duration of ' . $file_path); } // make waveform graphic $this->_ignore[] = $wav_file_path; $audio_path = $media_path . 'audio.' . $this->_options['EncoderWaveformExtension']; $cmd = ''; $cmd .= $this->_options['PathWaveformGenerator'] . ' --input ' . $wav_file_path; $cmd .= ' --height 64 --width 2800'; $cmd .= ' --linecolor ' . $this->_options['EncoderWaveformForecolor']; $cmd .= ' --padding 0'; $cmd .= ' --backgroundcolor ' . $this->_options['EncoderWaveformBackcolor']; $cmd .= ' --output ' . $audio_path; $response = $this->_shellExecute($cmd); if (!file_exists($audio_path)) { throw new RuntimeException('Could not create waveform graphic: ' . $cmd); } $this->_shellExecute('rm -R ' . $meta_dir); $this->_progressStep('EncodeAudio', 100, 'Encoded Audio'); } } }
function _processJob() { $dir_cache = $this->_options['DirCache']; $dir_jobs_queued = $this->_options['DirJobsQueued']; if (!($dir_cache && $dir_jobs_queued)) { throw new UnexpectedValueException('Configuration options DirCache, DirJobsQueued required'); } // create job file $this->_jobXML->asXML($dir_jobs_queued . $this->_jobID . '.xml'); $xml_string = ''; $xml_string .= '<Progress>' . "\n"; $xml_string .= "\t" . '<PercentDone>1</PercentDone>' . "\n"; $xml_string .= "\t" . '<Date>' . http_date_string() . '</Date>' . "\n"; $xml_string .= "\t" . '<Status>Queued</Status>' . "\n"; $xml_string .= '</Progress>' . "\n"; $progress_path = $dir_cache . $this->_jobID . '/media.xml'; if (!safe_path($progress_path)) { throw new RuntimeException('Could not create path: ' . $progress_path); } if (!@file_put_contents($progress_path, $xml_string)) { throw new RuntimeException('Could not write file: ' . $progress_path); } if (!set_file_info($progress_path, 'cached', gmdate("Y-m-d H:i:s"))) { throw new RuntimeException('Could not set cached info: ' . $progress_path); } }
function codeFile($job_id) { if ($this->getOption('Verbose')) { $this->log(print_r($this->_options, 1)); } $has_callback = !(empty($this->_options['CoderDoneURL']) && empty($this->_options['CoderErrorURL'])); $ex = FALSE; $err = ''; // grab configuration options and make sure they're not empty $dir_temporary = $this->_options['DirTemporary']; $dir_cache = $this->_options['DirCache']; if (!($dir_temporary && $dir_cache)) { throw new UnexpectedValueException('Configuration options DirTemporary, DirCache required'); } // set unique _tempDir for job $uid = 'Coder_' . unique_id('codertemp'); $this->_tempDir = $dir_temporary . $uid . '/'; // set build directory within it, and make sure we can create it $this->_buildDir = $this->_tempDir . $this->_options['CoderFilename'] . '/'; if (!safe_path($this->_buildDir)) { throw new RuntimeException('Could not create path: ' . $this->_buildDir); } $this->__jobID = $job_id; // set progress path and make sure we can write to it (will create DirCache if it doesn't exist) $progress_path = $dir_cache . $this->__jobID . '/media.xml'; if (!safe_path($progress_path)) { throw new RuntimeException('Could not create path: ' . $progress_path); } $this->_ignore = array(); chdir($dir_temporary); $this->__percentDone = 1; $this->__steps = array('total_steps' => 0); $this->__outputProgress(substr($this->_coderName, 0, -1) . 'ing'); if (!set_file_info($progress_path, 'cached', gmdate("Y-m-d H:i:s"))) { throw new RuntimeException('Could not set cached meta data'); } // for progress calculations $this->_setupSteps(); if (!empty($this->_options['CoderFileURL'])) { $this->_addStep('StoreFile'); } if ($has_callback) { $this->_addStep('CallbackURL'); } try { $coder_error = $this->getOption('CoderError'); if ($coder_error) { throw new RuntimeException($coder_error); } $file_path = $this->_codeFile(); // see if archive desired if (!empty($this->_options['CoderArchiveExtension'])) { if (substr($file_path, -1) == '/') { $file_path = substr($file_path, 0, -1); } //$this->log('Archiving ' . $file_path . ' to ' . $archive_path); $file_path = $this->__createArchive($file_path); } $this->__storeFile($file_path); if (!empty($this->_options['CoderArchiveExtension'])) { @unlink($file_path); } } catch (Exception $ex) { $err .= $ex->getMessage(); } try { if (!$err) { if ($has_callback) { $this->_progressStep('CallbackURL', 1, 'Calling Callback URL'); } } else { $this->__upProgress(-1, $err); } } catch (Exception $ex) { // ignore any possible errors from upping progress } try { $this->__sendDone($err); } catch (Exception $ex) { $err .= $ex->getMessage(); } try { if (!$err) { $this->__percentDone = 100; $this->__outputProgress($this->_coderName . 'd'); } } catch (Exception $ex) { // ignore any possible errors from upping progress } if (file_exists($this->_tempDir) && empty($this->_options['CoderSaveTemporaryFiles'])) { // remove temporary files, even in error cases $this->_shellExecute('rm -R ' . $this->_tempDir); } try { flush_cache_files($dir_cache, $this->_options['CacheSize']); } catch (Exception $ex) { // ignore any possible errors from flushing cache } if ($err) { throw new RuntimeException($err); } }