Sejoo
Sejoo

Reputation: 63

PHP how to check if openload video exist?

I need something to check if openload video exist, some videos sometimes get removed by DMCA report and i just need to display myself not working links.

Just a sketch what I wanna

$result = mysqli_query($db, "SELECT videos FROM table");
while($row=mysqli_fetch_assoc($result) {

$embedUrl = $row["videos"];

//so i wanna show only not working url's
if($embedUrl == false) 
echo $embedUrl;
} 

This is example of not working link here

Upvotes: 0

Views: 807

Answers (1)

Ro Achterberg
Ro Achterberg

Reputation: 2704

Try this. Outputs: 'Video unavailable' if a video doesn't exist.

See comments for step-by-step explanation.

<?php

// Your Openload URL
$url = 'https://openload.co/embed/UgmaOAo1wlg/Horrible.Bosses.2.2014.720p.BluRay.x264.YIFY.mp4';

// Initialize cURL library.
if (($curl = curl_init()) === FALSE)
{
        $errno = curl_errno();
        throw new RuntimeException("curl_init() ($errno): " . curl_strerror($errno));
}

// Tell cURL which URL to operate on. GET is the default method.
curl_setopt($curl, CURLOPT_URL, $url);

// Optionally specify a path to a certificate store in PEM format.
// curl_setopt($curl, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
// Given Openload URL is requested over https. Allow for some sanity checking.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
// Set this to the latest SSL standard supported by PHP at the time of this answer.
curl_setopt($curl, CURLOPT_SSLVERSION, 6);

// Return response, so we can inspect its contents.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// Openload returns HTTP code 200 if a video wasn't found. Any code >= 400 indicates a different problem.
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
// Allow for server-side redirects.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
// Don't include header in response.
curl_setopt($curl, CURLOPT_HEADER, FALSE);

if (($response = curl_exec($curl)) === FALSE)
    throw new RuntimeException("curl_exec() failed for $url: " . curl_error($curl));

// Perform a case-insensitive search for a token that is specific to the 'video not found' page.
if (stripos($response, '<img class="image-blocked" src="/assets/img/blocked.png" alt="blocked">') !== FALSE)
    echo 'Video unavailable';

Upvotes: 1

Related Questions