Exemple #1
0
 public function testSubmitConfigWithAPIKey()
 {
     $config = "\nset source = https://s3-eu-west-1.amazonaws.com/media.heywatch.com/test.mp4\n";
     $job = HeyWatch::submit($config, "k-4d204a7fd1fc67fc00e87d3c326d9b75");
     $this->assertEquals("error", $job->{"status"});
     $this->assertEquals("authentication_failed", $job->{"error_code"});
 }
 /** 
  * Transcode missing formats from source
  * @param type $missingOnly
  */
 public function transcode($missingOnly = true)
 {
     // get source in preferred order
     $source = false;
     if (!$source && $this->SourceID) {
         $source = $this->Source();
     }
     if (!$source && $this->MP3ID) {
         $source = $this->MP3();
     }
     if (!$source && $this->OGGID) {
         $source = $this->OGG();
     }
     if (!$source || !$source->exists()) {
         Session::set('AudioNotification', array('error' => _t('Transcodable.MissingAudioSource', 'Could not find any audio to use as source for transcoding')));
         return false;
     }
     // Build heywatch configuration
     $hw_config = "# Audio config for Heywatch\n\t\t\t\nset source  = aud_source\nset webhook = aud_webhook\n";
     // Add missing files;
     if (!$this->MP3ID) {
         $hw_config .= "\n-> mp3 = aud_uploadaud_pathaud_name.mp4";
     }
     if (!$this->OGGID) {
         $hw_config .= "\n-> ogg = aud_uploadaud_pathaud_name.ogg";
     }
     $ext = pathinfo($source->getFilename(), PATHINFO_EXTENSION);
     // if we're on localhost, use development webhook, else use real one
     if (Config::inst()->get('Transcoding', 'transcode_development_webhook')) {
         $whook = Config::inst()->get('Transcoding', 'transcode_development_webhook');
     } else {
         $whook = Transcode_Controller::staticAbsoluteLink();
     }
     $replacements = array('aud_webhook' => $whook, 'aud_upload' => Config::inst()->get('Transcoding', 'transcode_upload_method'), 'aud_path' => Config::inst()->get('Transcoding', 'transcode_relative_audio_path'), 'aud_source' => $source->getAbsoluteURL(), 'aud_name' => basename($source->getFilename(), "." . $ext));
     $hw_config = strtr($hw_config, $replacements);
     //		$conf = file_get_contents("heywatch.conf");
     //		Debug::dump($hw_config);
     $joblog = TranscodeJob::getOrCreateForTranscodable($this->ID);
     $joblog->TranscodableClass = $this->ClassName;
     $job = HeyWatch::submit($hw_config, Config::inst()->get('Transcoding', 'transcode_api_key'));
     if ($job->{"status"} == "ok") {
         // job created
         $joblog->JobStatus = "started";
         $joblog->JobID = $job->{"id"};
         // Feedback to user
         Session::set('VideoNotification', array('good' => 'Transcoding started'));
     } else {
         // job not created...
         $joblog->JobStatus = "error";
         //$joblog->JobErrorCode = $job->{"error_code"};
         $joblog->JobErrorMessage = $job->{"error_message"};
         // Feedback to user
         Session::set('VideoNotification', array('bad' => 'Transcoding error'));
     }
     $joblog->write();
 }