b站视频默认可以获取站外调用代码,使用的是iframe框架代码,想要直接读取解析调用b站视频链接,需要使用解析b站视频地址代码,那么如何使用php读取解析调用b站视频链接呢,下面蓝叶分享一段简易的解析b站视频地址代码,只是获取低像素的供测试学习,高清像素解析就不分享了。
<?php /* * 解析调用B站视频代码 * author:蓝叶 * url:lanye.org * 使用方法?id=b站视频id */ error_reporting(0); $domain = trim($_SERVER['SERVER_NAME']); $domainList = "127.0.0.1,localhost,lanye.org"; $diymusic = 'https://lanye.org/static/daolian.mp3'; if(!preg_match('/('.$domain.')/i', $domainList)){ header('location:'.$diymusic); exit(); } $id = isset($_GET['id']) ? addslashes($_GET['id']) : 'BV1264y1Y78s'; $data = Curl('https://m.bilibili.com/video/'.$id); preg_match('/"aid":(.*),"bvid":"(.*)","cid":(.*),"readyPoster":"(.*)","readyVideoUrl":"(.*)","readyDuration"/i', $data, $match); $img = isset($match[4])?$match[4]:''; $mp4 = isset($match[5])?$match[5]:''; header('location: '.$mp4); exit(); function Curl($url){ $curl = curl_init(); $headers = array( "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1" ); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER,$headers); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_REFERER, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $response = curl_exec($curl); curl_close($curl); return $response; }
免责声明:
本页网址:点击复制分享给朋友吧!
本站分享的一切内容资源如若没有备注,均为蓝叶原创,如需转载请注明出处;如有侵权请与我们联系处理。敬请谅解!