How to first check in JavaScript if the link of the "video" returned by the JSON of the PHP Code is of HTML "oEmbed" type?

one text

Here is my PHP code from the ajax/setVideoBroken.php file which returns a Json:

if(isset($_POST["src"])) {
    $query = $con->prepare("UPDATE videos SET broken = 1 WHERE videoLink=:src");
    $query->bindValue(":src", $_POST["src"]);
    $query->execute();
    
    $response = ['success' => false];
    $videoQuery = $con->prepare("SELECT * FROM videos WHERE videoLink=:src");
    $videoQuery->bindValue(":src", $_POST["src"]);
    $videoQuery->execute();
    while($row = $videoQuery->fetch(PDO::FETCH_ASSOC)) {
        $response['success'] = true;
        $response = [
            'success' => true,
            'video_link' => $row["videoLink"],
            'thumbnail' => $row["thumbnail"],
            'video_type' => 'video/' . $row["video_extension"],
        ];  
    }
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode($response);
    exit;
} else {
    echo "No src passed to page";
}

Which Json returned in PHP above, is fetched in Ajax (JavaScript) to display the video_link video link in the source tag which itself is included in the video tag:

function loadVideo(src, className) {
    
    var video = $('<video id="player" playsinline controls><source /></video>');

    video.on("load", function() {
        $("." + className + " a").append(video);

        clearTimeout(timer);

        timer = setTimeout(function() {
            $(".imageResults").masonry();
        }, 500);

    });

    video.on("error", function() {
        
        $("." + className).remove();

        $.post("ajax/setVideoBroken.php", {src: src});

    });
    
    $.post("ajax/setVideoBroken.php", {src: src}, function(response) {
        if(response.success) {
            $('video', $video).attr('data-poster', response.thumbnail);
            $('source', $video)
                .attr('src', response.video_link)
                .attr('type', response.video_type);
        }
    });

}

I want to specify that response.video_link can contain simple video URLs (like: https://website.com/video.mp4) or oEmbed HTML code like that of Youtube (like: <iframe src="https://www.youtube.com/embed/4YCLRpKY1cs?feature=oembed"></iframe>)

So, how to check in JavaScript code:

  • If response.video_link (the video_link response of the Json returned by the PHP Code) begins with < which represents the opening sign of the HTML tag ???

  • And if Yes (video_link begins with the < sign, it means that video_link is equivalent to an oEmbed type HTML code like that of Youtube), give the value of this HTML code directly to the var video variable.

  • If not, we must to pass to the variable var video the code <video id="player" playsinline controls><source /></video> so as to add to the tag source, the link of the video what the JSON response contains: video_link.

I really need your help.

Source