/**
  * @param string $playlistId
  * @return StrawCollection|null A StrawCollection representation from the playlist
  */
 public static function fromPlaylist($playlistId)
 {
     $strawCollection = null;
     $playListHtmlString = CurlUtil::fetch("https://www.youtube.com/playlist?list={$playlistId}");
     $playListHtml = HtmlDomParser::str_get_html($playListHtmlString);
     $videosHtml = $playListHtml->find('tr.pl-video');
     $videoIds = array();
     foreach ($videosHtml as $vidHtml) {
         $videoIds[] = $vidHtml->getAttribute('data-video-id');
     }
     if (!empty($videoIds)) {
         $strawCollection = new StrawCollection();
         $strawCollection->addVideos($videoIds);
     }
     return $strawCollection;
 }
Exemple #2
0
 /**
  * Actually fetch and parse the video info
  */
 public function loadVideo()
 {
     if ($this->sources === null) {
         $videoInfo = CurlUtil::fetch("http://youtube.com/get_video_info?video_id={$this->videoId}");
         $videoData = array();
         parse_str($videoInfo, $videoData);
         // echo json_encode($videoData);die();
         $this->videoTitle = $videoData['title'];
         $this->sources = array();
         $ref = explode(',', $videoData['url_encoded_fmt_stream_map']);
         foreach ($ref as $source) {
             $stream = array();
             parse_str($source, $stream);
             $type = explode(';', $stream['type'])[0];
             $quality = explode(',', $stream['quality'])[0];
             if (!array_key_exists($type, $this->sources) || !is_array($this->sources[$type])) {
                 $this->sources[$type] = array();
             }
             $this->sources[$type][$quality] = $stream;
         }
     }
 }