PHP Curl使用接口从视频页面获取视频源URL,但不在html5视频播放器上播放
我正在编写一个新的代码,并尝试使用带有接口的curl从pornhub视频页面获取视频源URL 这段代码几天前运行正常,但我认为色情中心已经改变了他们的流媒体服务器上的一些东西,它已经停止工作。我的代码仍在pc的本地主机上运行,但当我在服务器上运行时,出现403错误PHP Curl使用接口从视频页面获取视频源URL,但不在html5视频播放器上播放,php,curl,Php,Curl,我正在编写一个新的代码,并尝试使用带有接口的curl从pornhub视频页面获取视频源URL 这段代码几天前运行正常,但我认为色情中心已经改变了他们的流媒体服务器上的一些东西,它已经停止工作。我的代码仍在pc的本地主机上运行,但当我在服务器上运行时,出现403错误 function get_site_html_string($url, $cookie=NULL, $referer = NULL, $timeout = CURL_TIMEOUT){ $ip = 'x.x.x.x'
function get_site_html_string($url, $cookie=NULL, $referer = NULL, $timeout = CURL_TIMEOUT){
$ip = 'x.x.x.x'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_INTERFACE,$ip);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6000);
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_NOPROGRESS, CURL_PROGRESS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.101 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($referer) {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ( $cookie ) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
$string = curl_exec($ch);
if (curl_errno($ch)) {
echo var_dump(curl_error($ch));
return FALSE;
}
curl_close($ch);
return $string;
}
function get_video_url_pornhub($url=''){
$html = get_site_html_string($url);
preg_match_all('/quality":"(.*?)","videoUrl":"(.*?)"/', $html, $matches_url);
foreach ($matches_url[2] as $k => $v) {
if (trim($v) != '') {
$videos[$matches_url[1][$k]] = stripslashes($v);
}
}
ksort($videos);
return $videos;
}
$url = 'https://www.pornhub.org/view_video.php?viewkey=ph5d27619512bda';
$videos = get_video_url_pornhub($url);
print_r($videos);
<video width="320" height="240" controls>
<source src="<?php echo $videos[480] ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
函数get\u site\u html\u string($url,$cookie=NULL,$referer=NULL,$timeout=CURL\u timeout){
$ip='x.x.x.x'
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_接口,$ip);
curl_setopt($ch,CURLOPT_头,FALSE);
curl_setopt($ch,CURLOPT_COOKIEJAR,COOKIE_文件);
curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIE_FILE);
curl_setopt($ch,CURLOPT_HTTPGET,TRUE);
curl_setopt($ch,CURLOPT_POST,FALSE);
curl_setopt($ch,CURLOPT_超时,6000);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,6000);
curl_setopt($ch,CURLOPT_VERBOSE,FALSE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_NOPROGRESS,curl_PROGRESS);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,比如Gecko)Chrome/53.0.2785.101 Safari/537.36');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
如果($referer){
curl_setopt($ch,CURLOPT_REFERER,$REFERER);
}
如果($cookie){
curl_setopt($ch,CURLOPT_COOKIE,$COOKIE);
}
$string=curl\u exec($ch);
if(旋度误差($ch)){
echo var_dump(curl_error($ch));
返回FALSE;
}
卷曲关闭($ch);
返回$string;
}
函数get\u video\u url\u pornhub($url=''){
$html=get\u site\u html\u字符串($url);
preg_match_all('/quality:“(.*?)”,“videoUrl:“(.*?/”,$html,$matches_url);
foreach($k=>$v匹配_url[2]{
如果(修剪($v)!=''){
$videos[$matches\u url[1][$k]]=斜杠($v);
}
}
ksort(视频);
返回$videos;
}
$url='1https://www.pornhub.org/view_video.php?viewkey=ph5d27619512bda';
$videos=get\u video\u url\u pornhub($url);
印刷(视频);