Hey Everyone!
I'm having a cURL problem. basically i am looking at this
I'm trying to download a video from a website. It is free for members, and i am a member, however i would like to download them automatically through curl [i believe this would be the best way to do it].
here is what i have:
Code:
$values = form_handle_input("videos_import_url");
/////////////////////////////////////////////////////////
$LOGINURL = "http://www.DOMAIN.com/login.php";
$id = "USER"; $password = "PASS";
$POSTFIELDS = 'username='.$id.'&password='.$password;
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
$reffer = "http://www.ORIGINALDOMAIN.com";
$hash = build_unique_path(DOC_ROOT."/vid",".flv");
$dist_file = DOC_ROOT."/vid/".$hash.".flv";
$flash = fopen( $dist_file, 'wb' );
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $values["url"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
$url = curl_exec($curl);
curl_setopt($curl, CURLOPT_URL,$LOGINURL);
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $POSTFIELDS);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
$store = curl_exec ($curl);
curl_setopt($curl, CURLOPT_URL,$values["video"]);
curl_setopt($curl, CURLOPT_REFERER, $values["url"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
curl_setopt($curl, CURLOPT_COOKIE, 1);
curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
$flv = curl_exec($curl);
// print($flv);exit;
fwrite($flash,$flv);
fclose($flash);
curl_close($curl);
///////////////////////////////////////////////////////
But i get a 403 error. [i find this out by editting the flv that is saved]. I can download images this way on the same server, but the videos are probably a little more advanced. Any ideas ? As you can see i'm already trying to make my curl be a "browser" with cookies and referer and still no good
Thanks in advance!
brandon