M3U8文件和TS切片加了Referer验证的PHP代理示例

主要使用 PHP 进行流量转发,需要消耗自己 PHP 服务器的带宽和流量。

链接例子:https://rtmlive06.secureswiftcontent.com/rtmchannel/06-manifest.m3u8

坛友一(kof97zip):

<?php
//Author: kof97zip
error_reporting(0);
header('Content-Type: text/json;charset=UTF-8');
$id = $_GET['id'];//1-6
$header = array(
    "Host: rtmlive01.secureswiftcontent.com",
    "Connection: keep-alive",
    "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4350.0 Iron Safari/537.36",
    "Accept: */*",
    "Origin: https://rtmklik.rtm.gov.my",
    "Sec-Fetch-Site: cross-site",
    "Sec-Fetch-Mode: cors",
    "Sec-Fetch-Dest: empty",
    "Referer: https://rtmklik.rtm.gov.my/tv/".$id,
    "Accept-Language: zh-CN,zh;q=0.9",
);
if($id !== NULL){
    $m3u8 = m3u8("https://rtmlive01.secureswiftcontent.com/rtmchannel/0".$id."-1080.m3u8",$header);
    $m3u8 = str_replace("0".$id."-1080-","my.php?ts=0".$id."-1080-",$m3u8);
    print_r($m3u8);
}else{
    $ts = $_GET['ts'];
    $data = ts("https://rtmlive01.secureswiftcontent.com/rtmchannel/".trim($ts),$header);
}

function m3u8($url,$header){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

function ts($url,$header){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    curl_close($ch);
}
?>
《M3U8文件和TS切片加了Referer验证的PHP代理示例》

坛友二(Taki):

<?php
//Author: Taki
error_reporting(0);
$id = $_GET['id'];
$m3u8 = empty($_GET['m3u8']) ? "$id-1080" : trim($_GET['m3u8']);
$time = $_GET['time'];
$bstr = isset($time)?$time:'';    
if($bstr == '')
{
    $url = "https://rtmlive$id.secureswiftcontent.com/rtmchannel/$m3u8.m3u8";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: https://rtmklik.rtm.gov.my/'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $data = curl_exec($ch);
    curl_close($ch);
    $table_change = array("$id-"=>"rtm.php?id=$id&m3u8=$id-",".m3u8"=>"",".ts"=>"","$m3u8-"=>"?id=$id&m3u8=$m3u8&time=");
    $data = strtr($data,$table_change);
    echo $data;
}
else
{
    $url = "https://rtmlive$id.secureswiftcontent.com/rtmchannel/$m3u8-$time.ts";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: https://rtmklik.rtm.gov.my/'));
    $data = curl_exec($ch);
    curl_close($ch);
}
header("Cache-Control: no-cache");
//header("Content-type:application/vnd.apple.mpegurl");
?>

搬运的,记录方法,方便套用。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

  1. lj2323 lj2323 说道:

    请问下这个PHP是不是可转发局域网内的直播流呢?

    1. 黑鸟 说道:

      意义不大,效率较低,请直接 Nginx 等转发 ..

      1. lj2323 lj2323 说道:

        nginx倒是有安装,但是搞不来,感觉好像很麻烦

  2. Taki Taki 说道:

    我是源码的原作者之一,请问您转载时能不能加个转载来源或者转载的恩山论坛ID呢?我看您最新发的那个央视频C4K的文章就有在标题上注明是转载wjxgzz大佬的呢

    1. 黑鸟 说道:

      更新了