Пример #1
0
 public function PreProcess()
 {
     $v = Validator::Create();
     $v->Register($this->source[Video_Source::FIELD_EMBED], Validator_Type::NOT_EMPTY, 'The Embed Code field is required');
     $v->Register($this->source[Video_Source::FIELD_DURATION], Validator_Type::VALID_TIME, 'The Video Duration field must be in HH:MM:SS format');
     $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
     $this->video_dir = new Video_Dir(null, 0700);
     Request::FixFiles();
     // No thumbnails uploaded
     if (!isset($_FILES[Video_Source::FIELD_THUMBNAILS])) {
         return;
     }
     // Process each uploaded file
     foreach ($_FILES[Video_Source::FIELD_THUMBNAILS] as $upload) {
         // No file uploaded in this field
         if ($upload['error'] == UPLOAD_ERR_NO_FILE) {
             continue;
         }
         // Check for other errors
         if ($upload['error'] != UPLOAD_ERR_OK) {
             throw new BaseException(Uploads::CodeToMessage($upload['error']));
         }
         switch (File::Type($upload['name'])) {
             case File::TYPE_ZIP:
                 foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_JPEG) as $name => $data) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                 }
                 break;
             case File::TYPE_JPEG:
                 $thumbs[] = $this->video_dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION);
                 break;
         }
     }
     // Resize (if possible) and move images to the correct directory
     if (Video_Thumbnail::CanResize()) {
         $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
     } else {
         $this->thumbs = $this->video_dir->MoveFiles(Video_Dir::TEMP, Video_Dir::THUMBS, JPG_EXTENSION);
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
Пример #2
0
 public function PreProcess()
 {
     $this->video_dir = new Video_Dir(null, 0700);
     Request::FixFiles();
     if (!isset($_FILES[Video_Source::FIELD_UPLOADS])) {
         throw new BaseException('No files were uploaded');
     }
     foreach ($_FILES[Video_Source::FIELD_UPLOADS] as $upload) {
         // No file uploaded in this field
         if ($upload['error'] == UPLOAD_ERR_NO_FILE) {
             continue;
         }
         // Check for other errors
         if ($upload['error'] != UPLOAD_ERR_OK) {
             throw new BaseException(Uploads::CodeToMessage($upload['error']));
         }
         $thumbs = array();
         $will_grab = Video_Info::CanExtract() && Video_FrameGrabber::CanGrab();
         switch (File::Type($upload['name'])) {
             case File::TYPE_ZIP:
                 foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_JPEG) as $name => $data) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                 }
                 foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_VIDEO) as $name => $data) {
                     $this->clips[] = $this->video_dir->AddClipFromVar($data, File::Extension($name));
                 }
                 break;
             case File::TYPE_JPEG:
                 $thumbs[] = $this->video_dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION);
                 break;
             case File::TYPE_VIDEO:
                 $this->clips[] = $this->video_dir->AddClipFromFile($upload['tmp_name'], File::Extension($upload['name']));
                 break;
         }
     }
     // Make sure at least one video clip was uploaded
     if (empty($this->clips)) {
         throw new BaseException('No video files were uploaded');
     }
     // Try to grab frames from video files
     if ($will_grab) {
         $amount = round(Config::Get('thumb_amount') / count($this->clips));
         foreach ($this->clips as $clip) {
             $vi = new Video_Info($clip);
             $vi->Extract();
             $this->duration += $vi->length;
             $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'));
             // Move generated thumbs from the processing directory
             foreach ($temp_thumbs as $temp_thumb) {
                 $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb);
             }
             $this->video_dir->ClearProcessing();
         }
     } else {
         $this->duration = $this->source[Video_Source::FIELD_DURATION];
     }
     // Use uploaded images if none could be generated
     if (empty($this->thumbs) && !empty($thumbs)) {
         if (Video_Thumbnail::CanResize()) {
             $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
         } else {
             $this->thumbs = $this->video_dir->MoveFiles(Video_Dir::TEMP, Video_Dir::THUMBS, JPG_EXTENSION);
         }
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
Пример #3
0
 public function PreProcess()
 {
     $this->video_dir = new Video_Dir(null, 0700);
     $thumbs = array();
     $clips = array();
     foreach ($this->source[Video_Source::FIELD_URLS] as $url) {
         $url_path = parse_url($url, PHP_URL_PATH);
         switch (File::Type($url_path)) {
             case File::TYPE_ZIP:
                 $http = new HTTP();
                 if ($http->Get($url, $url)) {
                     $zip = $this->video_dir->AddTempFromVar($http->body, ZIP_EXTENSION);
                     foreach (Zip::ExtractEntries($zip, File::TYPE_JPEG) as $name => $data) {
                         $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                     }
                     foreach (Zip::ExtractEntries($zip, File::TYPE_VIDEO) as $name => $data) {
                         $this->clips[] = $this->video_dir->AddClipFromVar($data, File::Extension($name));
                     }
                 }
                 break;
             case File::TYPE_JPEG:
                 $http = new HTTP();
                 if ($http->Get($url, $url)) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($http->body, JPG_EXTENSION);
                 }
                 break;
             case File::TYPE_VIDEO:
                 if ($this->source[Video_Source::FLAG_HOTLINK]) {
                     $clips[] = $url;
                     $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
                 } else {
                     $http = new HTTP();
                     if ($http->Get($url, $url)) {
                         $this->clips[] = $this->video_dir->AddClipFromVar($http->body, File::Extension($http->url));
                     }
                 }
                 break;
         }
     }
     if (empty($clips)) {
         if (!empty($this->clips) && Video_Info::CanExtract() && Video_FrameGrabber::CanGrab()) {
             $amount = round(Config::Get('thumb_amount') / count($this->clips));
             foreach ($this->clips as $clip) {
                 $vi = new Video_Info($clip);
                 $vi->Extract();
                 $this->duration += $vi->length;
                 $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'));
                 // Move generated thumbs from the processing directory
                 foreach ($temp_thumbs as $temp_thumb) {
                     $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb);
                 }
                 $this->video_dir->ClearProcessing();
             }
         }
     } else {
         $this->clips = $clips;
     }
     if (empty($this->clips)) {
         throw new BaseException('No valid video URLs were submitted');
     }
     // Use images from supplied URLs if none could be generated
     if (empty($this->thumbs) && !empty($thumbs)) {
         if (Video_Thumbnail::CanResize()) {
             $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
         } else {
             $this->thumbs = $this->video_dir->MoveFiles($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), JPG_EXTENSION);
         }
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }