Getting Dailymotion Video (FLV) URL

Some developers asked me, if it is easy to get dailymotion flv URL? I thought, I would post how to do that.

If you know the dailymotion video-id, believe me it’s very simple to do that. In case, you don’t know how to get dailymotion video-id?  Let me give you some hints, highlighted text is the video-id:-

Once you have video-id, you can use the following php-script (dailymotion.php.txt) to do either of two things:-

  • Get flv and thumbnail-url
    • http://yourserver/dailymotion.php?video_id=<video_id>&redirect=false
      • Returns: flv=<flv_url>thumbnail=<thumbnail_url>
  • Redirect to dailymotion flv-url directly. It can be used directly from Netstream’s play (<url>) instance method
    • http://yourserver/dailymotion.php?video_id=<video_id>&redirect=true
      • Redirects (HTTP 303) to flv_url.

// PHP code for getting dailymotion flv-path and more info.
// Author: Abdul Qabiz
// Jan 22, 2008
//Params:- Requires dailymotion video_id
// USAGE:-
// 1) For information
// http://server/dailymotion.php?video_id=&redirect=true
// Above invocation would return:-
// flv=&thumbnail=
// Example:-
// URL: http://server/dailymotion.php?video_id=x44ls3&redirect=false
// Result:-
// flv=
// 2) For redirection to flv i.e. video_id to flv
// http://server/dailymotion.php?video_id=&redirect=true
// Above invocation would redirect to dailymotion flv URL
if (isset ($_GET ['video_id']) == FALSE)
echo "video_id is required";
// Requires dailymotion video_id
$url = '' . $_GET['video_id'];
if (isset($_GET['redirect']) == FALSE)
$redirect = 'true';
//Start the Curl session
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071025 Firefox/');
curl_setopt($session, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$response = curl_exec($session);
$error = curl_error($session);
$result = array( 'header' => '',
'body' => '',
'curl_error' => '',
'http_code' => '',
'last_url' => '');
if ( $error != "" )
$result['curl_error'] = $error;
$header_size = curl_getinfo($session,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($session, CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($session, CURLINFO_EFFECTIVE_URL);
list($header,  $result['header']) = explode("\n\n",  $result['header'], 2);
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$urlInfo = parse_url(trim(array_pop($matches)));
//$newUrl = $urlInfo['scheme'] . '://' . $urlInfo['host'] . $urlInfo['path'] . ($urlInfo['query']?'?'.$urlInfo['query']:'');
parse_str($urlInfo['query'], $output);
$flvURL = $output ['url'];
$thumbnailURL = $output['previewURL'];
if ($redirect == "true")
header ("Location: ". $flvURL, TRUE, 303);
echo sprintf ("flv=%s&thumbnail=%s", $flvURL, $thumbnailURL);

Let me tell you, you can do the entire thing on client-side without using any server-side script, though logic remains same. Look at this post and learn what technique to use :-). Another hint, if you are consuming dailymotion rss-feed(s), you don’t need any php script to construct flv-url, you can just replace “80×40” text by “320×240” in media:content url.

As always, please look at the code, change, optimize and fix it to meet your requirements. I wrote it in ten minutes and just as a proof-of-concept, this is no way the best method and php-code can be much better.

Technorati Tags: , ,

  • were should i keep the video_id .
    when i call this code its saying video_id is required

  • Hi,
    I’ve copy your script on a test.php file, but it doesn’t work.
    Any Idea ?

  • @etienne: It seems you don’t have CURL module installed on your server… It works fine, I tested..
    Install the PHP CURL extension..

  • Your script has stopped working after the recent changes by dailymotion. Could you look into it?

  • Khan

    I am developer and followed exactly, but the result i no flv url not thumb url
    resut is “flv=&thumbnail=”
    Do you think dailymotion has changed the mechanism ?

  • i am also getting only the “flv=&thumbnail=” with this script. so i have tried with
    the video info xml contain the flv url with a dynamic key. i am able to grab the flv url from my local server. but when i tried it in the remote server the flv is not downloding.
    please can you help me?

  • suresh

    I am also doing myself on this task. But still i don’t get any result using this code.
    When i am giving this url it dosen’t show anything. Mr.Khan can u send your code which ever you can get thumbnail and photo to use this code. If u send it i am very thank full to you.

  • It works OK, but Dailymotion has changed their system again, so the script to grab their FLV’s need to be changed too. You can find the FLV url in the source code of the video page, at addVariable(“video”,….) with preg_match and then get headers of this URL with CURL. I use it on my site and it works fine now.

  • @Uzeik: You are right, they have changed the system and the method you mentioned is the one that works now. I investigate and found the same ๐Ÿ™‚

  • praveen castelino

    does anybody know to construct webshots download url?

  • Parece que DailyMotion genera el parametro KEY=xxxx acorde a la IP del usuario.
    Yo leo el RSS del video. luego Parseo la direccion buscando el FLV…. But error 403… ๐Ÿ™
    Heeeeelp @UZEIK

  • Yo mismo me contesto, Solucion: Leer el RSS de el lado del cliente asi el KEY generado es el Key que sirve para hacer la descarga(No leer el RSS en el Server, para luego devolver el KEY)

  • Durai

    so.addVariable(‘video’, ‘dailymotion.php?video_id=x6msvc_dancing-traffic-cop_fun&redirect=true’)
    and I’ve copy your script(above php script) on a dailymotion.php
    but it doesn’t play the video,please help me..
    please give me the code

  • SAM

    =>I followed the method posted by “Suresh” , but stil am not getting the “FLV URL”….
    vieo_id= ‘xxxxxxxxxxxxxxxx’
    and i’ve copied the above script on dailymotion.php..
    but still not working.

  • Ayyadurai

    Hi Friends,
    This is correct FLV Path for dailymotion video
    try this i have implemented this is working..×240/flv/11034301.flv?key=78db4df648c088468478aaefd429d4701371041

  • rmic

    can somebody post the last php content with the corrections please ๐Ÿ™‚ thank you

  • Roman

    Dear Abdul,
    it’s a bit offtopic for this post, but hope you would forgive me ๐Ÿ™‚
    Do you know of any solution to get a final (after redirect) url for progressively downloaded FLV? Either AS2 or AS3.
    We have Sockets in AS3 and can use it to send a request and parse reply, get new location and start netstream with that location. But my specific setup is a cross-domain request and I need a cookie in a request. I can make a javascript call to the second domain and get cookie as a js reply and provide this cookie to SWF via flashvars.
    But this is the least desired method.
    It would be handy to get this string directly from netstream, but looks like there’s no such option. Probably we can rewrite or extend netstream class with the desired behavior.
    Thank you for any responce!
    BR, Roman

  • Ed

    Any way to get this to work now?

  • Hi Guys
    It’s been while since I updated this script, not sure it works now or not. Dailymotion keeps changing the way they do things.
    Sorry for delaying replying. Specially, Roman sorry I have been so occupied couldn’t even read some comments. Shame on me ๐Ÿ™
    I hope, you guys have figured things you asked here.
    I would take care of these in future.

  • doonrothmani

    the string “” is the correct feed to get the underlying flv. running this on your local server will work. it’s a sandbox violation though, if you run it from a web server
    if would seem that a solution for this might be
    feeding a php file with “” as the url parameter, but this returns an incorrect flv key value from daily motion. if you do this in a browser you will get a “cute” message from dailymotion chiding you for trying to “sneak around” so this result is obviously deliberate on dailymotion’s part.
    parsing the html from will also provide you with an incorrect flv key value.
    so there seems to be no OBVIOUS way to broadcast or download the underlying daily motion flv from a web server.
    the good news is its fairly easy, using the rss feed, to download and broadcast dailymotion flvs from your pc.

  • Ayyadurai

    Hi Guys,
    I think the dailymotion video flv has been changed Please can any post it.

  • mmm

    Hi Abdul,

    Dailymotion video flv has been changed.

    Can you please update the script.

  • loop32

    Damn, not work, please inform me if you find fix. Thanks

    • Arpan

      not working……

  • Gbg Leaks finded the solution of this matter clearly as you want convert any format dailymotion video just visit