<?php
	// Return source code
	if(isset($_GET['source'])) {
		header("Content-Type: text/plain");
		die(file_get_contents(basename($_SERVER['PHP_SELF'])));
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<title>Discord video embedder</title>
	<link rel="canonical" href="https://home.pk11.us/video.php">
	<meta property="og:url" content="https://home.pk11.us/video.php">
	<meta property="title" content="Discord video embedder">
	
	<?php $video = htmlspecialchars(str_replace(' ', '%20', $_GET['video'])); ?>

	<?php if($video) { ?>
		<meta property="og:video" content="<?php echo $video ?>">
		<meta property="og:video:secure_url" content="<?php echo $video ?>">
		<meta property="og:video:width" content="0">
		<meta property="og:video:height" content="0">
		<meta property="og:video:type" content="video/mp4">
		<meta property="og:type" content="video.other">
		<meta name="twitter:player" content="<?php echo $video ?>">
		<meta name="twitter:player:width" content="0">
		<meta name="twitter:player:height" content="0">
		<meta name="twitter:player:stream" content="<?php echo $video ?>">
		<meta name="twitter:player:stream:content_type" content="video/mp4">

		<style>
			*, body, html, video, source {
				margin: 0;
				padding: 0;
			}

			video {
				width: 100%;
				height: auto;
			}
		</style>
	<?php } else { ?>
		<meta name="description" content="Put ?video=[link to video] at the end of the URL and Discord will show an embed of that video.">
	<?php } ?>

</head>
<body>
	<?php if($video) { ?>
		<video controls autoplay>
			<source src="<?php echo $video; ?>" type="video/mp4">
		</video>
	<?php } else { ?>
		<p>Put ?video=[link to video] at the end of the URL and Discord will show an embed of that video.</p>
	<?php } ?>
</body>
</html>
