Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Dailymotion FLV

13 replies [Last post]

Hi everyone,

I think I have found an "almost complete" solution to fetch flv from dailymotion.
Only problem is that I'm only able to copy flvs' data from dailymotion to the new files on my server. I haven't yet found a way to send cookie, got from dailymotion, along with the header() function to the second and last url. If there is someone how knows how to do it, please help...

<?php
$ch
= curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.dailymotion.com/video/x9hur6_shadow-complex-e3-trailer_videogames");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$buf = curl_exec($ch);
curl_close($ch);
unset(
$ch);

preg_match('/"video", "(.*?)"/', $buf, $match);
$urls = preg_split('/@@(.*?)\|\|/', urldecode($match[1]));

//Let's use only regular flv file
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "./tmp/dailymotion_cookie.txt");
curl_setopt($ch, CURLOPT_URL, $urls[0]);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_exec($ch);
$header = curl_getinfo($ch);
curl_close($ch);

unset(

$ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, "./tmp/dailymotion_cookie.txt");
curl_setopt($ch, CURLOPT_URL, $header['url']);

// Adjust so that the server has enough time
// to download the flv from dailymotion.
// About (flv filesize)/(server download speed).
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$flv = curl_exec($ch);
curl_close($ch);

// Write flv data to file
$video = "./tmp/dailymotion.flv";
$fh = fopen($video, 'w') or die("can't open file");
fwrite($fh, $flv);
fclose($fh);
?>

Remember to create new directory called tmp to the same directory you put this script.

Regards, M@rk$

i noticed that old methods were not working anymore.

are dailymotion urls now IP specific (like Megavideo)?

regards.

So the thing is this. This is just an example.

If you look at the script above (lines 1-14 counting from "<?php"), it first fetches the url of the wanted flv from dailymotion's source code.

EXAMPLE URL: http://www.dailymotion.com/cdn/FLV-320x240/video/x9hur6?auth=1253865889-5e8e5e8c1975ca3f1d0c1a1229493b65

After this the script makes its first request with curl to the fetched url. Response is this:

Array
(
    [0] => HTTP/1.1 303 See Other
    [1] => Vary: Accept-Encoding
    [2] => P3p: policyref="http://www.dailymotion.com/w3c/p3p.xml", CP="IDC DSP CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT"
    [3] => Set-Cookie: XGEOIP=69f9b57f44ef939b:Idcd124ae:C225:ATX:RVGV4YXM=:LRGFsbGFz:Z75207:X32.7825000000000:Y-96.8207000000000:SAS36351:N; path=/; domain=.dailymotion.com
    [4] => X-Dm-Backnode: sc-08.srv.dailymotion.com:80
    [5] => Content-Length: 0
    [6] => Date: Wed, 23 Sep 2009 07:57:39 GMT
    [7] => X-Dm-Cell: core, rule=40, vars=
    [8] => Connection: Keep-Alive
    [9] => Location: http://proxy-35.dailymotion.com/18/320x240/flv/15949554.flv?auth=1253692959-dc7337f52ec3ea509aac5cbd53ac64a4
    [10] => Server: DMS/1.0.42
    [11] => Content-Type: text/html; charset=utf-8
    [12] => HTTP/1.0 200 OK
    [13] => Date: Wed, 23 Sep 2009 07:57:39 GMT
    [14] => Server: Apache
    [15] => ETag: d8c6d0862e5c934cae8797aa4d71f9ed
    [16] => Accept-Ranges: bytes
    [17] => X-Accept-TimeURI: npt, smpte-24, smpte-24-drop, smpte-25, smpte-30, smpte-30-drop
    [18] => X-Edge-Version: 1.5.1
    [19] => Last-Modified: Tue, 22 Sep 2009 11:30:52 GMT
    [20] => Content-Length: 5084198
    [21] => Connection: close
    [22] => Content-Type: video/x-flv
)

Like you see, there is a key number three which sets the cookie and with curl we are able to write it to the tmp/dailymotion_cookie.txt file for later use (lines 16-24).

After this the script uses the same url we fetched but now curl is set to follow redirects and use the cookie we got (lines 29-46) from previous request. With the cookie dailymotion's server doesn't throw 403 Forbidden in the url the script was redirected to but instead throws 200 Ok.

EXAMPLE URL: http://proxy-35.dailymotion.com/18/320x240/flv/15949554.flv?auth=1253693959-5d8bdf75c6ad5bf97dc4abc8...

On lines the reponse is written to the file called dailymotion.flv (49-42).

But yes, I think it's IP specific... :)

Btw, I also noticed that keepvid.com and clipnabber.com are also failing with their dailymotion-flv-fetching.

Regards, M@rk$

i have tried my own script with file_get_contents() and get_headers() without any cookies and i get 200 OK when requesting the flv file on my server, but if i display it for the end user (client), it shows them 403 forbidden (like keepvid and clipnabber).

Hmm, weird. Maybe we don't need the cookies then? I need to try that too.

Yeah, it worked that way too.

<?php
$content
= file_get_contents("http://www.dailymotion.com/video/x9hur6_shadow-complex-e3-trailer_videogames");

preg_match('/"video", "(.*?)"/', $content, $match);
$urls = preg_split('/@@(.*?)\|\|/', urldecode($match[1]));

$headers = get_headers($urls[0]);

$flv = file_get_contents(str_replace('Location: ', '', $headers[9]));

$file = "tmp/dailymotion.flv";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $flv);
fclose($fh);
?>

Little bit shorter now.... :)

@joacobL, do you think there is no way to get flv url to be displayed for the client side?

Regards M@rk$

ok so i noticed this...

if the final url starts with "video akm" then the url can be downloaded

but if it starts with "proxy" then it shows 403 forbidden

This is what i think it is:
creativecontent = 403
originalcontent = video akm

the 403 cant be fixed. make a check for get_headers() to see if its location is proxy and if it is, you will have to download the flv to your server then show the link to the client.

it sucks because it takes all your bandwidth :(

btw nice script :)

How to use ur code M@rk$

any of you make progress on this... as i got the same issue.. i have a similar script i made.. but i getting the exact the same errors.. weird thing is that it works on WAMP locally but on the live server it does not work..

if someone that knows about this and wants to discuss please instant message me

subfighter.tv at gmail.com

maybe we can figure it out.. thanks

it works locally of course because the IP that gets the download link is your local IP and only your local IP can access the "proxy" urls.

I was thinking maybe using jquery copy to bypass cross-domain policies to get the urls client side, then you can manipulate them however you want. but this may not work.

ughhh jquery can't get past cross domain policies because javascript can only run locally and not access external source code.

if domain=domaina.com - it can't access domainb.com

what exactly, is doing your code?

What exactly, is doing these code?

spaniol - what do you mean?