How to get video thumbnails from dailymotion?

Notice: Dailymotion changed the way they serve thumbnails. It is no longer possible to fetch them

You can get thumbnails from YouTube easily using their API, but Dailymotion does not have API or any other intuitive way to download jpeg from specific video. I made a little research and found a solution, that at least work for me. When you are scanning webpages for videos you find embed tags with videos similiar to the one below:

<embed src="http://www.dailymotion.com/swf/IHnP80wxWqFSlg4ms" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" height="363" width="425"></embed>

At first I thought that I can get thumbnail using swf parameter IHnP80wxWqFSlg4ms. But it was wrong. We need first get the effective URL (after HTTP 302, or HTTP Location header forwarding). We can do it using libcurl:

function getEffectiveUrl($url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_exec($ch);>

  $newurl = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
  curl_close($ch);

  return urldecode($newurl);
}

Our effective URL looks like this:

http://www.dailymotion.com/flash/flvplayer.swf?rev=1198003823&
statEnabled=1&selfURL=http://www.dailymotion.com/Gregouze7
/video/x2a39c_just-jack-starz-in-their-eyes_music&
(it is really long!)

Now we can get from the effective URL two important information - key and title using the following simple regular expression:

#video/([a-z0-9]+)_([a-z0-9-]+)#i”

So our key is x2a39c. We fetch the thumbnail from:

http://www.dailymotion.com/thumbnail/320×240/video/[key]

And that’s it. There also other sizes available like 160×120.

5 Responses to “How to get video thumbnails from dailymotion?”

  1. anurag Says:

    This code doesn’t seem to work for me…. Did DailyMotion change the way they serve images?

  2. Jamie Says:

    This didn’t work for me.
    Whatever URL I passed into the function was also returned by the function without change.

    for example if I do this:
    getEffectiveUrl(’http://www.dailymotion.com/swf/IHnP80wxWqFSlg4ms’);
    it returns this:
    ‘http://www.dailymotion.com/swf/IHnP80wxWqFSlg4ms’

  3. TigerTom Says:

    A sweet bit of code. Curl: Is there _nothing_ you can’t do?

  4. Durai Says:

    i have followed your code but not getting any thing

    #video/([a-z0-9]+)_([a-z0-9-]+)#i”

    http://www.dailymotion.com/thumbnail/320×240/video/key

    Please explain briefly…..

  5. mauser Says:

    Dailymotion changed the way they serve thumbnails. It is no longer possible to fetch them :(

Leave a Reply

Comment spam protected by SpamBam