山东临沂电视PHP代理、酷9 js

看到有人分享临沂电视,官网:

https://www.ilinyi.net/cms/tv/36417907

有3个节目,按F12打开浏览器开发者模式,很容易看到三个节目的地址:

https://m3u8-channel.lytv.tv/nmip-media/channellive/channel111841/playlist.m3u8

https://m3u8-channel.lytv.tv/nmip-media/channellive/channel115062/playlist.m3u8

https://m3u8-channel.lytv.tv/nmip-media/channellive/channel113571/playlist.m3u8

但是,这个m3u8是无法直接播放的,因为这个地址是有referer验证,即:

Referer: https://www.ilinyi.net/

因此,如果我们写PHP代理的话可以使用m3u8+ts转发:

<?php
// 设置公共的 HTTP headers
$headers = [
    'Referer: https://www.ilinyi.net/'
];

// 频道ID映射关系
$channelMap = [
    'lyzh' => '111841',
    'lyjj' => '115062',
    'lygg' => '113571'
];

// 获取当前脚本文件名
$currentFile = basename($_SERVER['SCRIPT_FILENAME']);

// 获取请求参数
$id = isset($_GET['id']) ? $_GET['id'] : 'lyzh';
$tsParam = isset($_GET['ts']) ? $_GET['ts'] : null;

// 根据ID获取对应的频道号,如果找不到则使用默认值
$channelId = isset($channelMap[$id]) ? $channelMap[$id] : '111841';
$url = "https://m3u8-channel.lytv.tv/nmip-media/channellive/channel{$channelId}/playlist.m3u8";

if ($tsParam) {
    // 如果传入了 ts 参数,则转发对应的 ts 文件
    // 设置内容类型为 ts
    header('Content-Type: video/mp2t');
    
    // 初始化 curl 来获取 ts 文件
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $tsParam);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); // 直接输出到浏览器
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    // 执行请求并将内容直接输出到浏览器
    curl_exec($ch);
    curl_close($ch);
} else {
    // 如果没有传入 ts 参数,则获取 m3u8 内容
    // 设置内容类型为 m3u8
    header('Content-Type: application/vnd.apple.mpegurl');
    header('Access-Control-Allow-Origin: *');
    
    // 获取原始 m3u8 内容
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    // 处理 m3u8 内容,将 ts 链接替换为本地转发链接
    $lines = explode("\n", $response);
    $output = [];
    
    foreach ($lines as $line) {
        if (strpos($line, '.ts') !== false && strpos($line, 'http') === 0) {
            // 如果是 ts 链接,则替换为本地转发链接,并附带 id 参数
            $output[] = "{$currentFile}?id={$id}&ts=" . urlencode($line);
        } elseif (strpos($line, '.ts') !== false && strpos($line, 'http') !== 0 && strpos($line, '/') !== 0) {
            // 相对路径的 ts 链接
            $baseUrl = dirname($url);
            $fullTsUrl = $baseUrl . '/' . $line;
            $output[] = "{$currentFile}?id={$id}&ts=" . urlencode($fullTsUrl);
        } else {
            $output[] = $line;
        }
    }
    
    echo implode("\n", $output);
}

将php直接上传到支持php的服务器,然后http://你的主机地址/xxx.php?id=lyzh即可:

php播放
php播放

如果是用酷9 js的话就更简单了,返回带referer的url即可:

functionmain(item) {
// 频道ID映射表
const channelMap = {
'lyzh''111841',   // 临沂综合
'lyjj''115062',   // 临沂经济
'lygg''113571'// 临沂公共
  };

// 获取频道ID参数
const channelId = ku9.getQuery(item.url, "id") || "lyzh";

// 检查频道ID是否有效
if (!channelMap[channelId]) {
return JSON.stringify({
errortrue,
message"无效的频道ID",
availableIdsObject.keys(channelMap)
    });
  }

// 获取频道号
const channelNumber = channelMap[channelId];

// 直播流URL
const streamUrl = `https://m3u8-channel.lytv.tv/nmip-media/channellive/channel${channelNumber}/playlist.m3u8`;

// 返回结果
return JSON.stringify({
url: streamUrl,
headers: {
"Referer""https://www.ilinyi.net/"
    }
  });
}

将代码存为js文件,如xxx.js,放到酷9 js文件夹下,然后http://A/ku9/js/xxx.js?id=lyzh即可播放:

酷9播放
酷9播放

1人评论了“山东临沂电视PHP代理、酷9 js”

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部