I have this program that retrieves videos from a channel and shuffles them, as you can see, the program gets the channel's name from the variable $playlistId
<?php
session_start();
class PlayList {
public function __construct($id) {
$this->id = $id;
$this->videos = [];
$this->currentVideo = 0;
$this->addVideos('https://gdata.youtube.com/feeds/api/users/' . $this->id . '/uploads?v=2&alt=json');
shuffle($this->videos);
}
public function addVideos($url) {
$cont = json_decode(file_get_contents($url));
foreach ($cont->feed->entry as $entry) {
$video = [];
$video['title'] = $entry->title->{'$t'};
$video['desc'] = $entry->{'media$group'}->{'media$description'}->{'$t'};
$video['id'] = $entry->{'media$group'}->{'yt$videoid'}->{'$t'};
$this->videos[] = $video;
}
foreach ($cont->feed->link as $link) {
if ($link->rel === 'next') {
$this->addVideos($link->href);
break;
}
}
}
public function getId() {
return $this->id;
}
public function nextVideo() {
if ($this->currentVideo < count($this->videos) - 1) {
$this->currentVideo += 1;
} else {
$this->currentVideo = 0;
}
}
public function getVideoTitle() {
return $this->videos[$this->currentVideo]['title'];
}
public function getVideoDesc() {
return $this->videos[$this->currentVideo]['desc'];
}
public function getVideoSrc() {
return "http://www.youtube.com/embed/" . $this->videos[$this->currentVideo]['id'];
}
public function printList() {
foreach ($this->videos as $video) {
echo $video['title'] . '<br>';
}
}
}
?>
<?php
$playlistId = "NAKCollection";
if (!isset($_SESSION['playlist']) || $_SESSION['playlist']->getId() != $playlistId) {
$_SESSION['playlist'] = new PlayList($playlistId);
} else {
$_SESSION['playlist']->nextVideo();
}
?>
<html>
<head>
<title>Video Shuffle</title>
</head>
<body>
<div style="float: right;">
<?php
$_SESSION['playlist']->printList();
?>
</div>
<div>
<?php echo $_SESSION['playlist']->getVideoTitle(); ?>
</div>
<div>
<iframe type="text/html" src="<?php echo $_SESSION['playlist']->getVideoSrc(); ?>" allowfullscreen></iframe>
</div>
</body>
</html>
If the channel has like 300 videos the page times out, how can I retrieve 50 videos at a time like a batch and then another 50 when the first group is done?
I know I can alter php.ini but I don't want to do that now
This is using the deprecated GData API, if you use the new Data API v3, while retrieving channel's uploaded videos, you can set maxresults and get your results with paging, so you can iterate through pages.