php-youtube-api
php-youtube-api copied to clipboard
Add getAllPlaylistItemsByPlaylistId() method
Will probably need changing to meet code style of library
Could do with metadata added to returned array
As such, unsure how a test would look like
great job! I need this function!
refactor by GPT
function getAllPlaylistItemsByPlaylistId($playlistId) {
$playlistItems = [];
$params = [
'playlistId' => $playlistId,
'part' => 'id, snippet, contentDetails, status',
];
do {
$raw = Youtube::getPlaylistItemsByPlaylistIdAdvanced($params, true);
if ($raw['results'] !== false) {
$playlistItems = array_merge($playlistItems, $raw['results']);
}
$params['pageToken'] = $raw['info']['nextPageToken'] ?? null;
} while ($params['pageToken'] !== null);
return $playlistItems;
}