代码里面的域名更换成自己的域名即可
<?php
error_reporting(0);
//关闭所有PHP错误报告
define(‘IFHC’,1);
//是否缓存视频链接 1 缓存 0 不缓存
define(‘HCFILE’,__DIR__.’/cache/’);
//缓存保存的文件夹 如果不缓存请无视
define(‘HCTIME’,604800);
//缓存时效 秒为单位 如果不缓存请无视
header(‘Content-type: text/json;charset=utf-8’);
$url = $_GET[‘url’];
$MD5 = Md5($url).’.m3u8′;
if (is_dir(HCFILE)==false) {
mkdir(HCFILE,0755,true);
}
if (IFHC==1 && file_exists(HCFILE.$MD5) && filemtime(HCFILE.$MD5) + HCTIME > time()) {
$arr = array(
‘code’ => 200,
‘msg’ => ‘解析成功’,
‘cache’ => true,
‘url’ => ‘https://www.51smzj.com/’.$MD5
);
die(json_encode($arr,456));
}
$data = curl($url);
if (empty($data)) {
die(404);
}
if (strstr($data,’.ts’)==false) {
$explode = explode(‘/’,$data);
$ts = explode(“\n”,$explode[0])[2];
$url = str_replace(‘index.m3u8′,”, $url).$ts.’/’.$explode[1].’/’.$explode[2];
$data = curl($url);
if (empty($data)) {
die(404);
}
}
echo m3u8ts($url,$MD5,$data,$explode[2]);
function m3u8ts($wz , $file , $data , $name){
$data = preg_replace(‘/#EXTINF:(.*),\n?http(.*)\n?/’,”,$data);
preg_match(‘/\/\/(.*)\/’.$name.’/’,$wz,$ym);
$web = ‘https:’.str_replace($name,”, $ym[0]);
$m3u8 = preg_replace(‘/#EXTINF:(.*),\n?(.*)\n?/’,”#EXTINF:$1,\n$web$2\n”,$data);
file_put_contents(HCFILE.$file,$m3u8);
$arr = array(
‘code’ => 200,
‘msg’ => ‘解析成功’,
‘url’ => ‘https://www.51smzj.com/’.$file
);
die(json_encode($arr,456));
return;
}
function curl($url) {
if(!function_exists(‘curl_init’)) die(‘php.ini未开启php_curl.dll’);
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
“accept: */*”,
“accept-encoding: gzip, deflate”,
“accept-language: zh-CN,zh;q=0.9”,
“Connection: keep-alive”,
));
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36′);
curl_setopt($ch, CURLOPT_REFERER,’https://www.51smzj.com/’);
curl_setopt($ch, CURLOPT_ENCODING, “gzip, deflate”);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
@ $file = curl_exec($ch);
curl_close($ch);
return $file;
}