<?php
/**
 * Project:        M.VuiZ.Net
 * Author:         nampt.me <admin@vuiz.net>
 * Copyright:      © 2025 vuiz.net All rights reserved.
 */
error_reporting(0);
$return = array();

if($_POST){
	$link = isset($_POST['link']) ? htmlspecialchars(rawurldecode($_POST['link'])) : '';

	if ($link && preg_match('#https?://#is',$link)){

		if (preg_match('#/bai-hat/#is',$link)){
			$send = '{"table":"customers","limit":1,"limit2":"links='.$link.'"}';
			$send = getcontent('https://sv007.getlinkaz.com/GET-x-2020/', 'x='.$send);
			$data = json_decode(remove_utf8_bom($send), true);

			if(isset($data[0]['name']) && preg_match('#btn-download#is',$data[0]['name'])){
				$return['success'] = '<div class="menu" style="text-align: center">'.$data[0]['name'].'</div>';
			} else {
				$data = json_decode(auto('https://zing-mp3.glitch.me/?url='.$link),true);
				$source = auto($link);
				preg_match('/og\:image\" content\=\"(.+)\"/', $source, $thumb);
				$thumb = trim($thumb[1]);
				if($data['download_status'] && $data['source']['audio']){
					$i=0;
					$download= '';
					foreach ($data['source']['audio'] as $cl => $url){
						$download .= '<a rel="noreferrer noopener" target="_blank" href="'.$url['download'].'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download '.$cl.'Kbps</button></a> ';
						$play = $url['download'];
						$i++;
					}
								$return['success'] = '
						<link rel="stylesheet" type="text/css" href="/template/audioplayerengine/initaudioplayer-1.css">
						<div class="menu">
							<div style="margin:12px auto;">
								<div id="amazingaudioplayer-1" style="display:block;position:relative;width:100%;max-width:300px;height:300px;margin:0px auto 0px;">
									<ul class="amazingaudioplayer-audios" style="display:none;">
										<li data-artist="'.$data['artist'].'" data-title="'.$data['title'].'" data-album="" data-info="" data-image="'.$thumb.'" data-duration="0">
											<div class="amazingaudioplayer-source" data-src="'.$play.'" data-type="audio/mpeg" />
										</li>
									</ul>
								</div>
							</div>
							<div style="text-align: center;">
								'.$download.'
							</div>
						</div>

					<script src="/template/audioplayerengine/amazingaudioplayer.js"></script>
					<script src="/template/audioplayerengine/initaudioplayer-1.js"></script>';
				}

			} //else { $return['error'] = $data['msg']; }
		}
		elseif (preg_match('#/video-clip/#is',$link)){
			$data = json_decode(auto('https://zing-mp3.glitch.me/?url='.$link),true);
			$source = auto($link);
			preg_match('/og\:image\" content\=\"(.+)\"/', $source, $thumb);
			$thumb = trim($thumb[1]);
			if($data['download_status'] && $data['source']['video']){
				$i=0;
				$download= '';
				foreach ($data['source']['video'] as $cl => $url){
					
					$download .= '<a rel="noreferrer noopener" target="_blank" href="'.$url['download'].'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download '.$cl.'p</button></a> ';
					$play[$i]['file'] = $url['view'];
					$play[$i]['type'] = 'mp4';
					$play[$i]['label'] = $cl.'p';
					if($cl=='1080')
						$play[$i]['default'] =true;
					$i++;
				}
				$return['success'] =  '
		<div class="menu">
			<div style="padding-bottom:15px;font-size: 16px;text-align:center;" ><b>'.$data['title'].'</b> - '.$data['artist'].'</div>
			<div id="video"><div id="myvideo"></div></div>
	<script>
			$("head").append(\'<meta name="referrer" content="no-referrer" />\');
			var playerInstance = jwplayer("myvideo");
			playerInstance.setup({
				sources: '.json_encode($play).',
				title: "'.$data['title'].'",
				image: "'.$thumb.'",
			});
	</script>
	    	<div style="text-align: center; padding-top:15px;">
				'.$download.'
			</div>
		</div>';
			} else {
				$return['error'] = 'Link bạn nhập không hợp lệ hoặc không được hỗ trợ!';
			}
		}

		//album
		elseif (preg_match('#/album/#is',$link)) {
			$source = json_decode(auto('https://zing-mp3.glitch.me/?url='.$link),true);
			$albumname = $source['data']['info']['title'];
			$list_item = $source['data']['items'];
			$image = isset($source['data']['info']['thumbnail_medium'])?$source['data']['info']['thumbnail_medium']:$source['data']['info']['thumbnail'];
			if($albumname && $list_item){
				$data = [];
				foreach ($list_item as $key => $item) {
					$data[$key]['name']     = $item['title'];
					$data[$key]['singer']   = $item['artist'];
					$data[$key]['linkplay']   = $item['source']['audio']['128']['view'];
					$data[$key]['download']['128']      = $item['source']['audio']['128']['download'];
					if ($item['source']['audio']['320']) {
						$data[$key]['download']['320'] = $item['source']['audio']['320']['download'];
					}
				}
				$player = ''; $download='';
				//TaoPlaylist
				$player.= '
		<link rel="stylesheet" type="text/css" href="/template/audioplayerengine/initaudioplayer-1.css">
		<div class="menu" id="playlist">
			<div style="margin:12px auto;">
				<div id="amazingaudioplayer-1" style="display:block;position:relative;width:100%;max-width:300px;height:300px;margin:0px auto 0px;">
					<ul class="amazingaudioplayer-audios" style="display:none;">';
				$download.= '
		<table class="table table-striped">
			<thead>
			  <tr>
				<th style="width:45%">Bài hát</th>
				<th style="width:15%;text-align:center" id="128"><label>128 Kbps <input type="checkbox" checked=""></label></th>
				<th style="width:15%;text-align:center" id="320"><label>320 Kbps <input type="checkbox" checked=""></label></th>
				<th style="width:15%;text-align:center" id="lossless"><label>Lossless <input type="checkbox" checked=""></label></th>
			  </tr>
			</thead>
			
			<script>
				$("#128").click(function(event) {
					if (event.target.nodeName == "LABEL") return;
					$(".128").fadeToggle();
					if($(".128").attr("href")) {
						$(".128").each(function() {
							var $t = $(this);
							$t.attr({href2 : $t.attr("href"),}).removeAttr("href");
						});
					} else  {
						$(".128").each(function() {
							var $t = $(this);
							$t.attr({href : $t.attr("href2"),}).removeAttr("href2");
						});
					}
				}); 
				$("#320").click(function(event) {
					if (event.target.nodeName == "LABEL") return;
					$(".320").fadeToggle();
					if($(".320").attr("href")) {
						$(".320").each(function() {
							var $t = $(this);
							$t.attr({href2 : $t.attr("href"),}).removeAttr("href");
						});
					} else  {
						$(".320").each(function() {
							var $t = $(this);
							$t.attr({href : $t.attr("href2"),}).removeAttr("href2");
						});
					}
				}); 
				$("#lossless").click(function(event) {
					if (event.target.nodeName == "LABEL") return;
					$(".lossless").fadeToggle();
					if($(".lossless").attr("href")) {
						$(".lossless").each(function() {
							var $t = $(this);
							$t.attr({href2 : $t.attr("href"),}).removeAttr("href");
						});
					} else  {
						$(".lossless").each(function() {
							var $t = $(this);
							$t.attr({href : $t.attr("href2"),}).removeAttr("href2");
						});
					}
				}); 
			</script>
			
			<tbody>';
				foreach($data as $key => $value) {
					$player.= '
						<li data-artist="'.$value['singer'].'" data-title="'.$value['name'].'" data-album="'.$albumname.'" data-info="" data-image="'.$image.'" data-duration="0">
							<div class="amazingaudioplayer-source" data-src="'.$value['linkplay'].'" data-type="audio/mpeg" />';
					$download.= '
			  <tr>
				<td>'.$key.'. <b>'.$value['name'].'</b> - '.$value['singer'].'</td>
				<td style="text-align:center">'.(isset($value['download']['128'])? '<a class="128" rel="noreferrer nofollow" target="_blank" href="'.$value['download']['128'].'" download="true"><i class="fa fa-download"></i>  Tải nhạc</a>':'Không có').'</td>
				<td style="text-align:center">'.(isset($value['download']['320'])? '<a class="320" rel="noreferrer nofollow" target="_blank" href="'.$value['download']['320'].'" download="true"><i class="fa fa-download"></i>  Tải nhạc</a>':'Không có').'</td>
				<td style="text-align:center">'.(isset($value['download']['lossless'])? '<a class="lossless" rel="noreferrer nofollow" target="_blank" href="'.$value['download']['lossless'].'" download="true"><i class="fa fa-download"></i>  Tải nhạc</a>':'Không có').'</td>
			  </tr>';
				}

				$download.= '
			</tbody>
		</table>';

				$player.= '
					</ul>
				</div>
			</div>
			'.$download.'
		</div>
	<style type="text/css">
	        #playlist table{
	            border-collapse:collapse;
	            width:100%;
	        }
	        #playlist th, #playlist td{
	            text-align:left;
	            padding:10px;
	        }
	        #playlist table tr:nth-child(odd){
	            background-color:#eee;
	        }
	        #playlist table tr:nth-child(even){
	            background-color:white;
	        }
	        #playlist thead tr:nth-child(1){
	            background-color:skyblue;
	        }
	</style>
	<script src="/template/audioplayerengine/amazingaudioplayer.js"></script>
	<script src="/template/audioplayerengine/initaudioplayer-1.js"></script>';
				$return['success'] =  $player;
			} else { $return['error'] = 'Có lỗi xảy ra khi get album, vui lòng thử lại sau!'; }
		} else { $return['error'] = 'Định dạng url không hợp lệ!'; }
	} else { $return['error'] = 'Link bạn nhập không hợp lệ hoặc không được hỗ trợ!'; }

} elseif ($_GET) 
{
	$url = 'https://m.zingmp3.vn/xhr/chart-realtime?chart=song&count=40';
	$source = json_decode(auto($url),true);
	$return = $source['data']['song'];
}

echo json_encode($return, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);


function remove_utf8_bom($text)
{
	$text = str_replace('
', '', trim($text));
	$text = str_replace('https://liclink.com/st?api=d2cdd57f7488db54a9d543da3f655e123a270213&url=', 'https://', trim($text));
	$bom = pack('H*','EFBBBF');
	$text = preg_replace("/^$bom/", '', $text);
	return $text;
}


function getcontent($url,$post) {
	$ch = @curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	$head[] = "Connection: keep-alive";
	$head[] = "Keep-Alive: 300";
	$head[] = "Accept-Language: en-us,en;q=0.5";
	$head[] = "Host: sv007.getlinkaz.com";
	$head[] = "Origin: https://www.getlinkaz.com";
	$head[] = "Referer: https://www.getlinkaz.com/?link=null";
	$head[] = "content-type: application/x-www-form-urlencoded; charset=UTF-8";
	$head[] = "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
	curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	$nd = curl_exec($ch);
	curl_close($ch);
	return $nd;
}


function auto($dkm) {
	$ch = @curl_init();
	curl_setopt($ch, CURLOPT_URL, $dkm);
	$head[] = "Connection: keep-alive";
	$head[] = "Keep-Alive: 300";
	$head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
	$head[] = "Accept-Language: en-us,en;q=0.5";
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/45.0 Chrome/39.0.2171.95 Safari/537.36');
	curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	
	$nd = curl_exec($ch);
	curl_close($ch);
	return $nd;
}

?>