Sometimes you need to get details of a video, Or maybe you are creating a new project and it has videos from Vimeo, well you are in luck. In this tutorial, I am going to show you quick and easy how you can retreave the info of a vimeo video using php!

 

First, lets create a video and call it. get_vimeo_video_info.php – Or you can really call it whatever you want.

Next, lets create a function and call it get_vimeo_id with the argument $url, you can see this example below.

function get_vimeo_id($url) {
     $regexstr = '#http://(?:\w+.)?vimeo.com/(?:video/|moogaloop\.swf\?clip_id=)(\w+)#i';
     preg_match($regexstr,$url, $matches);
     return $matches[1];
}

 

Now we will have php use a tool call curl to get the information from the url using the Vimeo api. You can read more about this at Vimeo Developer api website

 

// use the returned value from our get_vimeo_function
// you can do it like this
/*
$sample_link = 'http://developer.vimeo.com/'
if(get_vimeo_id($sample_link)) {
   $id = get_vimeo_id($sample_link);
}
*/
 
// then create a function to extract vimeo info
function get_vimeo_info($id) {
    if (!function_exists('curl_init')) {
       die('CURL is not installed!');
    } else {
        $cr = curl_init();
        curl_setopt($cr, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php"); // the vimeo simple api with php output
        curl_setopt($cr, CURLOPT_HEADER, 0);
        curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($cr, CURLOPT_TIMEOUT, 10);
        $output = unserialize(curl_exec($cr));
        $output = $output[0];
        curl_close($cr);
        return $output;
    }
}

 

Now simply just run the script and vola! You now have the Vimeo video information from the video id! You can use this if you are created a page that will take advantage of hosting videos on vimeo.