download

<?php  if ( ! defined('SYS_DIR')) exit('No direct script access allowed');

		class Download extends Controller{				
		function __call($func, $params){
					$spt = "";
					$last = "";
					foreach($params[0] as $row){
							$spt.="$row ";
							$last = $row;
					}
					  $list_arr = array("judul" 					=>"$func",
					  									"r"								=>"",
					  									"song"						=>"",
					  									"m_description"		=>"$func is $spt",
					  									"m_keywords"			=>trim($spt),
					  									'list'=>array());
						if ($last=="")						
							$this->load->view("index",$list_arr);
						else{
							  $this->load->view("index",$list_arr);
								$this->mp3($last);
							}	
		    }	

			
					function adfly($url, $key, $uid, $domain = 'adf.ly', $advert_type = 'int')
					{
					  // base api url
					  $api = 'http://api.adf.ly/api.php?';          					        
					  // api queries
					  $query = array(
					    'key' => $key,
					    'uid' => $uid,
					    'advert_type' => $advert_type,
					    'domain' => $domain,
					    'url' => $url
					  );
					
					  // full api url with query string
					  $api = $api . http_build_query($query);
					  // get data
					  if ($data = file_get_contents($api))
					    return $data;
					}			
			
				function getCount(){
						$this->load->model("product_model");
						$cnt = $this->product_model->fetchPrepare("SELECT COUNT(*) as jml from download",null);
						$i = $cnt->fetchAll();
						echo number_format( $i[0]['jml']);
				}
			
				function index(){
					
					  $list_arr = array("judul" 					=>"Index of Mp3",
					  									"r"								=>"",
					  									"song"						=>"",
					  									"m_description"		=>"Search any mp3, download mp3 and listen mp3",
					  									"m_keywords"			=>"free mp3,youtube to mp3,mp3 songs,mp3 songs,download mp3,youtube mp3,lagu lagu,lirik lagu,lirik,download lagu,lagu mp3,lagu terbaru,lagu hit,gudang lagu,bursa lagu,download lagu terbaru,lagu terbaru 2014",
					  									'list'=>array());

						$this->load->view("index",$list_arr);
						
						
						
						
				}
				
				function mp3($url=NULL,$json=NULL,$cback=NULL){

				// Your api key
				$apiKey = 'XXXX';
				// Your user id
				$uId = 123445;

					if ($url==NULL) 
							header("location:".BASE_URL);
					else
						{
								
								$s = trim(strtolower(str_replace(" ","_",$url)));
								
								if(strtolower(substr($s,strlen($s)-5)) != ".html")
								   $s = $s.".html";
								 
								$s = "http://mp3skull.com/mp3/$s";
								$url = str_ireplace(".html","",$url);
								
								//$s = "http://localhost/skull.html";
								$c = curl_init($s);
								curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false);
								curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false);
								curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
								curl_setopt($c, CURLOPT_HEADER, false);
								curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
								$page = curl_exec($c);
								curl_close($c);
								
								$html = htmlentities("<div style=\"font-size:15px;\">");
								$data = split($html, htmlentities($page));
								$list_mp3 = array();
								$ada = false;
								if (count($data)>0){
									 unset($data[0]);
									 $this->load->model("product_model");
												foreach($data as $nm){
													  $html = htmlentities("</b>");
														$nama = split($html,$nm);
														
														if(count($nama)>0){ 			
															 $html = htmlentities("href=\"htt");				
															 $nama3 = split($html,$nm);
															 if(count($nama3)>1){						
																$nama4 = split("\"",$nama3[1]);
																$nama5 = split("rel=",$nama4[0]);								
																$link = "htt".substr($nama5[0],0,strlen($nama5[0])-7);
																$title = substr($nama[0],9);
																
																if ($json==NULL){
																$ar = split("_",$url);
																foreach ($ar as $r){																	  
																		$title = str_ireplace($r,"<b>$r</b>",$title);
																}
															}
																
																$xurl = $link;
																$ada = true;
																
																
															  
															  $data = array(
															  								't' => $title,
															  								'u' => $xurl
															  						);																
																$this->product_model->save($data);

																
																if ($json==NULL)
																		$adfl =  $xurl;
																else		
														$adfl =  $xurl;//$adfl =  $this->adfly($xurl, $apiKey, $uId);
																
																
																$list_mp3[] = array("title"=>$title,
																										"url"=>$adfl);
																
																		
																
														}
								
														
													}
														
												}
												
									  }			
									  
									  $url = str_replace("_"," ",$url); 
									  if (count($list_mp3)==0)
									      $ket = "No Result.";
									  else    
									      $ket = "Download <b>".ucwords($url)."</b> mp3.";
									      
									      
									      
									  $list_arr = array("judul" 					=>"Index of $url",
									  									"r"								=>$ket,
									  									"song"						=>ucwords($url),
									  									"m_description"		=>"Download $url, try listen to $url mp3",
									  									"m_keywords"			=>"$url mp3, download $url mp3",
									  									'list'=>$list_mp3);
									  if ($json!=NULL){
									  			if ($json=="json"){
									  				  if ($cback!=NULL){
																			header('Content-type: application/json; charset=utf-8');
																			header("access-control-allow-origin: *");
									  								echo $cback."(".json_encode($list_mp3).")";
									  						}
									  					else{
																			header('Content-type: application/json; charset=utf-8');
																			header("access-control-allow-origin: *");
									  					    echo json_encode($list_mp3);
									  					  }
									  				}
									  			else
									  					echo "no data";
									  	}
									  else
									  		$this->load->view("index",$list_arr);
						}			
				}
				
				
				public function searching(){	
								if (!isset($_POST['search']) || empty($_POST['search']))
								   header("location:/");
								else{   
									 $s = trim(str_replace(" ","_",trim($_POST['search'])));
									 header("location:/download/mp3/$s.html");							
								}
					}
				
								
				

function getRandomUserAgent(){
    $userAgents=array(
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
        "Opera/9.20 (Windows NT 6.0; U; en)",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50",
        "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]",
        "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9",
        "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48"       
    );
    $random = rand(0,count($userAgents)-1);
 
    return $userAgents[$random];
}


function downloadMp3($id){
				$c = curl_init("http://youtubeinmp3.com/fetch/?api=advanced&format=JSON&video=http://www.youtube.com/watch?v=$id");
				curl_setopt($c, CURLOPT_HEADER, false);
				curl_setopt($c,CURLOPT_USERAGENT,$this->getRandomUserAgent());
				curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    				
				$page = curl_exec($c);
 				 				
				curl_close($c);
				
				$xmp3 = json_decode($page);

				$fakeFileName= $xmp3[0]->title.".mp3";
				$realFileName = $xmp3[0]->link;
				
				$file = $realFileName;
				$fp = fopen($file, 'rb');
				
				header("Content-Type: application/octet-stream");
				header("Content-Disposition: attachment; filename=$fakeFileName");
				header("Content-Length: " . filesize($file));
				fpassthru($fp);				

		
}

function video($ds){

$dc = str_replace(" ","+",$ds);
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos?q=$dc&alt=json");

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c,CURLOPT_USERAGENT,$this->getRandomUserAgent());
$data = curl_exec($c);
curl_close($c);

	

	$arrc = json_decode($data);
	$arr = $arrc->feed->entry;

	$cnt = 0;	
	$outp = array();
	
	for($i=0;$i<count($arr);$i++){
	  $index = 0;	 
	  $title 	= '';
	  $url 		= '';
	  $isi		= '';
	  $image	= '';
	  $num		= 0;
		foreach($arr[$i]->title as $dat	){
			  	

			  if ($index==0){

						$url_component = parse_url($arr[$i]->link[0]->href);
						
						parse_str($url_component['query'], $output);						
			
				$c = curl_init();
				curl_setopt($c, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos/".$output['v']."?v=2&alt=jsonc");
				curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($c,CURLOPT_USERAGENT,$this->getRandomUserAgent());
				$json = json_decode(curl_exec($c));
				curl_close($c);
	
    			 $image = $json->data->thumbnail->sqDefault; 	
			  	$cnt++;
	
					$title = $dat;
					$linkId = $output['v'];
				}
				$index++;				

					
				}
				
		$index = 0;	 		
		foreach($arr[$i]->content as $dat	){
				
			  if ($index==0){
					//echo $dat."<br/>";
					$isi = $dat;
					
				}
				$index++;				
				}
				
		$index = 0;	 		
		foreach($arr[$i]->{'yt$statistics'} as $dat	){
			  if ($index==1){
					//echo number_format( $dat,0)."<br/>";
					$num = $dat;
					
				}
				$index++;				
				}
				
				
				$outp[] = array("title"		=>$title,
												"image"		=>$image,
												"linkId"	=>$linkId,
												"content"	=>$isi,
												"view"		=>$num,
												);

				
		}
	
	
	function array_sort_by_column(&$arr, $col, $dir = SORT_ASC) {
    $sort_col = array();
    foreach ($arr as $key=> $row) {
        $sort_col[$key] = $row[$col];
    }

    array_multisort($sort_col, $dir, $arr);
}


array_sort_by_column($outp, 'view',SORT_DESC);
		$ims = array();
    foreach ($outp as $row) {
    		$ims[]= "<div class='img'>
  							<a href='downloadMp3/".$row['linkId']."'>
  								<img src='".$row['image']."' alt='".$row['content']."' width='110' height='90'/>
  							</a>
  						<div class='desc'>".$row['title']."</div>
							</div>";							    							        
    }
header('Content-type: application/json; charset=utf-8');
																			header("access-control-allow-origin: *");
    echo json_encode($ims);

		}
	}
?>

0 comments:

Post a Comment

 

Copyright 2013 Download Lagu Gratis: download Template by Casino Critic | Ping!. Powered by Blogger