|
|
发表于 2026-1-26 23:23:54
|
显示全部楼层
<?php
$id = $_GET['id'] ?: 'cctv1hd_3000';
$seq = intval(time()/10) - 8;
// 1. 生成M3U8头
header('Content-Type: application/vnd.apple.mpegurl');
echo "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-TARGETDURATION:10\n#EXT-X-MEDIA-SEQUENCE seq\n";
// 2. 关键修改:将TS文件地址指向本脚本自身,并通过参数传递
for($i = 0; $i < 7; $i++) {
$currentSeq = $seq + $i;
echo "#EXTINF:10.0,\n";
// 不再直接输出原始TS地址,而是输出一个经过本代理的地址
echo "?type=ts&id=$id&seq=$currentSeq\n";
}
// 3. 代理转发部分:当请求参数为ts时,去获取真实的TS流
if (isset($_GET['type']) && $_GET['type'] === 'ts') {
$proxyUrl = 'http://live1.hrtn.net/live/' . $_GET['id'] . '/' . $_GET['id'] . '_' . $_GET['seq'] . '.ts';
// 创建一个携带特定请求头的上下文
$options = [
'http' => [
'method' => 'GET',
'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\r\n" .
// 尝试添加Referer,如果知道来源页的话
// "Referer: http://example-tv-site.com/\r\n"
]
];
$context = stream_context_create($options);
// 转发内容
$tsContent = @file_get_contents($proxyUrl, false, $context);
if ($tsContent !== false) {
header('Content-Type: video/mp2t');
echo $tsContent;
} else {
// 可以记录错误日志
header('HTTP/1.1 404 Not Found');
}
exit;
}
?> |
|