I am having a very difficult time getting this to work how I want. I am looking to grab all of the videos from a playlist. Currently I can retrieve 20 but there are some playlists that contain over 100 videos. This is where I am having a problem. I am using the following code I found from another user on here because I have exhausted everything I can think of.
This starts the process. Note that I am calling the XML feed through a specific URL as there is minimal information on Googles Dev site for what I am trying to do.
public function saveSpecificVideoFeed($id) {
$url = 'https://gdata.youtube.com/feeds/api/playlists/' . $id . '?v=2';
$feed = $this->yt->getPlaylistVideoFeed($url);
$this->saveEntireFeed($feed, 1);
}
This is what I am passing the above function to:
public function saveEntireFeed($videoFeed, $counter) {
foreach ($videoFeed as $videoEntry) {
if (self::saveVideoEntry($videoEntry)) {
$this->success++;
} else {
$this->failed++;
}
$counter++;
}
// See whether we have another set of results
try {
$videoFeed = $videoFeed->getNextFeed();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage() . "<br/>";
echo "Successfuly Pulled: <b>" . $this->success . "</b> Videos.<br/>";
echo "Failed to Pull: <b>" . $this->failed . "</b> Videos.<br/>";
echo "You Tryed to Insert: <b>" . $this->duplicate . "</b> Duplicate Videos.";
return;
}
if ($videoFeed) {
self::saveEntireFeed($videoFeed, $counter);
}
}
Here is how I am saving the videos individually:
private function saveVideoEntry($videoEntry) {
if (self::videoExists($videoEntry->getVideoId())) {
// Do nothing if it exists
} else {
$videoThumbnails = $videoEntry->getVideoThumbnails();
$thumbs = null;
foreach ($videoThumbnails as $videoThumbnail) {
$thumbs .= $videoThumbnail['url'] . ',';
}
$binds = array(
'title' => $videoEntry->getVideoTitle(),
'videoId' => $videoEntry->getVideoId(),
'updated' => $videoEntry->getUpdated(),
'description' => $videoEntry->getVideoDescription(),
'category' => $videoEntry->getVideoCategory(),
'tags' => implode(", ", $videoEntry->getVideoTags()),
'watchPage' => $videoEntry->getVideoWatchPageUrl(),
'flashPlayerUrl' => $videoEntry->getFlashPlayerUrl(),
'duration' => $videoEntry->getVideoDuration(),
'viewCount' => $videoEntry->getVideoViewCount(),
'thumbnail' => $thumbs,
);
$sql = "INSERT INTO $this->tblName (title, videoId, updated, description, category, tags, watchPage, flashPlayerUrl, duration, viewCount, thumbnail)
VALUES (:title, :videoId, :updated, :description, :category, :tags, :watchPage, :flashPlayerUrl, :duration, :viewCount, :thumbnail)";
$sth = $this->db->prepare($sql);
foreach ($binds as $key => $value) {
if ($value == null) {
$value = '';
}
$sth->bindValue(":{$key}", $value);
}
if ($sth->execute()) {
return true;
} else {
print_r($sth->errorInfo());
return false;
}
}
}
This is what I get from browser output to let me know in an easy to read format what ive gotten from the pull:
Table has been created continuing with extraction. No link to next set of results found. Successfully Pulled: 20 Videos. Failed to Pull: 0 Videos. You Tried to Insert: 0 Duplicate Videos.
This however is a playlist with 36 videos so my problem is accessing the remaining videos. Is there an easier not so documented way to do this? Any help would be greatly appreciated.
I have already tried using the max-results and the start-index elements in the request URL and increasing them to the needed values when looping through, this however has no effect on the XML output from the YouTube API.
Any help would be greatly appreciated.