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.