<?
#ini_set('display.errors','1');
#error_reporting(E_ALL | E_STRICT);
$url1 = 'http://rapidshare.com/files/1234567890/TESTDATEI.rar';
// Normalen RS-Link nutzen um neuen Linktyp zu erhalten
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 9000);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009011913 Firefox/3.0.6');
$page_link = curl_exec($ch);
curl_close($ch);
echo "URL 1 ------------<a href='".$url1."'>".$url1."</a>-----------<br>";
$quelltext1 = strstr($page_link, '/#!');
$quelltext1 = substr($quelltext1, 0, (strpos($quelltext1, '";')));
echo "<br><br><br>";
ob_flush();
// Neuen RS-Link aufsplitten
$url2 = explode("|", $quelltext1);
###echo $quelltext1;
echo "URL 2 ------------/#!download|".$url2[1]."|".$url2[2]."|".$url2[3]."|".$url2[4]."-----------<br>";
echo "<br><br><br>";
ob_flush();
echo "ERROR ------------".$url2[5]."-----------<br>";
echo "<br><br><br>";
ob_flush();
// API Anfrage mit neuen RS-Link Teilen aufbauen
$url3 = 'http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download_v1&fileid='.$url2[2].'&filename='.$url2[3].'&try=1';
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url3);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch2, CURLOPT_AUTOREFERER, true);
curl_setopt($ch2, CURLOPT_NOPROGRESS, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_TIMEOUT, 9000);
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009011913 Firefox/3.0.6');
$page_link = curl_exec($ch2);
curl_close($ch2);
echo "URL 3 ---------------------".$url3."---------------<br>";
$quelltext2 = str_replace('script', ' ', $page_link);
#echo $page_link;
echo "<br><br><br>";
ob_flush();
$apireturn = explode(':', $quelltext2);
$apireturn2 = explode(',', $apireturn[1]);
###print_r($apireturn2);
echo "<br><br><br>";
ob_flush();
// API Abfrageergebnis nach JS-Funktion neu aufbauen
$auth = '#!download|'.$url2[1].'|'.$url2[2].'|'.$url2[3].'|'.$url2[4];
echo "auth ---------".$auth."----------------------";
echo "<br><br><br>";
ob_flush();
// Mit definitivem Downloadlink Datei holen
$dlurl = 'http://'.$apireturn2[0].'/cgi-bin/rsapi.cgi?sub=download_v1&editparentlocation=0&bin=1&fileid='.$url2[2].'&filename='.$url2[3].'&dlauth='.$apireturn2[1].$auth;
echo 'DL URL -----<a href="'.$dlurl.'">'.$dlurl.'</a>------------ DL-Zeit : '.($apireturn2[2]).'------------';
echo "<br><br><br>";
ob_flush();
if($url2[5] == ""){
echo 'Waiting for '.($apireturn2[2]).'+10 seconds!<br>';
flush();ob_flush();
// Zwangspause
$i = 1;
while($i <= ($apireturn2[2]+10)){
echo $i.'-';
if($i == 60 or $i == 120){ echo "<br>"; }
flush();ob_flush();
sleep(1);
$i++;
}
$file = $url2[3];
echo "<br>".$file."<br>";
$handle = fopen('downloads/'.$file,'w');
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, $dlurl);
#curl_setopt($ch3, CURLOPT_TIMEOUT, 90000);
#curl_setopt($ch3, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
curl_setopt($ch3, CURLOPT_FILE, $handle);
#curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch3, CURLOPT_HEADER, 0);
curl_setopt($ch3, CURLOPT_BINARYTRANSFER, 1);
$dlerg = curl_exec($ch3);
fclose($handle);
echo "<br>Error is : ".curl_error($ch3);
curl_close($ch3);
echo "<br><br>...###".$dlerg."###...<br><br>";
ob_flush();
$handle = fopen('dlfile.txt','w');
fwrite($handle, $page_link);
fclose($handle);
}else{
echo "Aktuell kein DL möglich";
}
?>