|
本帖最后由 Wheiss 于 2024-1-2 18:48 编辑
<?php
/*时区设置*/
date_default_timezone_set("PRC");
/*id部分*/
$id = empty($_GET['id']) ? "ybws" : $_GET['id'];
if (preg_match('/\?.*|\$.*/', $id)) {//源标签兼容
$id = preg_replace('/\?.*|\$.*/', '', $id);
}
$id_arr = [
"ybws"=>"cys",//延边卫视
"ybtv1"=>"ybtv1",//延边朝鲜语综合
"ybtv2"=>"ybtv2",//延边汉语综合
"ybxwgb"=>"fm983",//延边新闻综合广播
"yblygb"=>"fm1046",//延边旅游广播
"ybjtgb"=>"fm1059",//延边交通文艺广播
];
$id_arr2 = [
"iybws"=>"cys",//延边卫视
"iybtv1"=>"ybtv1",//延边朝鲜语综合
"iybtv2"=>"ybtv2",//延边汉语综合
"iybwyshgb"=>"am1206",//延边文艺生活广播
"iybxwzhgb"=>"fm1023",//延边新闻综合广播
"iybksgb1"=>"vradio",//延边可视广播*
"iybksgb2"=>"vraido2",//延边可视广播2*
];
/*url部分*/
if (isset($id_arr[$id])){
$html_url = "http://www.yb983.com/{$id_arr[$id]}/index.html";
} else if (in_array($id,array_keys($id_arr2))){
$html_url = "http://www.iybtv.com/{$id_arr2[$id]}/index.html";
} else {
die("id不存在");
}
$html_data = file_get_contents($html_url);
if ($html_data === false){
die("无法读取html文件内容");
}
$pattern = "/a:'(http.+)',\/\//";
preg_match($pattern,$html_data,$match);
if (!isset($match[1])){
die("未匹配到url");
}
$url = $match[1];
/*回看参数引入*/
$playseek = $_GET['playseek']??'';
$starttime = $_GET['starttime']??'';
$endtime = $_GET['endtime']??'';
/*模式判断*/
if (empty($playseek) && empty($starttime)) {
header("location: {$url}");
} else {//回看
$url1 = preg_replace('/index.m3u8/','',$url);
/*$playseek处理*/
if ($playseek) {
$t_arr=explode('-',$playseek);
$starttime = strtotime($t_arr[0]);
$endtime = strtotime($t_arr[1]);
}
/*媒体序列号获取*/
$json_data = file_get_contents('https://api.wheiss.com/json/ybtv');
$json_arr = json_decode($json_data,true);
$times = $json_arr['parameter']['times'];
$offset = $json_arr['parameter']['offset'];
$s_seq = intval($starttime/$times-$offset);
$e_seq = intval($endtime/$times-$offset);
/*m3u8列表生成*/
$m3u8 = "#EXTM3U".PHP_EOL."#EXT-X-VERSION:3".PHP_EOL."#EXT-X-ALLOW-CACHE:YES".PHP_EOL."#EXT-X-TARGETDURATION:7".PHP_EOL."#EXT-X-MEDIA-SEQUENCE:{$s_seq}".PHP_EOL;//前5行
for (; $s_seq < $e_seq; $s_seq++) {
$m3u8 .= "#EXTINF:5.95,".PHP_EOL."{$url1}{$s_seq}.ts".PHP_EOL;
}
$m3u8 .= "#EXT-X-ENDLIST";//结束标志
/*输出部分*/
header("Content-Type: application/vnd.apple.mpegURL");
header("Content-Disposition: inline; filename=index.m3u8");
echo $m3u8;
}
exit;
?>
2024/01/02 18:45 能编辑了,故更新一下
|
|