Pages

Thursday, July 11, 2013

How to get youtube video duration from id - PHP



function parseVideoEntry($video_id) {    
    $obj= new stdClass;

$url = 'http://gdata.youtube.com/feeds/api/videos/'.$video_id;
$categoriesArray = array();
$xml = simplexml_load_file($url);


    $media = $xml->children('http://search.yahoo.com/mrss/');
    $obj->title = $media->group->title;
    $obj->description = $media->group->description;
     
    $yt = $media->children('http://gdata.youtube.com/schemas/2007');
    $attrs = $yt->duration->attributes();

    $obj->length = $attrs['seconds'];
    $VideoSeconds = $obj->length;
    return $VideoSeconds;    
}

echo $video = parseVideoEntry("nVhM3IYMF8o");

No comments: