|
本帖最后由 追影 于 2021-8-21 12:57 编辑
- <?php
- error_reporting(0);
- header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
- function get_url_contents($url)
- {
- if (function_exists('curl_init')) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_URL, $url);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- } else {
- if (ini_get("allow_url_fopen") == "1") {
- return file_get_contents($url);
- }
- }
- }
- function resolve_hls($url)
- {
- $url = trim(urldecode($url));
- $old = pathinfo($url);
- $m3u8 = get_url_contents($url);
- if (!empty($old['dirname'])) {
- if (strpos($m3u8,'EXT-X-STREAM-INF')!== false) {
- try {
- preg_match_all('/([\S]+)(\.m3u8)+(.*)?/i', $m3u8, $match);
- $new = $match[0][0];
- if (stripos($new, 'http:') !== false || stripos($new, 'https:') !== false || substr($new, 0, 2) == '//') {
- $newUrl = $new;
- } else {
- $newUrl = $old['dirname'] . '/' . $new;
- }
- resolve_hls($newUrl);
- }catch (\Exception $exception) {
- echo $exception->getMessage();
- }
- } else {
- try {
- preg_match_all('/([\S]+)(\.ts)+(.*)?/i', $m3u8, $match_ts);
- if(empty($match_ts[0][0])){
- preg_match_all('/([\S]+)(\.aac)+(.*)?/i', $m3u8, $match_ts);
- }
- $new = $match_ts[0][0];
- if (stripos($new, 'http:') !== false || stripos($new, 'https:') !== false || substr($new, 0, 2) == '//') {
- $newUrl = '';
- } else {
- $newUrl = $old['dirname'] . '/';
- }
- echo preg_replace_callback('/([\S]+)(\.ts)+(.*)?/i', function ($mtches) use ($newUrl){
- return 'https://qianxun.damicms.com/transhls.php?action=' . urlencode($newUrl . $mtches[0]);
- }, $m3u8);
- } catch (\Exception $exception) {
- echo $exception->getMessage();
- }
- }
- }
- }
- if (!empty($_GET['url'])) {
- $url = urldecode($_GET['url']);
- resolve_hls($url);
- } else if(!empty($_GET['action'])){
- $url2 = trim(urldecode($_GET['action']));
- $m3u8 = get_url_contents($url2);
- echo $m3u8;
- }
- ?>
复制代码 当网站升级https后发现网站引用http的hls资源无发播放
|
|