<?php
/**
 * Project:        M.VuiZ.Net
 * Author:         nampt.me <admin@vuiz.net>
 * Copyright:      © 2025 vuiz.net All rights reserved.
 */
	$key = 'Tool Get Link Download Youtube';
	$mkey = 'Tìm nhạc và lấy link tải mp3 , Tải youtube miễn phí cho mobile, Lấy link , download youtube không cần tool.';
	include '../../template/header.php';
?>

	<div class="col-right-xs">
		<div class="mainblok">
			<div class="phdr">
					<div vocab="https://schema.org/" typeof="BreadcrumbList">
						<span property="itemListElement" typeof="ListItem">
							<a href="/"  property="item" typeof="WebPage">
								<i class="fa fa-home"></i> <span property="name">Home</span>
							</a>
							<meta property="position" content="1">
						</span>
						<i class="fa fa-angle-right"></i>
						<span property="itemListElement" typeof="ListItem">
							<a href="/getlink/"  property="item" typeof="WebPage">
								<i class="fa fa-chain-broken"></i> <span property="name">GetLink</span>
							</a>
							<meta property="position" content="2">
						</span>
						<i class="fa fa-angle-right"></i>
						<span property="itemListElement" typeof="ListItem">
							<span property="name">Tool Get Link Download Youtube</span>
							<meta property="position" content="3">
						</span>
					</div>
			</div>
			<div class="newsx">Tải video từ Youtube - Nhanh, miễn phí và đơn giản chuyển đổi video Youtube sang MP3, MP4 cùng nhiều định dạng khác nhau.</div>
			<div class="menu">
				<strong>Link hỗ trợ: </strong>youtube.com/watch?v=...<br/>
				youtu.be/...<br/>
				youtube.com/embed/...<br/>
				youtube-nocookie.com/embed/...<br/>
				youtube.com/watch?feature=player_embedded&v=...<br />
				<form role="form" class="form-horizontal" id="form" method="post" onSubmit="return false;">
					<input type="text" name="link" id="link" placeholder="YouTube">
					<input type="submit" id="submit" value="Lấy link get" name="submit" />
				</form>
			</div>
			<div id="DownloadLink"></div>
		</div>
		
<?php require '../list.php'; ?>
	</div>
	<div class="col-left-xs">
<?php require '../../tools/toolslist.php'; ?>
	</div>
	<div class="clear"></div>
<script>
$(document).ready(function(){
	$("#submit").click(function(){
		$("#submit").addClass('disabled');
		$("#DownloadLink").hide().html('<div class="gmenu" style="text-align: center;"><img src="/template/images/loading.svg" /></div>').slideDown('slow');
		var form = $('#form')[0];
		var formData = new FormData(form);
		$.ajax({
			url: "api.php",
			type: "POST",
			data:  formData,
			contentType: false,
			cache: false,
			processData:false,
			success: function(res)
			{
				if(res.success){
					var data = res.success;
					$("#submit").removeClass('disabled');
					var html = '<div class="menu" style="text-align:center;"><div style="padding-bottom:15px;font-size: 16px; font-weight: bold;">'+data.info.title+' - '+data.info.channelTitle+'</div><div id="player" style="padding-bottom:15px;"><img src="'+data.info.thumbnail+'" width="600px" title="'+data.info.title+'" /></div> <div><button id="PlayVideoButton"><i class="fa fa-youtube-play"></i> Play Video</button> <button id="PlayAudioButton"><i class="fa fa-music"></i> Play Audio</button></div>';

					if(data.downloads.video) {
						html += '<p style="font-weight: bold;">Video With Audio</p>';
						$.each(data.downloads.video, function(index, video) {
							html += '<a rel="noreferrer noopener" target="_blank" href="'+video.url+'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download '+video.qualityLabel+'</button></a> <br />';
						});

						$("#PlayVideoButton").click(function () {
							playvideo(data.info.title, data.info.thumbnail, data.downloads.video[0].url);
						});
					}
					if(data.downloads.videoNoAudio) {
						html += '<p style="font-weight: bold;">Video No Audio</p>';
						$.each(data.downloads.videoNoAudio, function(index, video) {
								html += '<a rel="noreferrer noopener" target="_blank" href="'+video.url+'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download '+video.qualityLabel+'</button></a> <br />';
						});
					}
					if(data.downloads.audio) {
						html += '<p style="font-weight: bold;">Audio Only</p>';
						$.each(data.downloads.audio, function(index, audio) {
							html += '<a rel="noreferrer noopener" target="_blank" href="'+audio.url+'"><button type="button" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download m4a</button></a> <br />';
						});
						$("#PlayAudioButton").click(function () {
							playaudio(data.info.title, data.info.thumbnail, data.downloads.audio[0].url);
						});
					}
					html += '</div>';

					$("#DownloadLink").hide().html(html).slideDown('slow');
					$("head").append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.8/plyr.min.css" /><script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.8/plyr.min.js" type="text/javascript"><\/script>');

					if(data.downloads.video) {
						$("#PlayVideoButton").click(function () {
							playvideo(data.info.title, data.info.thumbnail, data.downloads.video);
						});
					}
					if(data.downloads.audio) {
						$("#PlayAudioButton").click(function () {
							playaudio(data.info.title, data.info.thumbnail, data.downloads.audio[0].url);
						});
					}
				}
				if(res.error){
					$("#submit").removeClass('disabled');
					$("#DownloadLink").hide().html('<div class="gmenu" style="text-align: center;"><i style="color:red">'+res.error+'</i></div>').slideDown('slow');
				}
			},
			error: function() 
			{
				$("#DownloadLink").hide().html('<div class="gmenu" style="text-align: center;"><i style="color:red">Có lỗi hệ thống, vui lòng kiểm tra lại!</i></div>').slideDown('slow');
			}
		});
		$("#link").attr("placeholder", $("#link").val()).val("");
	});
});

function playvideo(title, image, videos) {
	var playsource = videos.map(function (video) {
		return {
			src: video.url,
			type: 'video/mp4',
			size: video.height
		}
	});
	$("#player").hide().html('<video id="videoplayer" playsinline controls></video>');
	const player = new Plyr('#videoplayer');
	player.source = {
		type: 'video',
		title: title,
		poster: image,
		sources: playsource
	};
	$("button.plyr__control--overlaid").css({"height":"auto", "margin":"none"});
	$("#player").slideDown('slow');
}

function playaudio(title, image, audio) {
	$("#player").hide().html('<div style="max-width:600px;margin:0 auto;"><img src="'+image+'" width="600px" title="'+title+'" /><audio id="videoplayer" controls"></audio></div>');
	const player = new Plyr('#videoplayer');
	player.source = {
		type: 'audio',
		title: title,
		poster: image,
		sources: [{
			src: audio,
			type: 'audio/mp4'
		}]
	};
	player.play();
	$("#player").slideDown('slow');
}
</script>

<?php
	require '../../template/footer.php';
?>
