Videos

$i = 6;

$input = array("Kerala Assemly Elections 2011", "Kerala Election News", "Kerala Congress", "KM Mani", "PK Kunjalikkutty");
$keywordencoded = $input[rand(0,4)];

$keywordencoded = ereg_replace('[[:space:]]+', '+', trim($keywordencoded));
// generate feed URL
//$feedURL = "http://gdata.youtube.com/feeds/api/videos/-/{$keywordencoded}?orderby=viewCount&max-results={$i}";
$feedURL = "http://gdata.youtube.com/feeds/api/videos?q={$keywordencoded}&orderby=relevance&start-index=1&max-results={$i}&v=2";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);

// get summary counts from opensearch: namespace
$counts = $sxml->children(‘http://a9.com/-/spec/opensearchrss/1.0/’);
$total = $counts->totalResults;
$startOffset = $counts->startIndex;
$endOffset = ($startOffset-1) + $counts->itemsPerPage;

foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information

$id= $entry->id;

$vdoid= substr ($id, stripos($id,”video:”)+6);
//echo substr ($id, stripos($id,”video:”)+6).”
“;
$media = $entry->children(‘http://search.yahoo.com/mrss/’);

// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];

// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];

// get node for video length
$yt = $media->children(‘http://gdata.youtube.com/schemas/2007′);
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];

$uploaded = $yt->uploaded;

$attrs = $yt->statistics->attributes();

// get node for video ratings
$gd = $entry->children(‘http://schemas.google.com/g/2005′);
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}

?>

group->title;?>

Comments are closed.