找回密码
 注册需QQ邮箱验证
搜索
查看: 705|回复: 13

湖北长江云js代码

[复制链接]

签到天数: 9 天

[LV.3]圆转纯熟

发表于 2025-3-21 10:32:13 | 显示全部楼层 |阅读模式
本帖最后由 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[1]
        const output = jsonString.replace(/^\s*\/\/.*$/gm, '');
        const matches = [...output.matchAll(/stream:\s*"([^"]+)"/g)].map(match => match[1]);

        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")


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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册需QQ邮箱验证

×

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 443 天

[LV.9]已臻大成

发表于 2025-3-21 10:43:37 | 显示全部楼层

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 17 天

[LV.4]初窥堂奥

发表于 2025-3-21 12:35:15 | 显示全部楼层
世界那么大···

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 115 天

[LV.6]渐入佳境

发表于 2025-3-21 14:06:00 | 显示全部楼层
人生没有彩排,每天都是直播

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 140 天

[LV.7]炉火纯青

发表于 2025-3-21 14:45:26 | 显示全部楼层
猴赛雷!厉害

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 30 天

[LV.5]略有小成

发表于 2025-3-21 15:17:11 | 显示全部楼层
厉害。。。。。。

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 115 天

[LV.6]渐入佳境

发表于 2025-3-21 15:49:29 | 显示全部楼层
怎么用啊?

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 73 天

[LV.6]渐入佳境

发表于 2025-3-21 18:36:24 | 显示全部楼层
太专业了根本看不懂怎么用

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 73 天

[LV.6]渐入佳境

发表于 2025-3-21 18:40:52 | 显示全部楼层
脚本文件运行出错: ReferenceError,ReferenceError: 'main' is not defined at <eval>(湖北频道.js:145)

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 2 天

[LV.1]初学乍练

发表于 2025-3-22 17:10:43 | 显示全部楼层
本帖最后由 tongxunlu 于 2025-3-22 17:11 编辑

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

点评

每分钟=频繁,weigui  发表于 2025-3-22 19:56

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 48 天

[LV.5]略有小成

发表于 2025-3-22 17:12:28 | 显示全部楼层
谢谢楼主的分享

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

Welcome to iptv.cc !

回复

使用道具 举报

签到天数: 115 天

[LV.6]渐入佳境

发表于 2025-3-24 16:29:52 | 显示全部楼层
脚本文件运行出错: ReferenceError,ReferenceError: 'main' is not defined at <eval>

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

Welcome to iptv.cc !

回复

使用道具 举报

本版积分规则

Archiver|手机版|小黑屋|IPTV论坛 | 管理员邮箱:a@8494.net

本站以兴趣爱好为宗旨,非经营性质,不以任何形式收取任何费用。IPTV论坛没有任何官方Q群,V群,T群,禁止留任何联系方式,请配合。

免责声明:本站上述内容来自网络,不得用于商业或非法用途,您必须在下载后24小时内,从设备中删除,否则后果自负。如内容侵犯您的版权、著作权,请联系我,第一时间处理。

GMT+8, 2025-5-9 15:01 , Processed in 0.107527 second(s), 19 queries .

IPTV论坛 创建于 2023年5月1日