重庆电视台php

warning: 这篇文章距离上次修改已过655天,其中的内容可能已经有所变动。

重庆卫视,id=2
重庆新闻,id=3
<-?php
$t=date('YmdHi');
$type=isset($_GET['type'])?$_GET['type']:'hls';
$id=isset($_GET['id'])?$_GET['id']:'2';
$u="https://sjlivecdn9.cbg.cn/".$t."/app_2/_definst_/ls_".$id.".stream/";

if($type=='key'){

$d = k('https://sjlivecdnx.cbg.cn/1ive/stream_'.$id.'.php','https://www.cbg.cn/');

}else if($type=='hls'){

//header("Content-type: application/x-mpegURL");
$m3u8=m3u8($u.'chunklist.m3u8');
getPHPm3u($m3u8,$u,$id);

}

function m3u8($url){

$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_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;

}
function getPHPm3u($_m3u8, $_u, $_id)
{

$phpself = substr($_SERVER['PHP_SELF'], strripos($_SERVER['PHP_SELF'], "/") + 1);
$_m3u8=preg_replace('/URI="(.*?)"/','URI="'.$phpself.'?type=key&id='.$_id.'"',$_m3u8);
if (strpos($_m3u8, '.ts')) {
    preg_match_all("/\n(.*?).ts/", $_m3u8, $a);
    for ($i = 0; $i < count($a[0]); $i++) {
        $_m3u8 = str_replace($a[0][$i], "\n" . $_u . $a[1][$i] . '.ts', $_m3u8);
    }
    echo $_m3u8;
}

}
function k($url,$ref){

$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_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_REFERER, $ref);
$result = curl_exec($ch);
curl_close($ch);

}
?->
注:由于重庆台直播源m3u8里的key文件是带有Referer验证的,故本人已在此php加上key文件带Referer验证转发的代码,故在播放器里播放完全无需另加Referer。

添加新评论