Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Function that returns random video ID from a users videofeed
<?php
// Function that returns random video ID from a users videofeed
function RandomYoutube($youtubefeed){
$feedresult = simplexml_load_file($youtubefeed);
$videoids = array();
foreach ($feedresult->entry as $video) {
$media = $video->children('media', true);
$url = (string)$media->group->player->attributes()->url;
$index = strrpos($url, "&");
$url = substr($url, 0, $index);
$index = strrpos($url, "watch");
$url = substr($url, $index + 8, strlen($url) - ($index + 8));
$videoids[] = $url;
}
return $videoids[array_rand($videoids)];
}
// Usage (not tested with other feed format, just replace username with your username)
echo RandomYoutube('http://gdata.youtube.com/feeds/api/users/username/uploads');
?>
@rkaartikeyan
Copy link

rkaartikeyan commented Dec 28, 2013

How to get all videos from a user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment