/** * @param string $url * * @return ParseResult */ public function parseFromUrl($url) { $code = $this->extractCode($url); if (!$code) { throw new \InvalidArgumentException("Invalid video url"); } $videoInfo = $this->_videoInfo($code); if (empty($videoInfo)) { throw new \InvalidArgumentException("Invalid video url"); } $info = $videoInfo[0]; if (empty($info)) { throw new \InvalidArgumentException("Invalid video url"); } $result = new ParseResult('vimeo', $code); $result->setTitle($info['title']); $result->setDescription($info['description']); $result->setVideoDuration($info['duration']); $result->setThumbnailUrl($info['thumbnail_large']); $result->setThumbnailSmallUrl($info['thumbnail_medium']); $result->setThumbMode('large'); $result->setProviderName('vimeo.com'); $result->setOriginUrl($url); return $result; }
public function addParseResult(\SplFileInfo $file, ParseResult $result) { if (!$result->hasUnits()) { return; } $filename = $file->getRealPath(); foreach ($result->getUnits() as $unit) { if (!$this->accept($unit)) { continue; } if (isset($this->units[$unit])) { throw new CollectorResultException(sprintf("Redeclaration of trait, interface or class found:\n\n\tUnit name: %s\n\tFirst occurance: %s\n\tRedeclaration: %s", $unit, $this->units[$unit], $filename), CollectorResultException::DuplicateUnitName); } $this->units[$unit] = $filename; $this->dependencies[$unit] = $result->getDependenciesForUnit($unit); } }
public function search($url) { $requestUrl = self::$api_base . self::$api_path . "?url={$url}&client_id=" . $this->key; $jsonData = Injector::inst()->get('Fetcher')->fetch($requestUrl); $data = json_decode($jsonData, true); if ($data['kind'] == 'track') { $result = ['Type' => 'soundcloud', 'Video' => $data['id'], 'Image' => $data['artwork_url'], 'Title' => $data['title'], 'Description' => $data['description']]; return ParseResult::create($result); } return ParseResult::create(['Error' => "'{$requestUrl}' can't be found on soundclound.com"]); }
public function search($url) { $host = parse_url($url, PHP_URL_HOST); $infoUrl = Controller::join_links(self::$api_base, $host, self::$api_blog_info . $this->key); $avatarUrl = Controller::join_links(self::$api_base, $host, self::$api_blog_avatar); $jsonData = Injector::inst()->get('Fetcher')->fetch($infoUrl); $infoData = json_decode($jsonData, true); if ($infoData['meta']['status'] == 200) { $result = ['Type' => 'tumblr', 'Image' => $avatarUrl, 'Title' => $infoData['response']['blog']['title'], 'Description' => $infoData['response']['blog']['description']]; return ParseResult::create($result); } return ParseResult::create(['Error' => "'{$infoUrl}' can't be found on tumblr.com"]); }
/** * @param string $url the url to parse * @return ParseResult the website in a result object */ public static function parse($url) { // check if we have a provider $providers = self::get_api_providers(); foreach ($providers as $provider) { /** @var IApiProvider $provider */ if ($provider->isProvided($url)) { return $provider->search($url); } } // otherwise fetch data try { $html = Injector::inst()->get('Fetcher')->fetch($url); // load xpath $xpathObj = self::load_xpath($html); } catch (Exception $ex) { return ParseResult::create(['Error' => $ex->getMessage()]); } // find open graph and meta data $ogData = self::get_open_graph_data($xpathObj); $metaData = self::get_meta_data($xpathObj); // merge data $data = array_merge($metaData, $ogData); // if no image provided - find image if (!array_key_exists('Image', $data)) { $data['Image'] = self::find_content_image($xpathObj, $url); } // create and return result return ParseResult::create($data); }
/** * @param string $url * * @return ParseResult */ public function parseFromUrl($url) { $code = $this->extractCode($url); if (!$code) { throw new \InvalidArgumentException("Invalid YouTube video url"); } $videoInfo = $this->_videoInfo($code); // validate result if (empty($videoInfo)) { throw new \InvalidArgumentException("Invalid YouTube video"); } $result = new ParseResult('youtube', $code); $snippet = $videoInfo['items'][0]['snippet']; $contentDetail = $videoInfo['items'][0]['contentDetails']; $result->setTitle($snippet['title']); $result->setDescription($snippet['description']); $result->setThumbnailUrl($snippet['thumbnails']['high']['url']); $result->setThumbnailUrl('http://img.youtube.com/vi/' . $code . '/sddefault.jpg'); $result->setThumbnailSmallUrl($snippet['thumbnails']['medium']['url']); $result->setVideoDuration($this->extractDuration($contentDetail['duration'])); $result->setDimension($contentDetail['dimension']); $result->setDefinition($contentDetail['definition']); $result->setThumbMode('large'); $result->setProviderName('www.youtube.com'); $result->setOriginUrl($url); return $result; }