/** * Maintenance script to collect video data (local and premium videos) and insert into video_info table * Note: video data come from embedded premium videos, local videos, and related videos (related videos list and global list) * Default setting: create video_info table, remove deleted videos (local) and add videos * @author Liz Lee, Saipetch Kongkatong */ function addVideo(&$videoList, $titleName) { global $dryrun, $added, $invalid, $duplicate, $dupInDb; $videoInfoHelper = new VideoInfoHelper(); $videoData = $videoInfoHelper->getVideoDataFromTitle($titleName); if (!empty($videoData)) { printText($videoData['videoTitle']); $titleHash = md5($videoData['videoTitle']); if (!in_array($titleHash, $videoList)) { $status = true; if (!$dryrun) { $videoInfo = new VideoInfo($videoData); $status = $videoInfo->addVideo(); } if ($status) { $added++; printText("..... ADDED.\n"); } else { $dupInDb++; printText("..... ALREADY ADDED TO DB.\n"); } $videoList[] = $titleHash; } else { $duplicate++; printText("..... ALREADY ADDED.\n"); } } else { $invalid++; printText("{$titleName}..... INVALID.\n"); } }
/** * Check the file passed and fail if its a ghost file; that is, a file * that is from the video wiki but doesn't have any local record * * @param File $file A file object to check * @return bool Whether this hook has succeeded */ public static function onCheckGhostFile(&$file) { # If we're on a file page and we don't have any video_info for the current # title, treat it like a non-existent file if ($file && WikiaFileHelper::isFileTypeVideo($file)) { $title = $file->getTitle()->getDBkey(); $info = VideoInfo::newFromTitle($title); if (empty($info)) { F::app()->wg->IsGhostVideo = true; $file = null; } } return true; }
/** * Trigger the video conversion */ function video_conversion_cron($hook, $entity_type, $returnvalue, $params) { $ia = elgg_set_ignore_access(true); $videos = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'video', 'limit' => 2, 'metadata_name_value_pairs' => array('name' => 'conversion_done', 'value' => 0))); elgg_load_library('elgg:video'); foreach ($videos as $video) { $sources = $video->getSources(); $success = true; foreach ($sources as $source) { // Converted sources may exist if previous conversion has been interrupted if ($source->conversion_done == true) { continue; } try { $filename = $source->getFilenameOnFilestore(); // Create a new video file to data directory $converter = new VideoConverter(); $converter->setInputFile($video->getFilenameOnFilestore()); $converter->setOutputFile($filename); $converter->setResolution($source->resolution); $converter->setBitrate($source->bitrate); $result = $converter->convert(); // Save video details $info = new VideoInfo($source); $source->resolution = $info->getResolution(); $source->bitrate = $info->getBitrate(); $source->conversion_done = true; $source->save(); echo "<p>Successfully created video file {$source->getFilename()}</p>"; } catch (Exception $e) { // Print simple error to screen echo "<p>Failed to create video file {$source->getFilename()}</p>"; $success = false; // Print detailed error to error log $message = elgg_echo('VideoException:ConversionFailed', array($filename, $e->getMessage(), $converter->getCommand())); error_log($message); elgg_add_admin_notice('conversion_error', $message); } } if ($success) { $video->conversion_done = true; add_to_river('river/object/video/create', 'create', $video->getOwnerGUID(), $video->getGUID()); } } elgg_set_ignore_access($ia); return $returnvalue; }
/** * @param $video - Video to flag in the video_info table * @param $removeVideo - Boolean, whether the video should be deleted or not * Flag removed status of video in the video_info table. All videos which have some sort of error * (deleted, private, or other), are flagged as removed, all working videos are flagged as not removed. */ private function setRemovedValue($video, $removeVideo) { $videoInfo = VideoInfo::newFromTitle($video['video_title']); if (is_null($videoInfo)) { $videoInfoHelper = new VideoInfoHelper(); $videoTitle = Title::newFromText($video['video_title'], NS_FILE); $videoInfo = $videoInfoHelper->getVideoInfoFromTitle($videoTitle); $videoInfo->addVideo(); } if ($removeVideo) { if (!$videoInfo->isRemoved()) { $videoInfo->removeVideo(); } } else { if ($videoInfo->isRemoved()) { $videoInfo->restoreVideo(); } } $removedStatus = $removeVideo ? "removed" : "not removed"; $this->debug("Video set as {$removedStatus}: " . $video['video_title']); }
// Open the video to guarantee the directory exists $video->open("write"); $video->close(); move_uploaded_file($_FILES['upload']['tmp_name'], $video->getFilenameOnFilestore()); // Change the directory mode chmod($video->getFileDirectory(), 0775); $guid = $video->save(); } // video saved so clear sticky form elgg_clear_sticky_form('video'); // handle results differently for new videos and video updates if ($new_video) { if ($guid) { elgg_load_library('elgg:video'); // Find out file info and save it as metadata $info = new VideoInfo($video); $video->resolution = $info->getResolution(); $video->bitrate = $info->getBitrate(); $video->duration = $info->getDuration(); // Mark the video as unconverted so conversion script can find it $video->conversion_done = false; $video->save(); $video->setSources(); video_create_thumbnails($video); $message = elgg_echo("video:saved"); system_message($message); } else { // failed to save video object - nothing we can do about this $error = elgg_echo("video:uploadfailed"); register_error($error); }
/** * Check if the premium video is added to the wiki * @param File $file * @return boolean $isAdded */ public static function isAdded($file) { $isAdded = true; if ($file instanceof File && !$file->isLocal() && F::app()->wg->WikiaVideoRepoDBName == $file->getRepo()->getWiki()) { $info = VideoInfo::newFromTitle($file->getTitle()->getDBkey()); if (empty($info)) { $isAdded = false; } } return $isAdded; }
/** * Override the getUser method for foreign files to return the user that originally added the * video rather than the one who uploaded it to the foreign repo * @param string $type * @return int|string */ public function getUser($type = 'text') { // Try to get video info for this file $info = VideoInfo::newFromTitle($this->getName()); if (!empty($info)) { $addedBy = $info->getAddedBy(); } // If we got an addedBy user ID, use that otherwise fall back to the parent method if (!empty($addedBy)) { if ($type == 'text') { $user = User::newFromId($addedBy); if ($user instanceof User) { return $user->getName(); } } else { return $addedBy; } } return parent::getUser($type); }
/** * restore premium video * @param Title $title * @param integer $userId * @return boolean $affected */ public function restorePremiumVideo($title, $userId) { wfProfileIn(__METHOD__); $affected = false; if ($title instanceof Title) { $videoInfo = VideoInfo::newFromTitle($title->getDBKey()); if (empty($videoInfo)) { $newVideoInfo = $this->getVideoInfoFromTitle($title, true); if (!empty($newVideoInfo)) { // add premium video if not exist $affected = $newVideoInfo->addPremiumVideo($userId); } } else { $affected = $videoInfo->restoreVideo(); } } wfProfileOut(__METHOD__); return $affected; }