/** * @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; }
<?php require_once '../vendor/autoload.php'; use FlatBits\YouStraw\StrawCollection; ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1); $playlistId = 'PLkRSD11r9mB_HbAxcCdYs7kMQOTzrDokj'; $videos = StrawCollection::fromPlaylist($playlistId); $videos->downloadAll('../cache/videos/');