Obtener el thumbnail de los videos de vimeo
agosto 1st, 2012 | Posted by in PHPCon esta funcion podemos tener toda la info de un video de vimeo (incluida la foto del mismo video). De esta manera, si estamos desarrollando un sistema de alta de videos para algun cliente, con solo copiar la URL del video, podemos mostrarle un thumbnail en el mismo momento.
<?php
function get_vimeo_thumb($vimeo)
{
$id = $vimeo;
//try new embed code
preg_match('/http://player.vimeo.com/video/([^?"]*)/is',
$vimeo, $match);
if(!empty($match))
{
//found id
$id = $match[1];
}
else
{
//try old embed code
preg_match('/http://[w.]*vimeo.com/moogaloop.swf?clip_id=([^&"]*)/is',
$vimeo, $match);
if(!empty($match))
{
//found id
$id = $match[1];
}
else
{
//try url
preg_match('/http://[w.]*vimeo.com/([^&"]*)/is',
$vimeo, $match);
if(!empty($match))
{
//found id
$id = $match[1];
}
}
}
//forming API url
$url = "http://vimeo.com/api/v2/video/".$id.".json";
//curl request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$curlData = curl_exec($curl);
curl_close($curl);
//decoding json structure into array
return current(json_decode($curlData, true));
}
$vimeo = 'http://vimeo.com/12083674';
$arr = get_vimeo_thumb($vimeo);
echo "<pre>";
print_r($arr);
echo "</pre>";
echo "<img src='".$arr["thumbnail_medium"]."'/>";
?>
You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.





Pingback: Bitacoras.com