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

$link = isset($_GET['link']) ? htmlspecialchars(rawurldecode($_GET['link'])) : '';
$link = str_replace(['xvideos1.com', 'xvideos2.com', 'xvideos3.com', 'xv-horezeedipaif.com', 'xvideos-vn.com'], 'xvideos.com', $link);
$link = str_replace('x*ideos.com', 'xvideos.com', $link);
$link = str_replace('xn**.com', 'xnxx.com', $link);

if ($link && preg_match('#https?://#is',$link) ){
	$html = auto($link);
	
	preg_match('/html5player.setVideoTitle\(\'(.*?)\'\)\;/i', $html, $title);
	$title = $title[1];

	preg_match('/html5player.setVideoUrlLow\(\'(.*?)\'\)\;/i', $html, $sd);
	$sd = $sd[1];

	preg_match('/html5player.setVideoUrlHigh\(\'(.*?)\'\)\;/i', $html, $hd);
	$hd = $hd[1];

	preg_match('/html5player.setVideoHLS\(\'(.*?)\'\)\;/i', $html, $stream);
	$stream = sslfix($stream[1]);

	preg_match('/html5player.setThumbSlide\(\'(.*?)\'\)\;/i', $html, $thumb);
	$thumb = $thumb[1];

	if (!empty($title) && !empty($sd) && !empty($hd) && !empty($stream) && !empty($thumb)) {
		$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 defer>
						$("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: "'.$stream.'", //A link to the HLS manifest
							image: "'.$thumb.'", // 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="'.$sd.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download Video SD</button></a>
						<a rel="noreferrer noopener" target="_blank" href="'.$hd.'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download Video HD</button></a> 
					</div>
				</div>';
	}else{
		$return['error'] = 'Tạm thời máy chủ bận!';
	}
}
else{
	$return['error'] = 'Đường dẫn bạn nhập không hợp lệ!';
}


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




function sslfix($url)
{
	$url = str_replace('http://', 'https://', $url);
	return $url;
}



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_MAXREDIRS, 5);
	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;
}
?>