The code below will get you the video thumbnail, title, and duration, FROM THE URL. Just change the youtube link from the end.
Demo: http://100ro.ro/wp-includes/ajaxdemo/test.php?y=www.youtube.com/watch?v=V80jm1rs2UQ :
(note: use the youtube url in y=youtubeurl without http:// )
<?php
getYoutubeImage($_GET["y"]);
function getYoutubeImage($e){
//GET THE URL
$url = $e;
$queryString = parse_url($url, PHP_URL_QUERY);
parse_str($queryString, $params);
$v = $params['v'];
// function to parse a video <entry>
function parseVideoEntry($entry) {
$obj= new stdClass;
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
$obj->title = $media->group->title;
$obj->description = $media->group->description;
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];
// return object to caller
return $obj;
}
// get video ID from $_GET
if (!isset($v)) {
die ('ERROR: Missing video ID');
} else {
$vid = $v;
}
// set video data feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $v;
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
// parse video entry
$video = parseVideoEntry($entry);
// display video image, title and duration
echo "<img src='http://i3.ytimg.com/vi/$v/default.jpg' width='150' />";
echo "<p>{$video->title}</p>";
echo "<p>".sprintf("%0.2f", $video->length/60) . " min. </p>";
}
?>