예제 #1
0
 public static function Run()
 {
     chdir(realpath(dirname(__FILE__) . '/../'));
     require_once 'includes/global.php';
     $doc_root = Config::Get('document_root');
     $DB = GetDB();
     self::Log('Starting...');
     self::MarkRunning();
     while (true) {
         // See if we were requested to stop
         if (self::ShouldStop()) {
             self::Log('User requested stop...');
             break;
         }
         self::Ping();
         $DB->Connect();
         $queue_item = $DB->Row('SELECT * FROM `tbx_thumb_queue` ORDER BY `queued` LIMIT 1');
         if (!empty($queue_item)) {
             $video = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($queue_item['video_id']));
             if (!empty($video)) {
                 $DB->Update('UPDATE `tbx_thumb_queue` SET `date_started`=? WHERE `video_id`=?', array(Database_MySQL::Now(), $video['video_id']));
                 $clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=? AND `type`!=? ORDER BY `clip_id`', array($queue_item['video_id'], 'Embed'));
                 $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
                 Video_FrameGrabber::SetLogFile($dir->GetBaseDir() . '/thumbnailer.log');
                 $thumb_start = time();
                 try {
                     if (!empty($clips)) {
                         $thumbs = array();
                         $duration = 0;
                         // Number of thumbs to create per clip
                         $amount = round(Config::Get('thumb_amount') / count($clips));
                         // Move existing thumbnails
                         $dir->MoveFiles($dir->GetThumbsDir(), $dir->GetTempDir(), JPG_EXTENSION);
                         // Process each clip
                         foreach ($clips as $clip) {
                             self::Ping();
                             // Remote video
                             if (preg_match('~https?://~i', $clip['clip'])) {
                                 $http = new HTTP();
                                 if ($http->Get($clip['clip'], $clip['clip'])) {
                                     $video_file = $dir->AddOriginalFromVar($http->body, File::Extension($clip['clip']));
                                     $vi = new Video_Info($video_file);
                                     $vi->Extract();
                                     $duration += $vi->length;
                                     $temp_thumbs = Video_FrameGrabber::Grab($video_file, $dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'), $vi);
                                     // Move generated thumbs from the processing directory
                                     foreach ($temp_thumbs as $temp_thumb) {
                                         $thumbs[] = $dir->AddThumbFromFile($temp_thumb);
                                     }
                                     @unlink($video_file);
                                 }
                             } else {
                                 $temp_thumbs = Video_FrameGrabber::Grab($doc_root . '/' . $clip['clip'], $dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'));
                                 // Move generated thumbs from the processing directory
                                 foreach ($temp_thumbs as $temp_thumb) {
                                     $thumbs[] = $dir->AddThumbFromFile($temp_thumb);
                                 }
                             }
                         }
                         // Get the relative URL for each thumb and add to database
                         $thumb_ids = array();
                         foreach ($thumbs as $thumb) {
                             $thumb = str_replace($doc_root, '', $thumb);
                             $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => $thumb));
                         }
                         // Determine number of thumbnails and select random display thumbnail
                         $num_thumbnails = count($thumbs);
                         $display_thumbnail = null;
                         if ($num_thumbnails > 0) {
                             // Select display thumbnail randomly from the first 40%
                             $display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))];
                         }
                         $update = array('video_id' => $video['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail);
                         if (empty($video['duration']) && !empty($duration)) {
                             $update['duration'] = $duration;
                         }
                         DatabaseUpdate('tbx_video', $update);
                         // Remove old thumbnails
                         $DB->Update('DELETE FROM `tbx_video_thumbnail` WHERE `video_id`=?' . (!empty($thumb_ids) ? ' AND`thumbnail_id` NOT IN (' . join(',', $thumb_ids) . ')' : ''), array($video['video_id']));
                         $dir->ClearTemp();
                     }
                 } catch (Exception $e) {
                     // Restore old thumbnails
                     $dir->MoveFiles($dir->GetTempDir(), $dir->GetThumbsDir(), JPG_EXTENSION);
                     Video_FrameGrabber::Log($e->getMessage() . (strtolower(get_class($e)) == 'baseexception' ? $e->getExtras() : '') . "\n" . $e->getTraceAsString());
                     self::UpdateStatsProcessed($thumb_start, $thumb_end, $queue_item['queued'], true);
                 }
                 $thumb_end = time();
                 $DB->Update('DELETE FROM `tbx_thumb_queue` WHERE `video_id`=?', array($queue_item['video_id']));
                 self::UpdateStatsProcessed($thumb_start, $thumb_end, $queue_item['queued']);
             }
         } else {
             break;
         }
     }
     self::MarkStopped();
     self::Log('Exiting...');
 }
예제 #2
0
 public static function Run()
 {
     chdir(realpath(dirname(__FILE__) . '/../'));
     require_once 'includes/global.php';
     $doc_root = Config::Get('document_root');
     $DB = GetDB();
     self::Log('Starting...');
     self::MarkRunning();
     while (true) {
         // See if we were requested to stop
         if (self::ShouldStop()) {
             self::Log('User requested stop...');
             break;
         }
         self::Ping();
         $DB->Connect();
         $queue_item = $DB->Row('SELECT *,`tbx_conversion_queue`.`video_id` AS `video_id`,`tbx_conversion_queue`.`queued` AS `queued` FROM `tbx_conversion_queue` LEFT JOIN ' . '`tbx_thumb_queue` USING (`video_id`) WHERE `tbx_thumb_queue`.`video_id` IS NULL ORDER BY `tbx_conversion_queue`.`queued` LIMIT 1');
         if (!empty($queue_item)) {
             $video = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($queue_item['video_id']));
             if (!empty($video)) {
                 $DB->Update('UPDATE `tbx_video` SET `conversion_failed`=0 WHERE `video_id`=?', array($video['video_id']));
                 $DB->Update('UPDATE `tbx_conversion_queue` SET `date_started`=? WHERE `video_id`=?', array(Database_MySQL::Now(), $video['video_id']));
                 $clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=? ORDER BY `clip_id`', array($queue_item['video_id']));
                 $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
                 Video_Converter::SetLogFile($dir->GetBaseDir() . '/convert.log');
                 $convert_start = time();
                 $conversion_failed = false;
                 foreach ($clips as $clip) {
                     $clip_path = null;
                     $old_path = null;
                     try {
                         // Stored locally, move to originals directory
                         if ($clip['clip'][0] == '/') {
                             $old_path = $doc_root . $clip['clip'];
                             $clip_path = $dir->AddOriginalFromFile($old_path);
                         } else {
                             $http = new HTTP();
                             if ($http->Get($clip['clip'], $clip['clip'])) {
                                 $clip_path = $dir->AddOriginalFromVar($http->body, File::Extension($clip['clip']));
                             } else {
                                 throw new BaseException('Could not download clip for conversion: ' . $http->error);
                             }
                         }
                         $output_file = Video_Converter::Convert($clip_path, $dir->GetProcessingDir(), Config::Get('video_format'), Config::Get('video_bitrate'), Config::Get('audio_bitrate'), Config::Get('video_size'), array('ConversionQueue', 'Ping'));
                         $converted_video = $dir->AddClipFromFile($output_file);
                         $DB->Disconnect();
                         $DB->Connect();
                         $DB->Update('UPDATE `tbx_video_clip` SET `clip`=?,`filesize`=? WHERE `clip_id`=?', array(str_replace($doc_root, '', $converted_video), filesize($converted_video), $clip['clip_id']));
                     } catch (Exception $e) {
                         if (!empty($old_path) && !empty($clip_path)) {
                             rename($clip_path, $old_path);
                         }
                         Video_Converter::Log($e->getMessage() . (strtolower(get_class($e)) == 'baseexception' ? $e->getExtras() : '') . "\n" . $e->getTraceAsString());
                         $conversion_failed = true;
                     }
                 }
                 $convert_end = time();
                 $dir->ClearProcessing();
                 $dir->ClearTemp();
                 $DB->Connect();
                 $DB->Update('DELETE FROM `tbx_conversion_queue` WHERE `video_id`=?', array($queue_item['video_id']));
                 if ($conversion_failed) {
                     self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued'], true);
                     $DB->Update('UPDATE `tbx_video` SET `conversion_failed`=1 WHERE `video_id`=?', array($video['video_id']));
                 } else {
                     // Update stats
                     self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued']);
                     $status = empty($video['next_status']) ? STATUS_ACTIVE : $video['next_status'];
                     // Set video status
                     $DB->Update('UPDATE `tbx_video` SET `status`=? WHERE `video_id`=?', array($status, $video['video_id']));
                     if ($video['status'] != $status && $status == STATUS_ACTIVE && !$video['is_private']) {
                         Tags::AddToFrequency($video['tags']);
                     }
                     UpdateCategoryStats($video['category_id']);
                 }
             }
         } else {
             break;
         }
     }
     self::MarkStopped();
     self::Log('Exiting...');
 }
예제 #3
0
 public function Import()
 {
     $imported = 0;
     $DB = GetDB();
     $yt = new Zend_Gdata_YouTube();
     $video_feed = $yt->getVideoFeed($this->feed['feed_url']);
     $entry;
     foreach ($video_feed as $entry) {
         // Check for duplicates, and skip
         if ($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_feed_history` WHERE `feed_id`=? AND `unique_id`=?', array($this->feed['feed_id'], $entry->getVideoId()))) {
             continue;
         }
         // Video is not embeddable, skip
         if (!$entry->isVideoEmbeddable()) {
             continue;
         }
         // Setup defaults
         $video = $this->defaults;
         $video['title'] = $entry->getVideoTitle();
         $video['description'] = $entry->getVideoDescription();
         $video['tags'] = Tags::Format(implode(' ', $entry->getVideoTags()));
         $video['duration'] = $entry->getVideoDuration();
         // Get preview images
         $times = array();
         $thumbs = array();
         foreach ($entry->getVideoThumbnails() as $thumb) {
             if (!isset($times[$thumb['time']])) {
                 $times[$thumb['time']] = true;
                 $thumbs[] = array('thumbnail' => $thumb['url']);
             }
         }
         $clip = array('type' => 'Embed', 'clip' => '<object width="640" height="385">' . '<param name="movie" value="http://www.youtube.com/v/' . $entry->getVideoId() . '&fs=1"></param>' . '<param name="allowFullScreen" value="true"></param>' . '<param name="allowscriptaccess" value="always"></param>' . '<embed src="http://www.youtube.com/v/' . $entry->getVideoId() . '&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="640" height="385"></embed>' . '</object>');
         $best_category = GetBestCategory(join(' ', array($video['title'], $video['description'], $video['tags'])));
         if (!empty($best_category)) {
             $video['category_id'] = $best_category;
         }
         $video['video_id'] = DatabaseAdd('tbx_video', $video);
         DatabaseAdd('tbx_video_custom', $video);
         DatabaseAdd('tbx_video_stat', $video);
         if (!$video['is_private']) {
             Tags::AddToFrequency($video['tags']);
         }
         UpdateCategoryStats($video['category_id']);
         $video_dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
         $clip['video_id'] = $video['video_id'];
         DatabaseAdd('tbx_video_clip', $clip);
         $display_thumbnail = null;
         foreach ($thumbs as $thumb) {
             $thttp = new HTTP();
             if ($thttp->Get($thumb['thumbnail'], $thumb['thumbnail'])) {
                 $temp_file = $video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION);
                 $imgsize = @getimagesize($temp_file);
                 if ($imgsize !== false) {
                     if (Video_Thumbnail::CanResize()) {
                         $local_filename = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $video_dir->GetThumbsDir());
                     } else {
                         $local_filename = $video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION);
                     }
                     $local_filename = str_replace(Config::Get('document_root'), '', $local_filename);
                     $thumb_id = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => $local_filename));
                     if (empty($display_thumbnail)) {
                         $display_thumbnail = $thumb_id;
                     }
                 } else {
                     unlink($temp_file);
                 }
             }
         }
         if (!empty($display_thumbnail)) {
             $DB->Update('UPDATE `tbx_video` SET `display_thumbnail`=? WHERE `video_id`=?', array($display_thumbnail, $video['video_id']));
         }
         $DB->Update('INSERT INTO `tbx_video_feed_history` VALUES (?,?)', array($this->feed['feed_id'], $entry->getVideoId()));
         $imported++;
     }
     $DB->Update('UPDATE `tbx_video_feed` SET `date_last_read`=? WHERE `feed_id`=?', array(Database_MySQL::Now(), $this->feed['feed_id']));
     UpdateSponsorStats($this->feed['sponsor_id']);
     return $imported;
 }
예제 #4
0
 function getHTTP($url)
 {
     // Use wfGetHTTP from MW 1.5 if it is available
     global $IP;
     include_once "{$IP}/includes/HttpFunctions.php";
     wfSuppressWarnings();
     if (class_exists('HTTP')) {
         $text = HTTP::Get($url);
     } else {
         if (function_exists('wfGetHTTP')) {
             $text = wfGetHTTP($url);
         } else {
             $url_fopen = ini_set('allow_url_fopen', 1);
             $text = file_get_contents($url);
             ini_set('allow_url_fopen', $url_fopen);
         }
     }
     wfRestoreWarnings();
     return $text;
 }
예제 #5
0
파일: Import.php 프로젝트: hackingman/TubeX
 public static function Import($settings)
 {
     $DB = GetDB();
     ProgressBarShow('pb-import');
     $file = TEMP_DIR . '/' . File::Sanitize($settings['import_file']);
     $fp = fopen($file, 'r');
     $filesize = filesize($file);
     $line = $read = $imported = 0;
     $expected = count($settings['fields']);
     while (!feof($fp)) {
         $line++;
         $string = fgets($fp);
         $read += strlen($string);
         $data = explode($settings['delimiter'], trim($string));
         ProgressBarUpdate('pb-import', $read / $filesize * 100);
         // Line does not have the expected number of fields
         if (count($data) != $expected) {
             continue;
         }
         $video = array();
         $defaults = array('category_id' => $settings['category_id'], 'sponsor_id' => $settings['sponsor_id'], 'username' => $settings['username'], 'duration' => Format::DurationToSeconds($settings['duration']), 'status' => $settings['status'], 'next_status' => $settings['status'], 'allow_comments' => $settings['allow_comments'], 'allow_ratings' => $settings['allow_ratings'], 'allow_embedding' => $settings['allow_embedding'], 'is_private' => $settings['is_private'], 'date_added' => Database_MySQL::Now(), 'is_featured' => 0, 'is_user_submitted' => 0, 'conversion_failed' => 0, 'tags' => null, 'title' => null, 'description' => null);
         foreach ($settings['fields'] as $index => $field) {
             if (!empty($field)) {
                 $video[$field] = trim($data[$index]);
             }
         }
         // Setup clips
         $clips = array();
         $thumbs = array();
         $clip_type = 'URL';
         if (isset($video['embed_code'])) {
             // Cannot convert or thumbnail from embed code
             $settings['flag_convert'] = $settings['flag_thumb'] = false;
             $clips[] = $video['embed_code'];
             $clip_type = 'Embed';
         } else {
             if (isset($video['gallery_url'])) {
                 $http = new HTTP();
                 if (!$http->Get($video['gallery_url'])) {
                     // Broken gallery URL, continue
                     continue;
                 }
                 list($thumbs, $clips) = Video_Source_Gallery::ExtractUrls($http->url, $http->body);
             } else {
                 if (!isset($video['video_url']) && isset($video['base_video_url'])) {
                     if (!preg_match('~/$~', $video['base_video_url'])) {
                         $video['base_video_url'] .= '/';
                     }
                     foreach (explode(',', $video['video_filename']) as $filename) {
                         $clips[] = $video['base_video_url'] . $filename;
                     }
                 } else {
                     $clips[] = $video['video_url'];
                 }
             }
         }
         // Check for duplicate clips
         $duplicate = false;
         foreach ($clips as $clip) {
             if (!Request::Get('flag_skip_imported_check') && $DB->QueryCount('SELECT COUNT(*) FROM `tbx_imported` WHERE `video_url`=?', array($clip)) > 0) {
                 $duplicate = true;
             }
             $DB->Update('REPLACE INTO `tbx_imported` VALUES (?)', array($clip));
         }
         // Dupe found
         if ($duplicate) {
             continue;
         }
         // Setup thumbs
         if (!isset($video['gallery_url']) && !isset($video['thumbnail_url']) && isset($video['base_thumbnail_url'])) {
             if (!preg_match('~/$~', $video['base_thumbnail_url'])) {
                 $video['base_thumbnail_url'] .= '/';
             }
             foreach (explode(',', String::FormatCommaSeparated($video['thumbnail_filename'])) as $filename) {
                 $thumbs[] = $video['base_thumbnail_url'] . $filename;
             }
         } else {
             if (!isset($video['gallery_url']) && isset($video['thumbnail_url'])) {
                 $thumbs[] = $video['thumbnail_url'];
             }
         }
         // Setup duration
         if (isset($video['duration_seconds'])) {
             $video['duration'] = $video['duration_seconds'];
         } else {
             if (isset($video['duration_formatted'])) {
                 $video['duration'] = Format::DurationToSeconds($video['duration_formatted']);
             }
         }
         // Use description for title
         if (empty($video['title'])) {
             $video['title'] = isset($video['description']) ? $video['description'] : '';
         }
         // Use title for description
         if (empty($video['description'])) {
             $video['description'] = isset($video['title']) ? $video['title'] : '';
         }
         // Use title for tags
         if (empty($video['tags'])) {
             $video['tags'] = isset($video['title']) ? $video['title'] : '';
         }
         // Setup category
         if (isset($video['category']) && ($category_id = $DB->QuerySingleColumn('SELECT `category_id` FROM `tbx_category` WHERE `name` LIKE ?', array($video['category']))) !== false) {
             $video['category_id'] = $category_id;
         } else {
             if (($category_id = GetBestCategory($video['title'] . ' ' . $video['description'])) !== null) {
                 $video['category_id'] = $category_id;
             }
         }
         // Merge in the defaults
         $video = array_merge($defaults, $video);
         // Format tags and convert to UTF-8
         $video['tags'] = Tags::Format($video['tags']);
         $video = String::ToUTF8($video);
         if (Request::Get('flag_convert')) {
             $video['status'] = STATUS_QUEUED;
         }
         // Add to database
         $video['video_id'] = DatabaseAdd('tbx_video', $video);
         DatabaseAdd('tbx_video_custom', $video);
         DatabaseAdd('tbx_video_stat', $video);
         if ($video['is_private']) {
             $video['private_id'] = sha1(uniqid(mt_rand(), true));
             DatabaseAdd('tbx_video_private', $video);
         }
         if ($video['status'] == STATUS_QUEUED) {
             $video['queued'] = time();
             DatabaseAdd('tbx_conversion_queue', $video);
         }
         if (Request::Get('flag_thumb')) {
             $video['queued'] = time();
             DatabaseAdd('tbx_thumb_queue', $video);
         }
         if ($video['status'] == STATUS_ACTIVE && !$video['is_private']) {
             Tags::AddToFrequency($video['tags']);
         }
         // Add clips
         foreach ($clips as $clip) {
             DatabaseAdd('tbx_video_clip', array('video_id' => $video['video_id'], 'type' => $clip_type, 'clip' => $clip));
         }
         $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
         // Process thumbs
         $thumb_ids = array();
         foreach ($thumbs as $thumb) {
             $http = new HTTP();
             if ($http->Get($thumb, $thumb)) {
                 if (Video_Thumbnail::CanResize()) {
                     $thumb_temp = $dir->AddTempFromVar($http->body, 'jpg');
                     $thumb_file = Video_Thumbnail::Resize($thumb_temp, Config::Get('thumb_size'), Config::Get('thumb_quality'), $dir->GetThumbsDir());
                 } else {
                     $thumb_file = $dir->AddThumbFromVar($http->body);
                 }
                 if (!empty($thumb_file)) {
                     $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => str_replace(Config::Get('document_root'), '', $thumb_file)));
                 }
             }
         }
         // Determine number of thumbnails and select random display thumbnail
         $num_thumbnails = count($thumb_ids);
         $display_thumbnail = null;
         if ($num_thumbnails > 0) {
             // Select display thumbnail randomly from the first 40%
             $display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))];
         }
         DatabaseUpdate('tbx_video', array('video_id' => $video['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail));
         $imported++;
     }
     fclose($fp);
     UpdateCategoryStats();
     UpdateSponsorStats($settings['sponsor_id']);
     $t = new Template();
     $t->ClearCache('categories.tpl');
     ProgressBarHide('pb-import', NumberFormatInteger($imported) . ' videos have been imported!');
     // Start up the thumbnail and converson queues if needed
     if (!Config::Get('flag_using_cron')) {
         if (Request::Get('flag_convert')) {
             ConversionQueue::Start();
         }
         if (Request::Get('flag_thumb')) {
             ThumbQueue::Start();
         }
     }
     File::Delete($file);
 }
예제 #6
0
파일: URL.php 프로젝트: hackingman/TubeX
 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();
 }
예제 #7
0
 public function PreProcess()
 {
     $this->video_dir = new Video_Dir(null, 0700);
     $http = new HTTP();
     if (!$http->Get($this->source[Video_Source::FIELD_GALLERY])) {
         throw new BaseException('Could not access gallery: ' . $http->error);
     }
     list($thumbs, $clips) = self::ExtractUrls($http->url, $http->body);
     if (empty($clips)) {
         throw new BaseException('No video files could be located on this gallery');
     }
     // Hotlinking video from gallery
     if ($this->source[Video_Source::FLAG_HOTLINK]) {
         $this->clips = $clips;
         $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
     } else {
         // Download clips
         $amount = round(Config::Get('thumb_amount') / count($clips));
         foreach ($clips as $clip) {
             $chttp = new HTTP();
             if ($chttp->Get($clip, $http->url)) {
                 $clip = $this->video_dir->AddClipFromVar($chttp->body, File::Extension($chttp->url));
                 $this->clips[] = $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();
             }
         }
     }
     // Download thumbs from gallery if none could be created from the video files
     // or video files are being hotlinked
     if (empty($this->thumbs)) {
         foreach ($thumbs as $thumb) {
             $coords = null;
             if (preg_match('~^\\[(.*?)\\](.*)~', $thumb, $matches)) {
                 $coords = $matches[1];
                 $thumb = $matches[2];
             }
             $thttp = new HTTP();
             if ($thttp->Get($thumb, $http->url)) {
                 $temp_file = $this->video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION);
                 $imgsize = @getimagesize($temp_file);
                 $aspect = $imgsize !== false ? $imgsize[0] / $imgsize[1] : 0;
                 if ($imgsize !== false && $aspect >= self::MIN_ASPECT && $aspect <= self::MAX_ASPECT) {
                     if (Video_Thumbnail::CanResize()) {
                         $this->thumbs[] = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $this->video_dir->GetThumbsDir(), $coords);
                     } else {
                         $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION);
                     }
                 } else {
                     unlink($temp_file);
                 }
             }
         }
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
예제 #8
0
 public function Test()
 {
     $http = new HTTP();
     if ($http->Get($this->feed['feed_url'])) {
         $xml = simplexml_load_string($this->ToUTF8($http->body), 'XML_Element', LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOCDATA);
         if ($xml !== false) {
             $xvideos = $xml->xpath('/videos');
             $xvideo = $xml->xpath('/videos/video');
             $xclips = $xml->xpath('/videos/video/clips');
             if (empty($xvideos) || empty($xvideo) || empty($xclips)) {
                 throw new BaseException('Sorry, this is not a valid Videos XML feed');
             }
         } else {
             $error = libxml_get_last_error();
             throw new BaseException('Invalid XML: ' . $error->message);
         }
     } else {
         throw new BaseException('Bad URL: ' . $http->error);
     }
 }