bug7sec

Joox - Download Manager

Oct 24th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.04 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. class Joox
  4. {
  5.     function ngecurl($url , $post=null , $header=null){
  6.         mkdir("Download");
  7.         $ch = curl_init($url);
  8.         if($post != null) {
  9.             curl_setopt($ch, CURLOPT_POST, true);
  10.             curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  11.         }
  12.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 8_3_3 like Mac OS X; en-SG) AppleWebKit/537.25 (KHTML, like Gecko) Version/7.0 Mobile/8C3 Safari/6533.18.1");
  14.         curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'temp/'."cookies.txt");
  15.         curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'temp/'."cookies.txt");
  16.         curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  17.         if($header != null) {
  18.             curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  19.         }
  20.         curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  21.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
  22.         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  23.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  24.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  25.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  26.         return curl_exec($ch);
  27.         curl_close($ch);
  28.     }  
  29.     function bersih($data){return preg_replace('/\s+/', '', $data);}
  30.     function decode($data){
  31.         foreach ($data as $is) {
  32.             $data[] = base64_decode($is);
  33.         }
  34.         return $data;
  35.     }
  36.     function parsing($data){
  37.         $regex = array(
  38.             'judul'     =>  '/"info1":"(.*?)"/',
  39.             'penyanyi'  =>  '/"name":"(.*?)"/',
  40.             'album'     =>  '/"info3":"(.*?)"/',
  41.             'songid'    =>  '/"songid":"(.*?)"/',
  42.         );
  43.         foreach ($regex as $label => $regexnya) {
  44.             preg_match_all($regexnya, $data, $matches);
  45.             if($label != "songid"){
  46.                 foreach ($matches[1] as $key => $datanya) {
  47.                     $result_[] = base64_decode($datanya);
  48.                 }
  49.                 $result[] = array($label => $result_);
  50.                 unset($result_);
  51.             }else{
  52.                 $result[] = array($label => $matches[1]);
  53.                 unset($result_);
  54.             }
  55.         }
  56.         return $result;
  57.     }
  58.     function readline($pesan){
  59.         echo "[Download Mp4a/mp3] ".$pesan;
  60.         $answer =  rtrim( fgets( STDIN ));
  61.         return $answer;
  62.     }
  63.     function secondsToTime($seconds) {
  64.       $hours = floor($seconds / (60 * 60));
  65.       $divisor_for_minutes = $seconds % (60 * 60);
  66.       $minutes = floor($divisor_for_minutes / 60);
  67.       $divisor_for_seconds = $divisor_for_minutes % 60;
  68.       $seconds = ceil($divisor_for_seconds);
  69.       $obj = array(
  70.           "h" => (int) $hours,
  71.           "m" => (int) $minutes,
  72.           "s" => (int) $seconds,
  73.        );
  74.       return $obj;
  75.     }
  76.     function times(){
  77.         $time = microtime();
  78.         $time = explode(' ', $time);
  79.         return $time[1] + $time[0];
  80.     }
  81.     function download($judul,$url){
  82.         $start = $this->times();
  83.         echo "[Download Mp4a/mp3] Download Size : ";
  84.         $fp = fopen ("Download/".$judul, 'w+');
  85.         $ch = curl_init();
  86.         curl_setopt( $ch, CURLOPT_URL, $url );
  87.         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
  88.         curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
  89.         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
  90.         curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
  91.         curl_setopt( $ch, CURLOPT_FILE, $fp );
  92.         curl_exec( $ch );
  93.         curl_close( $ch );
  94.         fclose( $fp );
  95.         $end = $this->times();
  96.         $time = $this->secondsToTime(round(($end - $start), 1));
  97.         if(filesize("Download/".$judul) > 0){
  98.             echo $this->formatSizeUnits( filesize("Download/".$judul) )." | Selesai pada ".$time[m]." menit ".$time[s]." detik\r\n";
  99.         }else{
  100.             echo $this->formatSizeUnits( filesize("Download/".$judul) )." (Gagal)\r\n";
  101.         }
  102.     }
  103.     function getHeaders($url){
  104.       $ch = curl_init($url);
  105.       curl_setopt( $ch, CURLOPT_NOBODY, true );
  106.       curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
  107.       curl_setopt( $ch, CURLOPT_HEADER, false );
  108.       curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  109.       curl_setopt( $ch, CURLOPT_MAXREDIRS, 3 );
  110.       curl_exec( $ch );
  111.       $headers = curl_getinfo( $ch );
  112.       curl_close( $ch );
  113.       return $headers;
  114.     }
  115.     function formatSizeUnits($bytes)
  116.     {
  117.         if ($bytes >= 1073741824)
  118.         {
  119.             $bytes = number_format($bytes / 1073741824, 2) . ' GB';
  120.         }
  121.         elseif ($bytes >= 1048576)
  122.         {
  123.             $bytes = number_format($bytes / 1048576, 2) . ' MB';
  124.         }
  125.         elseif ($bytes >= 1024)
  126.         {
  127.             $bytes = number_format($bytes / 1024, 2) . ' kB';
  128.         }
  129.         elseif ($bytes > 1)
  130.         {
  131.             $bytes = $bytes . ' bytes';
  132.         }
  133.         elseif ($bytes == 1)
  134.         {
  135.             $bytes = $bytes . ' byte';
  136.         }
  137.         else
  138.         {
  139.             $bytes = '0 bytes';
  140.         }
  141.         return $bytes;
  142.     }
  143.     function pencarian($katakunci)
  144.     {
  145.         $data = $this->bersih($this->ngecurl("http://api.joox.com/web-fcgi-bin//web_search?callback=jQuery110003061714756163918_1477336272879&lang=id&country=id&type=0&search_input=".urlencode($katakunci)));
  146.         $data = $this->parsing($data);
  147.         $judul    = $data[0][judul];
  148.         $penyanyi = $data[1][penyanyi];
  149.         $album    = $data[2][album];
  150.         $songid   = $data[3][songid];
  151.             echo ".-[ID]-|------[ PENYANYI ]--------.--------------[ JUDUL LAGU ]--------------.\r\n";
  152.         foreach ($data[0][judul] as $keyID => $string) {
  153.             if(strlen($keyID) == 1){
  154.                 echo "|  ".$keyID."   | ".$penyanyi[$keyID];
  155.                 for ($i=strlen($penyanyi[$keyID]); $i <25; $i++) {
  156.                     echo " ";
  157.                 }
  158.                 echo "| ".substr($string, 0, 40);
  159.                 for ($i=strlen($string); $i <40; $i++) {
  160.                     echo " ";
  161.                 }
  162.                 echo " |    \r\n";
  163.             }else{
  164.                 echo "|  ".$keyID."  | ".$penyanyi[$keyID];
  165.                 for ($i=strlen($penyanyi[$keyID]); $i <25; $i++) {
  166.                     echo " ";
  167.                 }
  168.                 echo "| ".substr($string, 0, 40);
  169.                 for ($i=strlen($string); $i <40; $i++) {
  170.                     echo " ";
  171.                 }
  172.                 echo " |\r\n";
  173.             }
  174.         }
  175.         echo "\----------------------------------------------------------------------------/\r\n";
  176.         $IDnya = $this->readline("Pilih ID Lagu (0 - ".(count($data[3][songid])-1).")  : ");
  177.         $IDnya = explode(",", $IDnya);
  178.         foreach ($IDnya as $key => $idLagu) {
  179.             if($idLagu != null && isset($songid[$idLagu])){
  180.                 echo "\r\n[Download Mp4a/mp3] Judul Lagu : ".$penyanyi[$idLagu]." - ".$judul[$idLagu]." (".$key."/".count($IDnya).")\r\n";
  181.                 $data = $this->bersih($this->ngecurl("http://api.joox.com/web-fcgi-bin/web_get_songinfo?songid=".$songid[$idLagu]."&lang=id&country=id&from_type=-1&channel_id=-1"));
  182.                 $mp4a = '/"m4aUrl":"(.*?)"/';
  183.                 $mp3  = '/"mp3Url":"(.*?)"/';
  184.                 preg_match_all($mp4a, $data, $matchesmp4a);
  185.                 preg_match_all($mp3, $data, $matchesmp3);
  186.                 if($matchesmp4a[1][0] != null){
  187.                     $this->download( $penyanyi[$idLagu]." - ".$judul[$idLagu].".mp4a" ,$matchesmp4a[1][0]);
  188.                 }else if($matchesmp3[1][0] != null){
  189.                     $this->download( $penyanyi[$idLagu]." - ".$judul[$idLagu].".mp3" ,$matchesmp3[1][0]);
  190.                 }else{
  191.                     echo "\r\n[Download Mp4a/mp3] Link ".$penyanyi[$idLagu]." - ".$judul[$idLagu]." Tidak ada\r\n";
  192.                 }
  193.             }else{
  194.                 $this->start();
  195.             }
  196.         }
  197.         $this->start();
  198.     }
  199.     function start(){
  200.         $this->pencarian($this->readline("Masukan kata pencarian : "));
  201.     }
  202. }
  203. $Joox = new Joox;
  204. $Joox->start();
  205. ?>
Add Comment
Please, Sign In to add comment