<?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
    }
}

$mensagem = "";

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["links"])) {
    $links = explode("\n", $_POST["links"]);
    $videos = [];
    foreach ($links as $link) {
        if (verificaConteudoMedia(trim($link))) {
            $videos[] = $link;
        }
    }

    if (!empty($videos)) {
        $mensagem = "Os seguintes links têm vídeo online:<br>";
        foreach ($videos as $video) {
            $mensagem .= $video . "<br>";
        }
    } else {
        $mensagem = "Nenhum dos links fornecidos tem vídeo online.";
    }
}

?>

<!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="links">Adicione os links (um por linha):</label><br>
        <textarea id="links" name="links" rows="5" cols="50"></textarea><br><br>
        <button type="submit">Verificar</button>
    </form>

    <?php if (!empty($mensagem)): ?>
        <div><?php echo $mensagem; ?></div>
    <?php endif; ?>
</body>
</html>