public function execute() { $this->verbose = $this->hasOption("verbose"); $this->dryRun = $this->hasOption("dryRun"); $this->limit = $this->getOption("limit", self::BATCH_SIZE); $titles = $this->getScreenplayTitles(); $ooyalaAsset = new OoyalaAsset(); if ($this->dryRun) { echo "Dry run...\n"; } foreach ($titles as $title) { $videoFile = WikiaFileHelper::getVideoFileFromTitle($title); if (empty($videoFile)) { $this->log("Skipping video '{$title}' -- couldn't find video file"); $this->skippedVideos++; continue; } $ooyalaData = $this->prepForOoyala($videoFile); if ($this->dryRun) { echo "Ready to migrate video " . $videoFile->getName() . " to Ooyala with the following data:\n"; print_r($ooyalaData); $success = true; $videoId = "TestID"; } else { // $videoId gets set in addRemoteAsset() $success = $ooyalaAsset->addRemoteAsset($ooyalaData, $videoId); } if (!$success) { $this->log("Error uploading video {$ooyalaData['assetTitle']} onto Ooyala. Skipping update locally"); $this->skippedVideos++; continue; } $localData = $this->prepForLocal($videoFile, $ooyalaData, $videoId); if ($this->dryRun) { echo "Ready to update video " . $videoFile->getName() . " locally with the following new metadata\n"; print_r(unserialize($localData)); } else { $this->updateVideoLocally($videoFile, $localData, $videoId); } $this->migratedVideos++; } $this->printSummary(); }
/** * Create remote asset * @return integer */ protected function createRemoteAsset() { $this->prepareMetaDataForOoyala(); if (empty($this->metaData['url']['flash'])) { $this->logger->videoWarnings("Error when generating remote asset data: empty asset url.\n"); return 0; } if (empty($this->metaData['duration']) || $this->metaData['duration'] < 0) { $msg = "Error when generating remote asset data: invalid duration ({$this->metaData}[duration]).\n"; $this->logger->videoWarnings($msg); return 0; } // check if video title exists $ooyalaAsset = new OoyalaAsset(); $isExist = $ooyalaAsset->isTitleExist($this->metaData['assetTitle'], $this->metaData['provider']); if ($isExist) { $msg = "SKIP: Uploading Asset: {$this->metaData['destinationTitle']} ({$this->metaData['provider']}). "; $msg .= "Video already exists in remote assets.\n"; $this->logger->videoSkipped($msg); return 0; } if ($this->debugMode()) { print "Ready to create remote asset\n"; print "id: {$this->metaData['videoId']}\n"; print "name: {$this->metaData['destinationTitle']}\n"; print "assetdata:\n"; foreach (explode("\n", var_export($this->metaData, TRUE)) as $line) { print ":: {$line}\n"; } } else { $result = $ooyalaAsset->addRemoteAsset($this->metaData); if (!$result) { $this->logger->videoWarnings(); return 0; } } $categories = empty($this->metaData['pageCategories']) ? [] : explode(", ", $this->metaData['pageCategories']); $msg = "Uploaded remote asset: {$this->metaData['destinationTitle']} (id: {$this->metaData['videoId']})\n"; $this->logger->videoIngested($msg, $categories); return 1; }