views:

5136

answers:

6

Hi, I want to get a thumbnail image for videos from Vimeo.

When getting images from Youtube I just do like this:

http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg

Any idea how to do for Vimeo?

Here is same question, without any answer.

+1  A: 

Actually the guy who asked that question posted his own answer.

"Vimeo seem to want me to make a HTTP request, and extract the thumbnail URL from the XML they return..."

The Vimeo API docs are here: http://vimeo.com/api/docs/simple-api

In short, your app needs to make a GET request to an URL like the following:

http://vimeo.com/api/v2/video/video_id.output

and parse the returned data to get the thumbnail URL that you require, then download the file at that URL.

Ian Kemp
+8  A: 

From the Vimeo Simple API docs:

Making a Video Request
To get data about a specific video, use the following url:

http://vimeo.com/api/v2/video/video_id.output
video_id
The ID of the video you want information for.
output
Specify the output type. We currently offer JSON, PHP, and XML formats.

So getting this URL http://vimeo.com/api/v2/video/6271487.xml

    <videos> 
      <video> 
        [skipped]
<thumbnail_small>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_100.jpg&lt;/thumbnail_small&gt; 
        <thumbnail_medium>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_200.jpg&lt;/thumbnail_medium&gt; 
        <thumbnail_large>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_640.jpg&lt;/thumbnail_large&gt; 
        [skipped]
    </videos>

Parse this for every video to get the thumbnail

Here's approximate code in PHP

<?
$imgid = 6271487;

$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
print_r($hash);  



?>
roddik
OK, nice. I'm not familiar with `xml` though. How can I get `thumbnail_small` with `php`?
Johan
To get it with PHP, first use php extension in URL like http://vimeo.com/api/v2/video/6271487.php, you'll be provided with a file, first line of which seems to be a serialized php hash, use unserialize and then simply read the entries you want
roddik
Sorry the whole file is serialized info
roddik
Excellent! Tank you very much. :)
Johan
echo $hash[0]['thumbnail_medium'];
roddik
+1  A: 

With Ruby, you can do the following if you have, say:

url                      = "http://www.vimeo.com/7592893"
vimeo_video_id           = url.scan(/vimeo.com\/(\d+)\/?/).flatten.to_s               # extract the video id
vimeo_video_json_url     = "http://vimeo.com/api/v2/video/%s.json" % vimeo_video_id   # API call

# Parse the JSON and extract the thumbnail_large url
thumbnail_image_location = JSON.parse(open(vimeo_video_json_url).read).first['thumbnail_large'] rescue nil
Michel Barbosa
+1  A: 

Here's a simple PHP Function to do the trick:

http://www.soapboxdave.com/2010/04/getting-the-vimeo-thumbnail/

David
A: 

I wrote a function in PHP to let me to this, I hope its useful to someone. The path to the thumbnail is contained within a link tag on the video page. This seems to do the trick for me.

    $video_url = "http://vimeo.com/7811853"  
    $file = fopen($video_url, "r");
    $filedata = stream_get_contents($file);
    $html_content = strpos($filedata,"<link rel=\"videothumbnail");
    $link_string = substr($filedata, $html_content, 128);
    $video_id_array = explode("\"", $link_string);
    $thumbnail_url = $video_id_array[3];
    echo $thumbnail_url;

Hope it helps anyone.

Foggson

A: 

Here is an example of how to do the same thing in ASP.NET using C#. Feel free to use a different error catch image :)

public string GetVimeoPreviewImage(string vimeoURL)
{
    try
    {
        string vimeoUrl = System.Web.HttpContext.Current.Server.HtmlEncode(vimeoURL);
        int pos = vimeoUrl.LastIndexOf(".com");
        string videoID = vimeoUrl.Substring(pos + 4, 8);

        XmlDocument doc = new XmlDocument();
        doc.Load("http://vimeo.com/api/v2/video" + videoID + ".xml");
        XmlElement root = doc.DocumentElement;
        string vimeoThumb = root.FirstChild.SelectSingleNode("thumbnail_medium").ChildNodes[0].Value;
        string imageURL = vimeoThumb;
        return imageURL;
    }
    catch
    {
        //cat with cheese on it's face fail
        return "http://bestofepicfail.com/wp-content/uploads/2008/08/cheese_fail.jpg";
    }
}
Mtblewis