PHP如何检查openload视频是否存在?

时间:2018-12-18 15:44:34

标签: php mysql video

我需要检查开放视频是否存在,某些视频有时会被DMCA报告删除,而我只需要显示自己无法正常工作的链接即可。

仅是我想要的草图

$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;
} 

这是链接here无效的示例

1 个答案:

答案 0 :(得分:1)

尝试一下。输出:如果不存在视频,则显示“视频不可用”。

请参阅注释以获取逐步说明。

<?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';