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"; }
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"; }
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"; }