コード例 #1
0
ファイル: Vimeo.php プロジェクト: pmill/php-extract
 /**
  * @param Crawler $crawler
  * @return ExtractedVideo
  */
 public function extract(Crawler $crawler)
 {
     $oembedData = $this->getOEmbedData($crawler);
     $video = new ExtractedVideo();
     if (is_array($oembedData) && isset($oembedData['description'])) {
         $video->setDescription($oembedData['description']);
     } else {
         $video->setDescription(trim($crawler->filter(".description_wrapper")->text()));
     }
     if (is_array($oembedData) && isset($oembedData['title'])) {
         $video->setTitle($oembedData['title']);
     } else {
         $video->setTitle(trim($crawler->filter("h1.js-clip_title")->html()));
     }
     if (is_array($oembedData) && isset($oembedData['thumbnail_url'])) {
         $thumbnail = ExtractedImageFactory::createFromUrl($oembedData['thumbnail_url'], isset($oembedData['thumbnail_width']) ? $oembedData['thumbnail_width'] : null, isset($oembedData['thumbnail_height']) ? $oembedData['thumbnail_height'] : null);
         $video->setThumbnail($thumbnail);
     }
     if (is_array($oembedData) && isset($oembedData['html'])) {
         $doc = new DOMDocument();
         $doc->loadHTML($oembedData['html']);
         /** @var DOMNodeList $iframes */
         $iframes = $doc->getElementsByTagName('iframe');
         if ($iframes->length > 0) {
             $video->setEmbedUrl($iframes->item(0)->getAttribute('src'));
         }
     }
     $publishedOn = $crawler->filter("time")->attr('datetime');
     $publishedDatetime = new \DateTime($publishedOn);
     $video->setPublishedOn($publishedDatetime);
     $video->setStats($this->extractStats());
     $video->setOwner($this->extractOwner($crawler, $oembedData));
     return $video;
 }
コード例 #2
0
ファイル: YouTube.php プロジェクト: pmill/php-extract
 /**
  * @param Crawler $crawler
  * @return ExtractedVideo
  */
 public function extract(Crawler $crawler)
 {
     $video = new ExtractedVideo();
     $video->setEmbedUrl(trim($crawler->filter("meta[property='og:video:url']")->attr('content')));
     $video->setDescription(trim($crawler->filter('#eow-description')->html()));
     $video->setTitle(trim($crawler->filter('#eow-title')->html()));
     $video->setThumbnailByUrl(trim($crawler->filter("meta[property='og:image']")->attr('content')));
     $publishedText = str_replace('Published on ', '', $crawler->filter("#watch-uploader-info")->text());
     $video->setPublishedOn(\DateTime::createFromFormat('M j, Y', $publishedText));
     $video->setStats($this->extractStats($crawler));
     $video->setOwner($this->extractOwner($crawler));
     return $video;
 }