/** * @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; }
/** * @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; }