Techno

Songs.pk grabber [ technoslab.blogspot.com ]

Mar 23rd, 2011
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.65 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. SONGS.PK GRABBER - Created by Techno
  6.  
  7. Visit http://technoslab.blogspot.com for more
  8.  
  9. Dependency -> GetID3
  10.  
  11. */
  12.  
  13. ini_set('time_limit','0');// Prevent script from timing out.
  14.  
  15. ini_set('memory_limit','16M'); // Provide more memory to the script.
  16.  
  17. $copy_to_server = true; // Should the song be copied server ?
  18.  
  19. $dir = "./files/"; // The directory to which songs will be saved.
  20.  
  21. $processtags = false; // Does the song's tags need to be edited before serving to user ? ( Will work only if file is copied to server. )
  22. // Alter the function process_tags() accordingly.
  23.  
  24. $your_site_name = "(www.djurva.info.ru.com)"; // song name will include your site name.
  25.  
  26. $max_files_to_store = 20;
  27.  
  28. $arrow = "http://s2.postimage.org/2yqnqn010/arrow.png";
  29.  
  30. /* function */
  31.  
  32. function friendly_size($size,$round=2){
  33.     $sizes=array(' Byts',' Kb',' Mb',' Gb',' Tb');
  34.     $total=count($sizes)-1;
  35.     for($i=0;$size>1024 && $i<$total;$i++){
  36.         $size/=1024;
  37.     }
  38.     return round($size,$round).$sizes[$i];
  39. }
  40.  
  41. function delete_files($dir){
  42.     $h = opendir($dir);
  43.     while($f = readdir($h)){
  44.         if(is_file("$dir/$f")){
  45.             unlink("$dir/$f");
  46.         }
  47.     }
  48.     closedir($h);
  49. }
  50.  
  51. function capitalize($var){
  52.     return strtoupper(substr($var,0,1)).strtolower(substr($var,1));
  53. }
  54.  
  55. function extract_movie_names($c,$char){
  56.     $p = "@http://www.songs.pk/indian/(.+?)\.html@is";
  57.     preg_match_all($p,$c,$m);
  58.     $movies = array();
  59.     foreach($m[1] as $mv){
  60.         if(strtolower($char)==strtolower(substr($mv,0,1)))
  61.             $movies[] = $mv;
  62.     }
  63.     sort($movies,SORT_STRING);
  64.     return $movies;
  65. }
  66.  
  67. function extract_songs($c){
  68.     $p = "@<a href=\"(http://link.songs.pk/.+?)\">(.+?)</a>@is";
  69.     preg_match_all($p,$c,$m);
  70.     $songs = array();
  71.     for($i=0;$i<count($m[1]);$i++){
  72.         $songs[$m[1][$i]] = trim(strip_tags($m[2][$i]));
  73.     }
  74.     return $songs;
  75. }
  76.  
  77.  
  78. function extract_song_url($c){
  79.     $h = get_headers($c);
  80.     foreach($h as $v){
  81.         if(substr($v,0,10)=="Location: ")
  82.             return trim(str_replace("Location: ","",$v));
  83.     }
  84. }
  85.  
  86. function adv_get($url){
  87.     return file_get_contents($url);
  88. }
  89.  
  90. function process_tags($mp3_file,$data=""){
  91.     if(!is_file($mp3_file))return false;
  92.     $mp3_tagformat = 'UTF-8';
  93.     include_once('getid3/getid3.php');
  94.     $mp3_handler = new getID3;
  95.     $mp3_handler->setOption(array('encoding'=>$mp3_tagformat));
  96.     include_once('getid3/write.php');
  97.     $mp3_writter = new getid3_writetags;
  98.     $mp3_writter->filename       = $mp3_file;
  99.     $mp3_writter->tagformats     = array('id3v1', 'id3v2.3');
  100.     $mp3_writter->overwrite_tags = true;
  101.     $mp3_writter->tag_encoding   = $mp3_tagformat;
  102.     $mp3_writter->remove_other_tags = false;
  103.     /*
  104.  
  105.     // If you are here, you can uncomment this block to modify tags competely. ( not recommended) //
  106.  
  107.     $mp3_data['title'][]   = $data['mp3_songname'];
  108.     $mp3_data['artist'][]  = $data['mp3_artist'];
  109.     $mp3_data['album'][]   = $data['mp3_album'];
  110.     $mp3_data['year'][]    = $data['mp3_year'];
  111.     $mp3_data['genre'][]   = $data['mp3_genre'];
  112.     $mp3_data['comment'][] = $data['mp3_comment'];
  113.  
  114.         $mp3_data['attached_picture'][0]['data'] = file_get_contents($data['mp3_image']['path']);
  115.         $mp3_data['attached_picture'][0]['picturetypeid'] = $data['mp3_image']['type'];
  116.         $mp3_data['attached_picture'][0]['description'] = $data['mp3_image']['name'];
  117.         $mp3_data['attached_picture'][0]['mime'] = $data['mp3_image']['type'];
  118. */
  119.  
  120. // Comment / Remove the lines  below .
  121.  
  122.         $mp3_data['comment'][] = $data['mp3_comment'];
  123.        
  124.         $mp3_writter->tag_data = $mp3_data;
  125.         $mp3_writter->WriteTags();
  126. }
  127.  
  128. ?>
  129.  
  130. <html>
  131.  
  132. <head>
  133.  
  134. <title>Download all Bollywood songs</title>
  135.  
  136. <style type="text/css">
  137.  
  138. body{background:rgb(185,185,185);}
  139.  
  140. a:link,a:visited,a:hover{font:inherit;color:inherit;text-decoration:none;}
  141.  
  142. a:hover{color:rgb(0,0,150);}
  143.  
  144. .header{padding:5px;margin:5px;font:bold 20px cursive;color:rgb(50,150,250);border:1px dotted rgb(50,50,150);background:rgb(255,255,255);}
  145.  
  146. .list{font:bold 15px cursive;padding:10px;margin:5px;border:1px dotted rgb(50,50,150);background:rgb(255,255,255) left center no-repeat;}
  147.  
  148. div:hover{background-color:rgb(255,255,155);cursor:;}
  149.  
  150. .list *:hover{color:rgb(150,150,250);}
  151.  
  152. img{border:0px;}
  153.  
  154. </style>
  155.  
  156. </head>
  157.  
  158. <body>
  159.  
  160. <?php
  161.  
  162. //$alpha = array("latest","numeric","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  163. $alpha = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  164. if(isset($_GET['song'])){
  165.     $song = base64_decode($_GET['song']);
  166.     $song_url = extract_song_url($song);
  167.     if(filter_var($song_url,FILTER_VALIDATE_URL)){
  168.         if($copy_to_server){
  169.             $song_name = basename($song_url);
  170.             $song_name = str_replace("(www.songs.pk)","$your_site_name",$song_name);
  171.             $song_name = $dir.$song_name;
  172.             $num_files = count(scandir($dir));
  173.             $num_files -= 2;
  174.             if($num_files>$max_files_to_store){
  175.                 delete_files($dir);
  176.             }
  177.             if(!is_file($song_name)){
  178.                 $iscopied = copy($song_url,$song_name);
  179.                 if(iscopied){
  180.                     if($processtags){
  181.                         process_tags($song_name);
  182.                     }
  183.                     echo"<div class='list'><a href='$song_name'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> Click here to download : ".capitalize(basename($song_name))."</div></a> ( ".friendly_size(filesize($song_name)).")</div>";
  184.                 }
  185.                 else{
  186.                     echo"<div class='msg'> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> Try downloading again ...</div>";
  187.                 }
  188.             }
  189.             else{
  190.                 echo"<div class='list'><a href='$song_name'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> Click here to download : ".capitalize(basename($song_name))."</div></a> ( ".friendly_size(filesize($song_name)).")</div>";
  191.             }
  192.         }
  193.         else{
  194.             echo"<div class='list'><a href='$song_url'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> Click here to download : ".capitalize(basename(str_replace("(www.songs.pk)","",$song_url)))."</div></a></div>";
  195.         }
  196.     }
  197.     else{
  198.         echo"<div class='msg'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> Try downloading again ...<div></div>";
  199.     }
  200. }
  201. else{
  202.     if(isset($_GET['movie'])){
  203.         $base = "http://www.songs.pk/indian/";
  204.         $movie = $_GET['movie'];
  205.         $murl = $base.$movie.".html";
  206.         $data = adv_get($murl);
  207.         $songs = extract_songs($data);
  208.         echo"<h3 class='header'>Songs of the movie '".capitalize($movie)."'</h3>";
  209.         foreach($songs as $song => $name){
  210.             echo"<div class='list'><a href='?song=".base64_encode($song)."'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> $name</div></a></div>";
  211.         }
  212.     }
  213.     else{
  214.         if(isset($_GET['char'])){
  215.             $char = strtolower($_GET['char']);
  216.             if(in_array($char,$alpha)){
  217.                 if($char=='latest') $data = adv_get("http://www.songs.pk/");
  218.                 else $data = adv_get("http://www.songs.pk/{$char}_list.html");
  219.                 $movies = extract_movie_names($data,$char);
  220.                 echo"<h3 class='header'>List of movies starting with '".capitalize($char)."'</h3>";
  221.                 foreach($movies as $movie){
  222.                     echo"<div class='list'><a href='?movie=$movie'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> ".capitalize($movie)."</div></a></div>";
  223.                 }
  224.             }
  225.             else{
  226.                 echo"<div class='msg'>The character '$char' is Invalid</div>";
  227.             }
  228.         }
  229.         else{
  230.             echo"<h3 class='header'>Movie name starts with ?</h3>";
  231.             for($i=0;$i<26;$i++){
  232.                 echo"<div class='list'><a href='?char=$alpha[$i]' title='Movie starts with $alpha[$i]' class='button round'><div> <img src='$arrow' alt='&raquo'  title='&raquo' align='middle' /> ".capitalize($alpha[$i])."</div></a> </div>";
  233.             }
  234.         }
  235.     }
  236. }
  237.  
  238. ?>
  239.  
  240. <div class='list'><a href='index.php'><div>Back to homepage</div></a></div>
  241.  
  242. </body>
  243.  
  244. </html>
Add Comment
Please, Sign In to add comment