<?php

function verificaConteudoMedia($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    
    $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
    curl_close($ch);
    
    if (strpos($contentType, "video/") === 0) {
        return true; // O link aponta para um recurso de vídeo
    } else {
        return false; // O link não é de vídeo
    }
}

$links = [];
$videos = [];

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["links"])) {
    $links = $_POST["links"];
    foreach ($links as $link) {
        if (verificaConteudoMedia($link)) {
            $videos[] = $link;
        }
    }
}

?>

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Detectar Links de Vídeo</title>
</head>
<body>
    <h1>Detectar Links de Vídeo</h1>
    <form method="post">
        <label for="link">Adicione um link:</label><br>
        <input type="text" id="link" name="links[]" placeholder="https://exemplo.com/seu-video.mp4"><br><br>
        <input type="text" id="link" name="links[]" placeholder="https://exemplo.com/seu-outro-video.mp4"><br><br>
        <button type="submit">Verificar</button>
    </form>

    <?php if (!empty($videos)): ?>
        <h2>Links de vídeo encontrados:</h2>
        <ul>
            <?php foreach ($videos as $video): ?>
                <li><?php echo $video; ?></li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
</body>
</html>