bet365直播信息列表以及直播源获取教程

作者:admin人气:0更新:2021-04-22 21:47:53

这套代码和昨天公布的代码基本是一个意思,是获取直播源的爬虫代码,网上基本没有,同样只放出了部分,仅供学习参考,商用代码可以联系我获取,不过是有偿的.有的朋友可能看不懂这套代码,没关系,你可以提出你的需求,我来帮你写。

<?php

$streamId = $_REQUEST['streamId'];

$eventId = $_REQUEST['eventId'];

$cookie1 = $_REQUEST['cookie1'];

$cookie2 = $_REQUEST['cookie2'];

if(empty($streamId)){

$streamId = bet365ck($eventId);

}

$UrlCookie1 = "state=116; aps03=ct=42&lng=10; bet365SportsExtra=settings=0,0,0,0,0,27,0,RMB,1,1; pstk=$cookie1";

$UrlCookie2 = "state=116; aps03=ct=42&lng=10; bet365SportsExtra=settings=0,0,0,0,0,27,0,RMB,1,1; pstk=$cookie2";

if(empty($streamId)){exit("err1");}

$EventCode = Bet365Init($streamId,$eventId,$UrlCookie1,$UrlCookie2,$cookie1,$cookie2); 

exit($EventCode);


function Bet365Init($Str,$eventId,$UrlCookie1,$UrlCookie2,$cookie1,$cookie2){

$HttpUrl = "https://videostream.bet365.com.au/streamingapi/stream";

$referer = "https://extra.bet365.com/streaming/zh-CHS?sl=1";

$ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";

$h = "Content-type: application/x-www-form-urlencoded;Host: videostream.38365365.com;Origin: https://www.48365-365.com;Accept: */*;";

$socksip = "";

$shellcode = "curl --cookie '${UrlCookie1}' --referer '${referer}' --user-agent '${ua}' -H '${h}' -X POST -d 'm=${Str}&t=1' ${HttpUrl}";// --socks5 '$socksip'  m=${Str}&t=1

$EventCodeS = shell_exec($shellcode);

if($EventCodeS === "Response=notloggedin" || !empty(strpos($EventCodeS,"geoblocked"))){

$shellcode = "curl --cookie '${UrlCookie2}' --referer '${referer}' --user-agent '${ua}' -H '${h}' -X POST -d 'm=${Str}&t=1' ${HttpUrl}";// --socks5 '$socksip'  m=${Str}&t=1

$EventCodeS = shell_exec($shellcode);

}

/*

$jsondata = file_get_contents('sockslist.json');

$obj = json_decode($jsondata);

foreach ( $obj as $unit ){

$socksip = $unit->ip;

$shellcode = "curl --cookie '${UrlCookie1}' --referer '${referer}' --user-agent '${ua}' -H 'Content-type: application/x-www-form-urlencoded;' --socks5 '$socksip' -X POST -d 'm=${Str}' ${HttpUrl}";

$Code = shell_exec($shellcode);

if(!empty($Code)){ 

$EventCodeS = $Code;

break;

}

}

*/

$EventCodeS = DoBOM($EventCodeS);

if(!empty($EventCodeS)){

$EventCodeS = str_replace("&url=","@@",$EventCodeS);

$EventCodeS = str_replace("ProviderID=","",$EventCodeS);

$StreamCodeS = explode('@@',$EventCodeS);

$ProviderID = $StreamCodeS[0];

$url = $StreamCodeS[1];

$url = urldecode($url);

if($ProviderID === "9" || $ProviderID === "19" || $ProviderID === "20"){

$url = str_replace("https","http",$url);

$liveurl = imgcode($url);

//$liveurl = urlencode($liveurl);

$ck = "1";

}elseif($ProviderID === "3" || $ProviderID === "10"){

$url = str_replace("https","http",$url);

$url = str_replace("protocol=rtmp","protocol=hls",$url);

$url = str_replace("mobilestreamaccess.unas.tv/multistreaming","streamaccess.unas.tv/mobile/live",$url);

$liveurl = utvrtmpcode($url);

$liveurl = str_replace("https","http",$liveurl);

//$liveurl = urlencode($liveurl);

$ck = "2";

}elseif($ProviderID === "4" || $ProviderID === "7"){

$liveurl = bet365rtmp($url);

//$liveurl = str_replace("https","http",$liveurl);

//$liveurl = urlencode($liveurl);

$ck = "2";

}elseif($ProviderID === "21" || $ProviderID === "22"){

$liveurl = $url;

//$liveurl = urlencode($liveurl);

$ck = "1";

}else{

$liveurl = str_replace("https","http",$url);

//$liveurl = urlencode($liveurl);

$ck = "1";

}

//$liveurl = $ck."@@".$liveurl;

$liveurl = $liveurl;

}

exit($liveurl);

}




function bet365ck($str){

$UrlStr = "https://api.betsapi.com/v1/bet365/event?token=abc${str}";

$EventCode = file_get_contents($UrlStr);

preg_match('|"MS":"(.*?)"|i',$EventCode,$Code1); 

$MS = $Code1[1];

if(!empty($MS)){

return $MS;

}

}


function CurlInitHTTPUnas($UrlStr,$ip,$UrlRefere,$UrlCookie){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"${UrlStr}");

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-FORWARDED-FOR:$ip", "CLIENT-IP:$ip","origin: https://mobile.48365-365.com"));

curl_setopt($ch, CURLOPT_REFERER, "https://mobile.48365-365.com/");

curl_setopt($ch, CURLOPT_COOKIE, "$UrlCookie");

curl_setopt($ch, CURLOPT_TIMEOUT, 5);

curl_setopt($ch, CURLOPT_HEADER,0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 

curl_setopt($ch, CURLOPT_ENCODING ,'gzip');

if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

}

curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36");

$out = curl_exec($ch);

curl_close($ch);

return $out;

}



function imgcode($UrlStr){

$StreamCode = CurlInitHTTP($UrlStr,$ip,$UrlStr,"test");

$obj = json_decode($StreamCode);

$statusText = $obj->statusText;

if($statusText == "Not Found"){exit("");}

if($statusText == "Bad Request"){exit("");}

if(!empty($statusText)){exit("");}

$rtmpUrl = $obj->rtmpUrl;

$hlsUrl = $obj->hlsUrl;

if(empty($hlsUrl)){exit("");}

return $hlsUrl;

}


function utvrtmpcode($code){

$UrlStr = $code;

$UrlCookie = "test!";

$serverip = $_SERVER["SERVER_ADDR"];

$ip = $serverip;

$StreamCode = CurlInitHTTPUnas($UrlStr,$ip,$UrlStr,"test");

$find = "restricted";

$strpos = strstr($StreamCode,$find);

if(!empty($strpos)){    

$ip = rand_ip();     

$StreamCode = CurlInitHTTPUnas($UrlStr,$ip,$UrlRefere,$UrlCookie);

$find = "restricted";

$strpos = strstr($StreamCode,$find);

}

if(!empty($strpos)){

$ip = "203.162.224.139";

$StreamCode = CurlInitHTTPUnas($UrlStr,$ip,$UrlRefere,$UrlCookie);

$find = "restricted";

$strpos = strstr($StreamCode,$find);

}

if(!empty($strpos)){         

$ip = "123.17.0.2";

$StreamCode = CurlInitHTTPUnas($UrlStr,$ip,$UrlRefere,$UrlCookie);

}

preg_match('|url="(.*?)"|i',$StreamCode,$UrlCodeS); 

$Url = $UrlCodeS[1];

/*

preg_match('|auth="(.*?)"|i',$StreamCode,$AuthCodeS); 

$Auth = $AuthCodeS[1];

preg_match('|stream="(.*?)"|i',$StreamCode,$StreamCodeS); 

$Stream = $StreamCodeS[1];

preg_match('|status="(.*?)"|i',$StreamCode,$StatusCodeS); 

$StatusCode = $StatusCodeS[1];

$EventCode = "rtmp://".$Url."/".$Stream."?auth=".$Auth."&aifp=v001";

*/

if(empty($Url)){ 

return "";

}else{

return $Url;

}

}


function bet365rtmp($code){

$EventUrl = str_replace("validation/addUser","wab/multiformat",$code);

$EventCode = CurlInitHTTP($EventUrl,$ip,$EventUrl,"test!");

preg_match_all('/\[CDATA\[([\s\S]*?)\]\]/',$EventCode,$b1);

$streamLaunchCode = $b1[1][1];


/*

$pa1 = '%<mediaFormat id="1012">(.*?)</mediaFormat>%si';

preg_match($pa1,$EventCode,$r1);

$mediaFormat = $r1[1];

$pa2 = '%<streamLaunchCode>(.*?)</streamLaunchCode>%si';

preg_match($pa2,$mediaFormat,$r2);

$streamLaunchCode = $r2[1];

$streamLaunchCode = str_replace("<![CDATA[","",$streamLaunchCode);

$streamLaunchCode = str_replace("]]>","",$streamLaunchCode);

$streamLaunchCode = trim($streamLaunchCode);

*/

$streamLaunchCode = "http://127.0.0.1:33333/ptvr/live/index.m3u8?url=".urlencode($streamLaunchCode);

return $streamLaunchCode;

}


function CurlInitHTTP($UrlStr,$ip,$UrlRefere,$UrlCookie){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"${UrlStr}");

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-FORWARDED-FOR:".$ip."", "CLIENT-IP:".$ip.""));

curl_setopt($ch, CURLOPT_REFERER, "$UrlRefere");

curl_setopt($ch, CURLOPT_COOKIE, "$UrlCookie");

curl_setopt($ch, CURLOPT_TIMEOUT, 5);

curl_setopt($ch, CURLOPT_HEADER,array('HOST:mobilestreamaccess.unas.tv'));

curl_setopt($ch, CURLOPT_HEADER,0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 

curl_setopt($ch, CURLOPT_ENCODING ,'gzip');

if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

}

curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");

$out = curl_exec($ch);

curl_close($ch);

return $out;

}


function CurlInit($UrlStr,$ip,$UrlRefere,$UrlCookie,$datacode,$socksip){

$HTTP_REQUEST_HEADER = array(

        "Host: extra.48365-365.com",

        "Connection: keep-alive",

        "Cookie: ".$UrlCookie,

        "Pragma: no-cache",

        "Cache-Control: no-cache",

        "Accept: */*",

        "Origin: https://extra.48365-365.com",

        "Upgrade-Insecure-Requests: 1",

        "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",

        "Content-Type: application/x-www-form-urlencoded",

        "Referer: https://extra.48365-365.com/streaming/zh-CHS?sl=1",

        "Accept-Encoding: gzip, deflate",

        "Accept-Language: zh-CN,zh;q=0.8"

);

$timeout = 15;

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $UrlStr);

curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36');

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_COOKIE, $UrlCookie);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, $HTTP_REQUEST_HEADER);

curl_setopt($curl, CURLOPT_POSTFIELDS, $datacode);

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);


curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, TRUE); 

curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);

curl_setopt($curl, CURLOPT_PROXY,$socksip); 

curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); 


curl_setopt($curl, CURLOPT_ENCODING ,'gzip');

//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($curl, CURLOPT_HEADER, true);

$out = curl_exec($curl);

curl_close($curl);

return $out;

}


function getcookies($sid){

$location = file_get_contents('../../filexml/json_config.json');

preg_match("|\"ck${sid}\":\"(.*?)\"|i",$location,$CodeS); 

$UrlCookie = $CodeS[1];

$UrlCookie = "pstk=$UrlCookie;aps03=tzi=&lng=;";

return $UrlCookie;

exit();

}



function short_md5($str){

    return substr(md5($str), 8, 16);

}


function DoBOM($text){

    if(substr($text, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) $text = substr($text, 9);

    return $text;

}

?>


更多标签

Copyright kds.tw Rights Reserved.