Guest User

Filesonic Stream Script

a guest
Jan 7th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1. <?php
  2. if(!empty($_GET['dl'])){
  3.     /***************************\
  4.     #    Filesonic stream shit   #
  5.     #    Robin@houtevelts.com    #
  6.     #    http://file-remoter.com #
  7.     #    25-dec-2011             #
  8.     \****************************/
  9.      
  10.     $username = $_GET['username'];
  11.     $password = $_GET['password'];
  12.      
  13.     $url = $_GET['url'];
  14.      
  15.     $regex = '#/file/(.*?)(/|$)#';
  16.     $matches = array();
  17.     preg_match($regex, $url, $matches);
  18.     $id = str_replace('/', '-', $matches[1]);
  19.     unset($matches,$regex);
  20.      
  21.     $fileinfo = file_get_contents('http://api.filesonic.com/link?method=getInfo&format=json&ids='.$id);
  22.     $fileinfo = json_decode($fileinfo,1);
  23.     $fileinfo = $fileinfo['FSApi_Link']['getInfo'];
  24.      
  25.     if($fileinfo['status'] != 'success')
  26.         die('API Error! mofo');
  27.      
  28.     $fileinfo = $fileinfo['response']['links'][0];
  29.      
  30.     if($fileinfo['status'] != 'AVAILABLE')
  31.         die('File is no moar!');
  32.  
  33.      
  34.     $filename = $fileinfo['filename'];
  35.     $filesize = $fileinfo['size'];
  36.  
  37.      
  38.     $url = file_get_contents('http://api.filesonic.com/link?method=getDownloadLink&u='.$username.'&p='.$password.'&ids='.$id);
  39.     $url = json_decode($url,1);
  40.     $url = $url['FSApi_Link']['getDownloadLink'];
  41.      
  42.     if($url['status'] != 'success')
  43.         die('API Error! mofo');
  44.      
  45.     $url = $url['response']['links'];
  46.     $url = end($url);
  47.     $url = $url['url'];
  48.      
  49.      
  50.     //The actual shit
  51.     $url = $url;
  52.     $host = parse_url($url);
  53.     $headers = '';
  54.     $rn = "\r\n";
  55.      
  56.     $headers .= 'GET '.$host['path'] . ($host['query'] == true ? '?'.$host['query'] : '').' HTTP/1.1' . $rn;
  57.     $headers .= 'Host: '.$host['host'] . $rn;
  58.     $headers .= 'Accept: */*' . $rn . $rn;
  59.      
  60.     $fs = fsockopen($host['host'],80,$errno,$errstr,30);
  61.     if($errno||$errstr){
  62.         echo 'ERROR: '.$errstr;
  63.         @fclose($fs);
  64.         exit;
  65.     }
  66.     fwrite($fs,$headers);
  67.     unset($headers);
  68.      
  69.     $header = '';
  70.      
  71.     do {
  72.         $header .= fgets ( $fs, 16384 );
  73.     }while(strpos($header,$rn.$rn) === false);
  74.      
  75.     /*
  76.         $header now contains the received headers
  77.         You could fetch the filesize etc from it etc, but we already know it.
  78.         But since I'm such a nice guy:
  79.     */
  80.     $filesize = preg_match('#Content-Length: (\d+)#',$header,$match);
  81.     $filesize = trim($match[1]);
  82.     unset($match,$header);
  83.      
  84.     header('Content-Length: '.$filesize);
  85.     header('Content-Disposition: attachment; filename="' . $filename . '"');
  86.     header('Connection: Close');
  87.      
  88.     while (!feof($fs)){
  89.         echo fread($fs,8192);
  90.     }
  91.     fclose($fs);
  92.      
  93. }else{
  94. ?>
  95.     <html>
  96.         <head>
  97.             <title>Filesonic direct link creator or whatever you want to use this for</title>
  98.         </head>
  99.         <body>
  100.             <form action="" method="GET">
  101.                 <input type="hidden" name="dl" value="1" />
  102.                 Filesonic Username: <input type="text" name="username" />
  103.                 Filesonic Password: <input type="text" name="password" />
  104.                 <br />
  105.                 Url: <input type="text" name="url" />
  106.                 <br />
  107.                  
  108.                 <input type="submit" value="Download" />
  109.             </form>
  110.         </body>
  111.     </html>
  112. <?php
  113. }
  114. ?>
Add Comment
Please, Sign In to add comment