|
还有一种双PHP文件的写法,欢迎指正~~~
文件一:hftv.php
(前面同)
if (empty($_GET['ts'])){
print_r(preg_replace("/(.*?.ts)/i","hfts.php?ts=$live$1",get_data($playurl,1)));//get最终m3u8地址,获取TS信息;把ts地址转换成代理的外部参数。
exit;
}
/*//这部分不要
else{
$ts=get_data($_GET['ts'],0);//get ts参数传入的ts地址。
//header("Content-type: video/mp2t");
echo $ts;
exit;
}
*/
文件二:hfts.php (专门解析TS切片)
<?php
header('Content-Type: text/json;charset=UTF-8');
$ts= get_data($_GET['ts']);
//header("Content-type: video/mp2t");
echo $ts;
exit;
function get_data($url){
$header=array(
"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:50.0) Gecko/20100101 Firefox/50.0",
"Referer: http://m.hfbtv.com/application/t ... nline=0&type=tv",
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
把hftv.php和hfts.php在服务器同一位置即可。此方法是否更优,有待验证。
|
|