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

$proxy = '';
$imageproxy = 'https://try.imgeng.in/w_300/f_webp/';
if(!empty($_POST['link'])){
	$link = isset($_POST['link']) ? htmlspecialchars(rawurldecode($_POST['link'])) : '';

	if ($link && preg_match('#https?://#is',$link)){
		if (preg_match('#/audio/#is',$link)) {
			$url = 'http://vip.service.keeng.vn:8080/KeengWSRestful///ws/common/getSong?identify='.getid($link).'&id_has_played=';
			$source = json_decode(auto($url),true);
			$name = $source['data']['name'];
			$singer = $source['data']['singer'];
			$image   = isset($source['data']['image_face'])?$source['data']['image_face']:$source['data']['image_path'];
			if (empty($image)) {
				$image   = isset($source['data']['image_path_cover'])?$source['data']['image_path_cover']:$source['data']['image310'];
			}
			$play = $source['data']['media_url_mono'];
			///Download
			$download = $source['data']['download_url_web'];
			if ($source['data']['is_lossless']) {
				$lossless = $source['data']['download_url_lossless'];
			}
			
			if($name && $singer && $image && $play){
				$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="'.$singer.'" data-title="'.$name.'" data-album="" data-info="" data-image="'.$imageproxy.$image.'" data-duration="0">
							<div class="amazingaudioplayer-source" data-src="'.changessl($play).'" data-type="audio/mpeg" />
						</li>
					</ul>
				</div>
			</div>
			<div style="text-align: center;">
				<a rel="noreferrer noopener" target="_blank" href="'.$download.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download 320Kbps</button></a>
				'.(empty($lossless)?'':'<a target="_banks" href="'.$lossless.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download Lossess</button></a>').'
			</div>
		</div>

	<script src="/template/audioplayerengine/amazingaudioplayer.js"></script>
	<script src="/template/audioplayerengine/initaudioplayer-1.js"></script>';
			} else { $return['error'] = 'Có lỗi xảy ra, vui lòng thử lại sau!'; }
		}

		//album
		elseif (preg_match('#/album/#is',$link)) {
			$url = 'http://vip.service.keeng.vn:8080/KeengWSRestful///ws/common/getAlbumInfo?identify='.getid($link);
			$source = json_decode(auto($url),true);
			$albumname = $source['data']['name'];
			$list_item = $source['data']['list_item'];
			if($albumname && $list_item){
				$data = [];
				foreach ($list_item as $key => $item) {
					$data[$key]['name']     = $item['name'];
					$data[$key]['singer']   = $item['singer'];
					$data[$key]['linkplay']   = $item['media_url_mono'];
					$data[$key]['image']   = isset($item['image_face'])?$item['image_face']:$item['image_path'];
					if (empty($data[$key]['image'])) {
						$data[$key]['image']   = isset($item['image_path_cover'])?$item['image_path_cover']:$item['image310'];
					}
					$data[$key]['download']['320']      = $item['download_url_web'];
					if ($item['is_lossless']) {
						$data[$key]['download']['lossless'] = $item['download_url_lossless'];
					}
				}
				//TaoPlaylist
				$player = ''; $download='';
				$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="'.$imageproxy.$value['image'].'" data-duration="0">
							<div class="amazingaudioplayer-source" data-src="'.changessl($value['linkplay']).'" data-type="audio/mpeg" />';
					$download.= '
			  <tr>
				<td>'.$key.'. <b>'.$value['name'].'</b> - '.$value['singer'].'</td>
				<td style="text-align:center">'.(isset($value['linkplay'])? '<a class="128" rel="noreferrer noopener" target="_blank" href="'.$value['linkplay'].'" 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!'; }
		}

		////Video

		elseif (preg_match('#/video/#is',$link)) {
			$url = 'http://vip.service.keeng.vn:8080/KeengWSRestful///ws/common/getVideo?identify='.getid($link).'&id_has_played=';
			$source = json_decode(auto($url),true);
			$name = $source['data']['name'];
			$singer = $source['data']['singer'];
			$image   = isset($source['data']['image_face'])?$source['data']['image_face']:$source['data']['image_path'];
			if (empty($image)) {
				$image   = isset($source['data']['image_path_cover'])?$source['data']['image_path_cover']:$source['data']['image310'];
			}
			$play = $source['data']['download_url'];
			///Download
			$download = $source['data']['download_url_web'];
			
			if($name && $singer && $image && $play){
				$return['success'] = '
		<div class="menu">
			<div style="padding-bottom:15px;font-size: 16px;text-align:center;" ><b>'.$name.'</b> - '.$singer.'</div>
			<div class="embed-responsive embed-responsive-16by9" style="text-align:center;"><div class="embed-responsive-item" id="player"></div></div>
			<script>
				$("head").append(\'<meta name="referrer" content="no-referrer" />\');
				var playerInstance = jwplayer("player");
				jwDefaults.key = "9dOyFG96QFb9AWbR+FhhislXHfV1gIhrkaxLYfLydfiYyC0s";
				playerInstance.setup({
					id: "player",
					title: "'.$name.'",
					controls: true,
					playbackRateControls: true,
					abouttext: "VuiZ.Net",
					aboutlink: "https://m.vuiz.net/",
					logo: {
					    file: "https://m.vuiz.net/template/images/logovideoplayer.png",
					    logoBar: "https://m.vuiz.net/template/images/logovideoplayer.png",
					    link: "https://m.vuiz.net/",
					    position: "control-bar"
					},
					file: "'.changessl($play).'", //A link to the HLS manifest
					image: "'.$imageproxy.$image.'", // Poster image that will show up before the stream begins
				});
				playerInstance.on("error",function() {
					playerInstance.load("https://cdn.jwplayer.com/v2/media/7RtXk3vl");
					playerInstance.setControls(false);
					playerInstance.play();
				});
			</script>
	    	<div style="padding-top:15px; text-align: center;">
				<a rel="noreferrer noopener" target="_blank" href="'.$download.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download Video</button></a>
			</div>
		</div>';
			} else { $return['error'] = 'Có lỗi xảy ra, vui lòng thử lại sau!'; }
		}

		//phim.keeng.vn
		elseif (preg_match('#phim.keeng.vn#is',$link)) {
			$source = auto($link);
			//tieu de
			preg_match('/property="og:title" content="(.*?)"/i', $source, $title);
			$title = trim($title[1]);

			//poster
			preg_match('/property="og:image" content="(.*?)"/i', $source, $thumb);
			$thumb = trim($thumb[1]);

			//stream
			preg_match('/videojs\("content_video"\).src\(\'(.*?)\'/i', $source, $streamlink);
			$streamlink = trim($streamlink[1]);
			$streamlink = changessl($streamlink);
			//download
			preg_match('/var mp4 = \'(.*?)\'/i', $source, $download);
			$download = trim($download[1]);

			if($title && $thumb && $streamlink && $download){
				$return['success'] = '
		<div class="menu">
			<div style="padding-bottom:15px;font-size: 16px;text-align:center;" ><b>'.$title.'</b></div>
			<div class="embed-responsive embed-responsive-16by9" style="text-align:center;"><div class="embed-responsive-item" id="player"></div></div>
			<script>
				$("head").append(\'<meta name="referrer" content="no-referrer" />\');
				var playerInstance = jwplayer("player");
				jwDefaults.key = "9dOyFG96QFb9AWbR+FhhislXHfV1gIhrkaxLYfLydfiYyC0s";
				playerInstance.setup({
					id: "player",
					title: "'.$title.'",
					controls: true,
					playbackRateControls: true,
					abouttext: "VuiZ.Net",
					aboutlink: "https://m.vuiz.net/",
					logo: {
					    file: "https://m.vuiz.net/template/images/logovideoplayer.png",
					    logoBar: "https://m.vuiz.net/template/images/logovideoplayer.png",
					    link: "https://m.vuiz.net/",
					    position: "control-bar"
					},
					file: "'.$streamlink.'", //A link to the HLS manifest
					image: "'.$imageproxy.$thumb.'", // Poster image that will show up before the stream begins
				});
				playerInstance.on("error",function() {
					playerInstance.load({file: "'.str_replace("http://", "https://", $download).'"});
				});
				playerInstance.on("error",function() {
					playerInstance.load("https://cdn.jwplayer.com/v2/media/7RtXk3vl");
					playerInstance.setControls(false);
					playerInstance.play();
				});
			</script>
	    	<div style="padding-top:15px; text-align: center;">
				<a rel="noreferrer noopener" target="_blank" href="'.$download.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download Video</button></a>
			</div>
		</div>';
			} else { $return['error'] = 'Có lỗi xảy ra, vui lòng thử lại sau!'; }
		}
		else {
			$return['error'] = 'Chưa hỗ trợ định dạng này!';
		}

	} else {
		$return['error'] = 'Link bạn nhập không hợp lệ!';
	}


} elseif (isset($_GET['page'])) {
	$page = isset($_GET['page']) ? htmlspecialchars(rawurldecode($_GET['page'])) : 1;
	$url = 'http://vip.service.keeng.vn:8080/KeengWSRestful///ws/common/getListSongHot?page='.$page.'&num=40';

	$source = json_decode(auto($url),true);
	$return = $source['data'];
}


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








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;
}
function getid($url)
{
	$url = str_replace('http://', '', $url);
	$url = str_replace('https://', '', $url);
	$temp = explode("/",$url);
	$id = trim($temp[3]);
	$id = str_replace('.html', '', $id);
	if (preg_match('#\?#is',$id)) {
		$ids = $id;
		$ids = explode("?",$ids);
		$ids = trim($ids[0]);
		$id = empty($ids)?$id:$ids;
	}
	return $id;
}

function changessl($link)
{
    $link = str_replace('http://', 'https://', $link);
    return $link;
}
?>