36547583040 发表于 2025-3-21 10:32:13

湖北长江云js代码

本帖最后由 36547583040 于 2025-3-24 20:32 编辑

湖北长江云js代码,需要websocket轮询,获取到的链接需要referer验证。
websocket的作用是为了验证参数client-id,经过测试,这个id可以重复使用,可以把websocket单独运行,然后用固定id去获取播放链接。获取的链接一个小时会断流,需要重新获取链接,官网也是。
使用方法:
npm install axios
npm install ws
node 文件名.js

const axios = require('axios')
const WebSocket = require('ws')
var ws;
async function gethubei_liveinfo(tv_name) {
    let headers = {
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    }
    let url = "https://news.hbtv.com.cn/app/tv/431"
    const res = await axios.get(url, { headers: headers })
    let clientId = "";
    let passportid = ""
    let acw_tc = ""
    let aaLook = ""
    let clientToken = ""
    const cookies = res.headers['set-cookie'];
    cookies.forEach((cookie, index) => {

      if (cookie.includes("client-id")) {
            //clientId = cookie.replace("client-id=","")
            clientId = "c7ca84f3-9df9-4f03-bc08-47a2b9ce69da"

      }
      if (cookie.includes("PASSPORTID")) {
            passportid = cookie.replace("PASSPORTID=", "").replace("; path=/; HttpOnly", "")
      }
      if (cookie.includes("acw_tc")) {
            acw_tc = cookie.replace("acw_tc=", "").replace(";path=/;HttpOnly;Max-Age=1800", "")

      }

      if (cookie.includes("aa-look")) {
            aaLook = cookie.replace("aa-look=", "")

      }
      if (cookie.includes("client-token")) {
            clientToken = cookie.replace("client-token=", "")
      }

    });
    const t = Math.round(+new Date / 1E3)
    let cookiesStr = `CookieName=CookieValue;
    PASSPORTID=${passportid};
    Hm_lvt_9910fc6fdb612de131f642626cdedd8c=${t};
    HMACCOUNT=3862602DA029B3F8;
    Hm_lvt_2f29d6cea5a0b5c06250d0303f7076b7=${t};
    acw_tc=${acw_tc};
    Hm_lpvt_2f29d6cea5a0b5c06250d0303f7076b7=${t};
    Hm_lpvt_9910fc6fdb612de131f642626cdedd8c=${t}`
    cookiesStr = cookiesStr.replaceAll('\n', '')
    const data = res.data;
    const match = data.match(/liveList:\s*(\[.*?\]),\s*audioList/s);
    let tvname = `new-${tv_name}`;
    let q = "";
    if (match) {
      let jsonString = match
      const output = jsonString.replace(/^\s*\/\/.*$/gm, '');
      const matches = [...output.matchAll(/stream:\s*"([^"]+)"/g)].map(match => match);

      matches.forEach(element => {
            if (element.includes(tvname)) {
                q = element;

            }
      });
    } else {
      console.error("未匹配到 liveList 数据");
    }
    q = `https://news.hbtv.com.cn/ajax/get_cdn_leech?url=${q}&client-id=${clientId}`
    headers['cookie'] = cookiesStr
    headers['referer'] = 'https://news.hbtv.com.cn/app/tv/431'
    headers['x-requested-with'] = 'XMLHttpRequest'
    let res_ = await axios.get(q, { headers: headers })
    init_ws(aaLook,clientId,clientToken)
    console.log(res_.data.data)
    setInterval(()=>{
      let msg = {
            "aa_look": aaLook,
            "client_id": clientId,
            "client_token": clientToken
      };
      ws.send(JSON.stringify(msg));
      console.log("websocket心跳发送成功")
      console.log(`client-id:${clientId} \n`)
      console.log(`aaLook:${aaLook} \n`)
      console.log(`client_token:${clientToken} \n`)
    },30000)
   
}
function init_ws(aaLook,clientId,clientToken) {
    ws = new WebSocket('wss://remote-wa.cjyun.org.cn/liveweb', {

      headers: {

            'origin': 'https://news.hbtv.com.cn'
      }
    });

    ws.on('open', () => {
      console.log("websocket链接成功");
      let msg = {
            "aa_look": aaLook,
            "client_id": clientId,
            "client_token": clientToken
      };
      ws.send(JSON.stringify(msg));
      console.log("websocket心跳发送成功")
      console.log(`client-id:${clientId} \n`)
      console.log(`aaLook:${aaLook} \n`)
      console.log(`client_token:${clientToken} \n`)
      // ws.close()
    });

    ws.on('message', (data) => {

      let resMsg = JSON.parse(data);
      if (resMsg.wsnode) {
            const nodeData = resMsg.wsnode;
            console.log("收到 wsnode,关闭连接");
            // ws.close(); // 如果需要关闭连接
            resolve(nodeData); // 返回结果
      }
    });

    ws.on('close', (code, reason) => {
      
      if (code !== 1000) {
            reject(new Error(`连接异常关闭,代码: ${code},原因: ${reason.toString()}`));
      }
    });

    ws.on('error', (error) => {
      console.error("WebSocket 错误:", error);
      reject(error);
    });
}

//湖北卫视-hbws
//湖北经视-hbjs
//湖北综合-hbzh
//湖北影视-hbys
//湖北教育-hbjy
//垄上频道-hbls

gethubei_liveinfo("hbls")


声明:代码均来自网络,代码仅仅用于学习交流,如有侵权,请联系删除!

iptver 发表于 2025-3-21 10:43:37

感谢大师, 应该是轮询不是轮训

deepseek 发表于 2025-3-21 12:35:15

世界那么大···

gbz2 发表于 2025-3-21 14:06:00

人生没有彩排,每天都是直播

Beryl 发表于 2025-3-21 14:45:26

猴赛雷!厉害

s.ice 发表于 2025-3-21 15:17:11

厉害。。。。。。

gbz2 发表于 2025-3-21 15:49:29

怎么用啊?

luguo 发表于 2025-3-21 18:36:24

太专业了根本看不懂怎么用

luguo 发表于 2025-3-21 18:40:52

脚本文件运行出错: ReferenceError,ReferenceError: 'main' is not defined at <eval>(湖北频道.js:145)

tongxunlu 发表于 2025-3-22 17:10:43

本帖最后由 tongxunlu 于 2025-3-22 17:11 编辑

有点像itouch的换壳,某网的websocket验证1分钟时效,每分钟获取新的就行了,不用理他什么ws轮询,反正也就1小时有效.至于这个湖北的不知道是不是一样的,楼主可以尝试,简单点能看就行了

datonnn 发表于 2025-3-22 17:12:28

谢谢楼主的分享

gbz2 发表于 2025-3-24 16:29:52

脚本文件运行出错: ReferenceError,ReferenceError: 'main' is not defined at <eval>
页: [1] 2
查看完整版本: 湖北长江云js代码