Get Youtube Video Info with SimpleXML


Z2pX599xo7M is the video ID

<?php

$sxml = simplexml_load_file(‘http://gdata.youtube.com/feeds/api/videos/Z2pX599xo7M&#8217;);

$media = $sxml->children(‘http://search.yahoo.com/mrss/&#8217;);
$yt   = $media->children(‘http://gdata.youtube.com/schemas/2007&#8217;);

$attr1 = $media->group->thumbnail[0]->attributes();
$thumbnail  = $attr1[‘url’]; // thumbnail url

$attr2 = $yt->duration->attributes();
$length  = $attr2[‘seconds’]; // in seconds
$video_duration = round($length/60,2); // in minutes

?>