一直播解析源码
- <?php
- //require_once(“../include/global.inc.php”);
- //$url = “http://www.yizhibo.com/l/v-InULNRQCjyrNSv.html”;
- echo json_encode(YiZhiBo::parse($url));
- /**
- *
- */
- class YiZhiBo
- {
- public static function parse($url)
- {
- $content = self::curl($url);
- preg_match(‘#play_url:”(.*)”,#’,$content,$urls);
- preg_match(‘#scid:”(.*)”,#’,$content,$vids);
- preg_match(‘#covers:”(.*)”,#’,$content,$posters);
- preg_match(‘#nickname:”(.*)”,#’,$content,$names);
- $ids[‘vid’] = isset($vids[1]) ? $vids[1] : exit(‘dd’);
- $ids[‘url’] = isset($urls[1]) ? $urls[1] : ”;
- $ids[‘poster’] = isset($posters[1]) ? $posters[1] : ”;
- $ids[‘name’] = isset($names[1]) ? $names[1] : ”;
- return self::get_video_info($ids);
- }
- public static function get_video_info($ids)
- {
- $api = “http://www.yizhibo.com/live/h5api/get_basic_live_info?scid={$ids[‘vid’]}”;
- $content = self::curl($api);
- $json = json_decode($content,true);
- if(isset($json[“data”])){
- $data = $json[“data”];
- $name = isset($data[“nickname”]) ? $data[“nickname”] : $ids[‘name’];
- $videoinfo[‘code’] = 200;
- $videoinfo[“data”][“poster”] = isset($data[“covers”]) ? $data[“covers”] : $ids[‘poster’];
- $videoinfo[“data”][“url”] = isset($data[“play_url”]) ? $data[“play_url”] : $ids[‘url’];
- $videoinfo[“data”][“name”] = $name;
- $videoinfo[“play”] = ‘hls’;
- }
- return $videoinfo;
- }
- public static function curl($url)
- {
- $params[“ua”] = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36”;
- return GlobalBase::curl($url,$params);
- }
- }
- ?>