public function alter_providerResult(org_tubepress_api_provider_ProviderResult $providerResult) { $totalResults = $providerResult->getEffectiveTotalResultCount(); $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_); $limit = $context->get(org_tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP); $firstCut = $limit == 0 ? $totalResults : min($limit, $totalResults); $secondCut = min($firstCut, self::_calculateRealMax($context, $firstCut)); $videos = $providerResult->getVideoArray(); $resultCount = count($videos); org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Effective total result count (taking into account user-defined limit) is %d video(s)', $secondCut); if ($resultCount > $secondCut) { org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Result has %d video(s), limit is %d. So we\'re chopping it down.', $resultCount, $secondCut); $providerResult->setVideoArray(array_splice($videos, 0, $secondCut - $resultCount)); } $providerResult->setEffectiveTotalResultCount($secondCut); return $providerResult; }
/** * Fetch a single video. * * @param string $customVideoId The video ID to fetch. * * @return org_tubepress_api_video_Video The video. */ public function getSingleVideo($customVideoId) { org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Fetching video with ID <tt>%s</tt>', $customVideoId); $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $urlBuilder = $ioc->get(org_tubepress_api_feed_UrlBuilder::_); $videoUrl = $urlBuilder->buildSingleVideoUrl($customVideoId); org_tubepress_impl_log_Log::log(self::$_logPrefix, 'URL to fetch is <a href="%s">this</a>', $videoUrl); $feedRetrievalService = $ioc->get(org_tubepress_api_feed_FeedFetcher::_); $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_); $results = $feedRetrievalService->fetch($videoUrl, $context->get(org_tubepress_api_const_options_names_Cache::CACHE_ENABLED)); $factory = $ioc->get(org_tubepress_api_factory_VideoFactory::_); $videoArray = $factory->feedToVideoArray($results); $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_); $pc = $ioc->get(org_tubepress_api_provider_ProviderCalculator::_); if (empty($videoArray)) { throw new Exception(sprintf('Could not find video with ID %s', $customVideoId)); //>(translatable)< } $result = new org_tubepress_api_provider_ProviderResult(); $result->setEffectiveTotalResultCount(1); $result->setVideoArray($videoArray); $provider = $pc->calculateProviderOfVideoId($customVideoId); $pm->runFilters(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $result, $provider); return $videoArray[0]; }