public function index() { if ($this->wg->user->isBlocked()) { $this->wg->out->blockedPage(); return false; // skip rendering } if (!$this->wg->user->isAllowed('specialvideohandler')) { $this->displayRestrictionError(); return false; } if (wfReadOnly() && !wfAutomaticReadOnly()) { $this->wg->out->readOnlyPage(); return false; } $videoId = $this->getVal('videoid', null); $provider = strtolower($this->getVal('provider', null)); $undercover = $this->getVal('undercover', false); $videoTitle = $this->getVal('videotitle', null); if ($videoId && $provider) { $overrideMetadata = array(); if (!empty($videoTitle)) { $overrideMetadata['title'] = $videoTitle; } try { $result = VideoFileUploader::uploadVideo($provider, $videoId, $title, null, $undercover, $overrideMetadata); } catch (Exception $e) { $result = (object) array('ok' => null, 'value' => null); } $this->setVal('uploadStatus', $result->ok); $this->setVal('isNewFile', empty($result->value)); $this->setVal('title', !empty($title) ? $title->getText() : ''); $this->setVal('url', !empty($title) ? $title->getFullURL() : ''); } }
public function createVideo(array $data, &$msg, $params = array()) { wfProfileIn(__METHOD__); $debug = !empty($params['debug']); $ignoreRecent = !empty($params['ignorerecent']) ? $params['ignorerecent'] : 0; if ($debug) { print "data after initial processing: \n"; foreach (explode("\n", var_export($data, 1)) as $line) { print ":: {$line}\n"; } } $addlCategories = !empty($params['addlCategories']) ? $params['addlCategories'] : array(); $id = $data['videoId']; $name = $this->generateName($data); $metadata = $this->generateMetadata($data, $msg); if (!empty($msg)) { print "Error when generating metadata\n"; var_dump($msg); wfProfileOut(__METHOD__); return 0; } $duplicates = WikiaFileHelper::findVideoDuplicates(static::$PROVIDER, $id); $dup_count = count($duplicates); $previousFile = null; if ($dup_count > 0) { if ($this->reupload === false) { // if reupload is disabled finish now if ($debug) { print "Not uploading - video already exists and reupload is disabled\n"; } return 0; } // if there are duplicates use name of one of them as reference // instead of generating new one $name = $duplicates[0]['img_name']; echo "Video already exists, using it's old name: {$name}\n"; $previousFile = Title::newFromText($name, NS_FILE); } else { // sanitize name $name = VideoFileUploader::sanitizeTitle($name); // make sure the name is unique $name = $this->getUniqueName($name); } $metadata['destinationTitle'] = $name; if (!$this->validateTitle($id, $name, $msg, $debug)) { wfProfileOut(__METHOD__); return 0; } // prepare wiki categories string (eg [[Category:MyCategory]] ) $categories = $this->generateCategories($data, $addlCategories); $categories[] = wfMsgForContent('videohandler-category'); $categories = array_unique($categories); $categoryStr = ''; foreach ($categories as $categoryName) { $category = Category::newFromName($categoryName); if ($category instanceof Category) { $categoryStr .= '[[' . $category->getTitle()->getFullText() . ']]'; } } // parepare article body $apiWrapper = new static::$API_WRAPPER($id, $metadata); $descriptionHeader = '==' . F::app()->wf->Msg('videohandler-description') . '=='; $body = $categoryStr . "\n" . $descriptionHeader . "\n" . $apiWrapper->getDescription(); if ($debug) { print "Ready to create video\n"; print "id: {$id}\n"; print "name: {$name}\n"; print "categories: " . implode(',', $categories) . "\n"; print "metadata:\n"; foreach (explode("\n", var_export($metadata, 1)) as $line) { print ":: {$line}\n"; } print "body:\n"; foreach (explode("\n", $body) as $line) { print ":: {$line}\n"; } wfProfileOut(__METHOD__); return 1; } else { if (!empty($ignoreRecent) && !is_null($previousFile)) { $revId = $previousFile->getLatestRevID(); $revision = Revision::newFromId($revId); $time = $revision->getTimestamp(); $timeUnix = intval(wfTimestamp(TS_UNIX, $time)); $timeNow = intval(wfTimestamp(TS_UNIX, time())); if ($timeUnix + $ignoreRecent >= $timeNow) { print "Recently uploaded, ignoring\n"; return 0; } } $uploadedTitle = null; $result = VideoFileUploader::uploadVideo(static::$PROVIDER, $id, $uploadedTitle, $body, false, $metadata); if ($result->ok) { $fullUrl = WikiFactory::getLocalEnvURL($uploadedTitle->getFullURL()); print "Ingested {$uploadedTitle->getText()} from partner clip id {$id}. {$fullUrl}\n\n"; wfWaitForSlaves(self::THROTTLE_INTERVAL); wfProfileOut(__METHOD__); return 1; } } wfProfileOut(__METHOD__); return 0; }
/** * After all the video meta data and categories have been prepared, upload the video * onto Wikia. * @return int */ public function saveVideo() { $body = $this->prepareBodyString(); if ($this->debugMode()) { $this->printReadyToSaveData($body); $msg = "Ingested {$this->metaData['destinationTitle']} (id: {$this->metaData['videoId']}).\n"; $this->logger->videoIngested($msg, $this->pageCategories); return 1; } else { /** @var Title $uploadedTitle */ $uploadedTitle = null; $result = VideoFileUploader::uploadVideo($this->metaData['provider'], $this->metaData['videoId'], $uploadedTitle, $body, false, $this->metaData); if ($result->ok) { $fullUrl = WikiFactory::getLocalEnvURL($uploadedTitle->getFullURL()); $msg = "Ingested {$uploadedTitle->getText()} from partner clip id {$this->metaData['videoId']}. {$fullUrl}\n"; $this->logger->videoIngested($msg, $this->pageCategories); wfWaitForSlaves(); wfRunHooks('VideoIngestionComplete', [$uploadedTitle, $this->pageCategories]); return 1; } } $this->logger->videoWarnings(); return 0; }
$file = wfFindFile( $title ); $img = $file->getFullUrl(); $article = Article::newFromID($title->getArticleID()); $body = $article->getContent(); echo "$w\t$h\t$aspect\t$url\t$img\n"; // fake the upload $metadata = unserialize($file->getMetadata()); if( $metadata['aspectRatio'] > 1.7 ) { echo $metadata['aspectRatio'] . "<- skipping\n"; continue; } else { echo $metadata['aspectRatio'] . "<- previous ratio\n"; } $metadata['aspectRatio'] = 1.7777778; $apiWrapper = new ScreenplayApiWrapper($name, $metadata); $uploadedTitle = null; //$descriptionHeader = '==' . F::app()->wf->Msg('videohandler-description') . '=='; //$body = $categoryStr."\n".$descriptionHeader."\n".$apiWrapper->getDescription(); $result = VideoFileUploader::uploadVideo('screenplay', $name, $uploadedTitle, $body, false); if ($result->ok) { echo "reupload OK\n"; } else { echo "reupload failed\n"; } sleep(5); } } }