Exemplo n.º 1
0
/**
* 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");
    }
}
Exemplo n.º 2
0
 public function execute()
 {
     $this->test = $this->hasOption('test');
     $this->verbose = $this->hasOption('verbose');
     $title = $this->getOption('title', '');
     echo "Checking " . F::app()->wg->Server . "\n";
     $stats = ['checked' => 0, 'ok' => 0, 'failed' => 0, 'fail_action' => [], 'error' => 0];
     if ($this->test) {
         echo "== TEST MODE ==\n";
     }
     $this->debug("(debugging output enabled)\n");
     $startTime = time();
     if ($title) {
         $videos = [$title];
     } else {
         $videos = VideoInfoHelper::getLocalVideoTitles();
         $this->debug("Found " . count($videos) . " video(s)\n");
     }
     $fix = $this->test ? false : true;
     $helper = new VideoHandlerHelper();
     foreach ($videos as $title) {
         $stats['checked']++;
         $status = $helper->fsckVideoThumbnail($title, $fix);
         if ($status->isGood()) {
             $result = $status->value;
             if ($result['check'] == 'ok') {
                 $stats['ok']++;
                 $this->debug("File '{$title}' ... ok\n");
             } else {
                 $stats['failed']++;
                 if (empty($stats['fail_action'][$result['action']])) {
                     $stats['fail_action'][$result['action']] = 0;
                 }
                 $stats['fail_action'][$result['action']]++;
                 echo "File '{$title}' ... failed\n";
                 echo "\tACTION: " . $result['action'] . "\n";
             }
         } else {
             echo "File '{$title}' ... ERROR\n";
             $stats['error']++;
             foreach ($status->errors as $err) {
                 echo "\tERR: " . $err['message'] . "\n";
             }
         }
     }
     printf("Checked %5d video(s)\n", $stats['checked']);
     printf("\t%5d ok\n", $stats['ok']);
     printf("\t%5d failed\n", $stats['failed']);
     foreach ($stats['fail_action'] as $action => $count) {
         printf("\t\t( %4d %s )\n", $count, $action);
     }
     printf("\t%5d error(s)\n", $stats['error']);
     $delta = F::app()->wg->lang->formatTimePeriod(time() - $startTime);
     echo "Finished after {$delta}\n";
 }
Exemplo n.º 3
0
 public function execute()
 {
     $this->test = $this->hasOption('test');
     $this->verbose = $this->hasOption('verbose');
     echo "Checking " . F::app()->wg->Server . "\n";
     if ($this->test) {
         echo "== TEST MODE ==\n";
     }
     $this->debug("(debugging output enabled)\n");
     $startTime = time();
     $videos = VideoInfoHelper::getLocalVideoTitles();
     $this->debug("Found " . count($videos) . " video(s)\n");
     foreach ($videos as $origTitle) {
         $title = preg_replace('/_/', ' ', $origTitle);
         $url = "https://api.dailymotion.com/videos?search=" . urlencode($title) . '&fields=title,ads';
         $json = Http::request('GET', $url);
         if ($json) {
             $resp = json_decode($json, true);
             if (isset($resp['list'])) {
                 // Reduce titles to just letters and numbers
                 $normalTitle = preg_replace('/[^a-zA-Z0-9]+/', '', $title);
                 $list = $resp['list'];
                 foreach ($list as $info) {
                     // Reduce the matched titles to just letters and numbers
                     $normalMatch = preg_replace('/[^a-zA-Z0-9]+/', '', $info['title']);
                     // See if the normalized versions match
                     if ($normalMatch == $normalTitle) {
                         echo "{$origTitle}\t" . $info['title'] . "\t" . $info['ads'] . "\n";
                         continue;
                     }
                 }
             }
         }
     }
     $delta = F::app()->wg->lang->formatTimePeriod(time() - $startTime);
     echo "Finished after {$delta}\n";
 }
 /**
  * Hook: check if the file is deleted
  * @todo re-implement this w/o reliance on request origination data
  * @param File $file
  * @param boolean $isDeleted
  * @return true
  */
 public static function onForeignFileDeleted($file, &$isDeleted)
 {
     // Only report this file as deleted when this request is coming from a file page.  In other
     // instances (search results from the WVL for example) we want to make sure these videos still appear.
     // (VideoEmbedTool controller for search in VET, insertVideo method for add video via VET, and
     // Videos controller and addVideo method for add video in general)
     $req = F::app()->wg->Request;
     $controller = $req->getVal('controller', '');
     $method = $req->getVal('method', '');
     $title = $req->getVal('title', '');
     if ($controller == 'VideoEmbedTool' || $method == 'insertVideo' || $title == 'Special:WikiaVideoAdd' || $controller == 'Videos' && $method == 'addVideo' || $controller == 'Lightbox' && ($method = 'getMediaDetail')) {
         return true;
     }
     if (WikiaFileHelper::isFileTypeVideo($file) && !$file->isLocal()) {
         $videoInfoHelper = new VideoInfoHelper();
         $isDeleted = $videoInfoHelper->isVideoRemoved($file->getName());
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * @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']);
 }
Exemplo n.º 6
0
 public function execute()
 {
     $this->test = $this->hasOption('test');
     $this->verbose = $this->hasOption('verbose');
     $this->opt = $this->getOption('opt');
     $this->startDate = $this->getOption('start');
     $this->endDate = $this->getOption('end');
     $this->provider = $this->getOption('provider');
     if (empty($this->opt) || !in_array($this->opt, self::$opts)) {
         die("Error: invalid option. Please enter 'reupload' or 'data'.\n");
     }
     if ($this->opt == 'reupload' && (empty($this->startDate) || empty($this->endDate))) {
         die("Error: Reuploading image requires start date and end date.\n");
     }
     $app = F::app();
     echo "Wiki: {$app->wg->CityId} ({$app->wg->DBname})\n";
     if ($this->test) {
         echo "== TEST MODE ==\n";
     }
     $startTime = time();
     $cnt = 0;
     $success = 0;
     $failed = 0;
     $affected = 0;
     if ($this->opt == 'reupload') {
         $videos = $this->getVideos();
     } else {
         $videos = VideoInfoHelper::getLocalVideoTitles();
     }
     $total = count($videos);
     $helper = new VideoHandlerHelper();
     foreach ($videos as $title) {
         $cnt++;
         $this->debug("Video [{$cnt} of {$total}]: {$title} ");
         $file = WikiaFileHelper::getVideoFileFromTitle($title);
         // check if the file exists
         if (empty($file)) {
             echo " ... FAILED (File not found)\n";
             $failed++;
             continue;
         }
         // check for test mode
         if ($this->test) {
             $this->debug("... DONE\n");
             $success++;
             continue;
         }
         if ($this->opt == 'reupload') {
             if ($this->provider == 'screenplay') {
                 $thumbUrl = ScreenplayApiWrapper::getThumbnailUrlFromAsset($file->getVideoId());
                 if (empty($thumbUrl)) {
                     echo " ... FAILED (Thumbnail URL not found)\n";
                     $failed++;
                     continue;
                 }
             } else {
                 $thumbUrl = null;
             }
             $status = $helper->resetVideoThumb($file, $thumbUrl);
         } else {
             if ($this->opt == 'data') {
                 if (file_exists($file->getLocalRefPath())) {
                     $status = $helper->updateThumbnailData($file);
                 } else {
                     $status = Status::newFatal('Path not found');
                 }
             } else {
                 $status = Status::newGood();
             }
         }
         if ($status->isGood()) {
             if ($this->opt == 'data') {
                 $changed = $status->value;
             } else {
                 $changed = 1;
             }
             $this->debug("... DONE ({$changed} affected).\n");
             $success++;
             if ($changed > 0) {
                 $affected++;
             }
         } else {
             $errorMsg = array();
             foreach ($status->errors as $err) {
                 $errorMsg[] = $err['message'];
             }
             $this->debug("... FAILED (" . implode(', ', $errorMsg) . ")\n");
             $failed++;
         }
     }
     $diff = $app->wg->lang->formatTimePeriod(time() - $startTime);
     echo "Wiki {$app->wg->CityId} ({$app->wg->DBname}): Total: {$total}, Success: {$success} ({$affected} affected), Failed: {$failed}. Finished after {$diff}\n";
 }
 /**
  * get total video views by title
  * @param string $title
  * @return integer $videoViews
  */
 public static function getTotalVideoViewsByTitle($title)
 {
     $app = F::app();
     $app->wf->ProfileIn(__METHOD__);
     $memKey = $app->wf->MemcKey('videos', 'total_video_views');
     $videoList = $app->wg->Memc->get($memKey);
     if (!is_array($videoList)) {
         if (!VideoInfoHelper::videoInfoExists()) {
             $videoList = F::build('DataMartService', array(), 'getVideoListViewsByTitleTotal');
         } else {
             $db = $app->wf->GetDB(DB_SLAVE);
             $result = $db->select(array('video_info'), array('video_title, views_total'), array(), __METHOD__);
             $videoList = array();
             while ($row = $db->fetchObject($result)) {
                 $hashTitle = md5($row->video_title);
                 $videoList[$hashTitle] = $row->views_total;
             }
             $app->wg->Memc->set($memKey, $videoList, 60 * 60 * 24);
         }
     }
     $hashTitle = md5($title);
     $videoViews = isset($videoList[$hashTitle]) ? $videoList[$hashTitle] : 0;
     $app->wf->ProfileOut(__METHOD__);
     return $videoViews;
 }
Exemplo n.º 8
0
 /**
  * Get total video views by title
  *
  * @param string $title
  * @return integer $videoViews
  */
 public static function getTotalVideoViewsByTitle($title)
 {
     $app = F::app();
     wfProfileIn(__METHOD__);
     $cacheTtl = 7200;
     // 2 hours for caching the result in memcache
     // 24hr allowance for returning stale results until new cache is built
     // Adjusted to increase the caching benefit for infrequently viewed videos
     $staleCacheTtl = 86400;
     $asyncCacheEnabled = !empty($app->wg->EnableAsyncVideoViewCache);
     $hashTitle = md5($title);
     $memKeyBase = self::getMemKeyTotalVideoViews($asyncCacheEnabled);
     // @TODO: Remove EnableAsyncVideoViewCache and the else clause,
     // after verifying the async caching solution works (@see VID-2103)
     if ($asyncCacheEnabled) {
         $cacheKey = $memKeyBase . '-' . $hashTitle;
         $videoViews = (new AsyncCache())->key($cacheKey)->ttl($cacheTtl)->callback([__CLASS__, 'getTotalVideoViewsByTitleFromDb'], [$title])->staleOnMiss($staleCacheTtl)->value();
     } else {
         $cacheKey = $memKeyBase . '-' . substr($hashTitle, 0, 2);
         $videoList = $app->wg->Memc->get($cacheKey);
         if (!isset($videoList[$hashTitle])) {
             $viewCount = VideoInfoHelper::getTotalViewsFromTitle($title);
             $videoList[$hashTitle] = $viewCount;
             $app->wg->Memc->set($cacheKey, $videoList, $cacheTtl);
         }
         $videoViews = $videoList[$hashTitle];
     }
     wfProfileOut(__METHOD__);
     return $videoViews;
 }