距离上次抓取直播源已经过去一年了,最近发现官方已更新了,以前的方法并不适用了,于是再来一波解析,小伙伴们准备好发车了吗?
之前直播源解析是从H5版本入手,直接从H5页面拿到全局变量liveLineUrl
,这是一个m3u8的播放地址,可以用VLC等播放器直接播放;另发现 一起看
模块的直播源地址和一般房间不同,fm
参数已经变成了seqid
:
如今版本发现全局变量中的liveLineUrl
已经变成加密的了,类似 Ly9hbC5obHMuaHV5YS5jb20vc3JjLzE2Nzc5NDIzMzMtMTY3Nzk0MjMzMy03MjA2NzA3NDQ0ODA4OTQxNTY4LTMzNTYwMDgxMjItMTAwNTctQS0wLTEubTN1OD9yYXRpbz0yMDAwJndzU2VjcmV0PWVkZjE3ZmNkMTk0ZDY2ZTY4MjIxYjQ4NjIxMWZiNWEyJndzVGltZT02Mzc2MmJiNSZmbT1SRmR4T0VKalNqTm9Oa1JLZERaVVdWOGtNRjhrTVY4a01sOGtNdyUzRCUzRCZjdHlwZT10YXJzX21vYmlsZSZmcz1iZ2N0JnNwaGRjZG49YWxfNy10eF8zLWpzXzMtd3NfNy1iZF8yLWh3XzImc3BoZERDPWh1eWEmc3BoZD0yNjRfKi0yNjVfKiZleHNwaGQ9MjY0XzUwMCwmdD0xMDM=
,炸一看感觉很可怕,其实跟简单这个就是典型的 base64
加密,我们用 在线工具 解密一下,得到结果 //al.hls.****.com/src/1677942333-1677942333-7206707444808941568-3356008122-10057-A-0-1.m3u8?ratio=2000&wsSecret=edf17fcd194d66e68221b486211fb5a2&wsTime=63762bb5&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103
查看下真实的播放地址是:
对比发现m3u8格式变成了flv格式,这个其实不重要,官方支持多种直播源格式,但是里面有 seqid
参数,没有 fm
参数,其他的参数其实在全局变量都有(只保留了重要的数据):
{
"roomProfile": {
"lUid": 367138632,
"liveLineUrl": "Ly9hbC5obHMuaHV5YS5jb20vc3JjLzM2NzEzODYzMi0zNjcxMzg2MzItMTU3Njg0ODQxNzUzODE3OTA3Mi03MzQ0MDA3MjAtMTAwNTctQS0wLTEtaW1ncGx1cy5tM3U4P3JhdGlvPTIwMDAmd3NTZWNyZXQ9ZTY3NzBjZTEwNTc5ZDVkZmU3ZjAzNjM1MWRiMzgzMmYmd3NUaW1lPTYzNzYzODE4JmZtPVJGZHhPRUpqU2pOb05rUktkRFpVV1Y4a01GOGtNVjhrTWw4a013JTNEJTNEJmN0eXBlPXRhcnNfbW9iaWxlJmZzPWJnY3Qmc3BoZGNkbj1hbF83LXR4XzMtanNfMy13c183LWJkXzItaHdfMiZzcGhkREM9aHV5YSZzcGhkPTI2NF8qLTI2NV8qJmV4c3BoZD0yNjRfNTAwLCZ0PTEwMw=="
},
"roomInfo": {
"tLiveInfo": {
"tLiveStreamInfo": {
"vStreamInfo": {
"value": [
{
"sCdnType": "AL",
"iIsMaster": 0,
"lChannelId": 367138632,
"lSubChannelId": 367138632,
"lPresenterUid": 367138632,
"sStreamName": "367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus",
"sFlvUrl": "http://al.flv.****.com/src",
"sFlvUrlSuffix": "flv",
"sFlvAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"sHlsUrl": "http://al.hls.****.com/src",
"sHlsUrlSuffix": "m3u8",
"sHlsAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"iIsP2PSupport": 2,
"sP2pUrl": "http://al.p2p.****.com/****live",
"sP2pUrlSuffix": "slice",
"sP2pAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103"
},
{
"sCdnType": "TX",
"iIsMaster": 0,
"lChannelId": 367138632,
"lSubChannelId": 367138632,
"lPresenterUid": 367138632,
"sStreamName": "367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus",
"sFlvUrl": "http://tx.flv.****.com/src",
"sFlvUrlSuffix": "flv",
"sFlvAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"sHlsUrl": "http://tx.hls.****.com/src",
"sHlsUrlSuffix": "m3u8",
"sHlsAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"sP2pUrl": "http://tx.p2p.****.com/****live",
"sP2pUrlSuffix": "slice",
"sP2pAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103"
},
{
"sCdnType": "HW",
"iIsMaster": 0,
"lChannelId": 367138632,
"lSubChannelId": 367138632,
"lPresenterUid": 367138632,
"sStreamName": "367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus",
"sFlvUrl": "http://hw.flv.****.com/src",
"sFlvUrlSuffix": "flv",
"sFlvAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"sHlsUrl": "http://hw.hls.****.com/src",
"sHlsUrlSuffix": "m3u8",
"sHlsAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
"iIsP2PSupport": 2,
"sP2pUrl": "http://hw.p2p.****.com/****live",
"sP2pUrlSuffix": "slice",
"sP2pAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103"
}
]
},
"iDefaultLiveStreamBitRate": 2000,
"sDefaultLiveStreamLine": "AL",
"sDefaultLiveStreamSuffix": "m3u8",
"sDefaultLiveStreamUrl": "http://al.hls.****.com/src/367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus.m3u8?ratio=2000&wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103"
}
}
}
}
可以看到地址的参数基本都有了,也有很多默认的地址,但是都不能直接播放,不是真实的播放地址,也没有看到 seqid
参数,所以我们还是需要去找一下。
大致步骤:
搜索 getAnticode
相关的方法
getAnticode
方法进入加密方法,这个方法返回的参数里面包含了 seqid
,接下来就是找出各个加密方法和参数:
this[Qt]
是 fm
参数解密出来的,结果类似 DWq8BcJ3h6DJt6TY_$0_$1_$2_$3
:
this[ae]
是 sStreamName
this[zt]
是 wsTime
// 主方法
export function getUrl(sStreamName, wsTime, fm){
let uid = 2209349442; // uid 可固定
let ue = uid + 1668612439268; // Date.now(); 这里时间和wsTime等参数需要配套使用,这里做测试使用,正常是需要使用Date.now();
let s = Kt(""+ue+"|tars_mobile|103")
let r = uid
let n = parseFm(fm).replace("$0", r).replace("$1", sStreamName).replace("$2", s).replace("$3", wsTime);
let o = `wsSecret=${Kt(n)}&wsTime=${wsTime}&seqid=${ue}&ctype=tars_mobile&ver=1`;
let se = ["fs=bgct","sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2","sphdDC=****","sphd=264_*-265_*","t=103","exsphd=264_500,264_2000,"];
let res = sStreamName + ".flv?" + o + "&" + se.join('&')
return res;
}
// 以上用的加密方法
function parseFm(_fm){
let fm = decodeURI(_fm);
fm = unescape(fm);
return atob(fm)
}
function Kt(t){
return Bt(Ht(t))
}
function Bt(t) {
var e, i, s = "";
for (i = 0; i < t.length; i += 1)
e = t.charCodeAt(i),
s += "0123456789abcdef".charAt(e >>> 4 & 15) + "0123456789abcdef".charAt(15 & e);
return s
}
function Ht(t) {
return function(t) {
return Vt(Ft(xt(t), 8 * t.length))
}(Gt(t))
}
function Gt(t) {
return unescape(encodeURIComponent(t))
}
function Vt(t) {
var e, i = "", s = 32 * t.length;
for (e = 0; e < s; e += 8)
i += String.fromCharCode(t[e >> 5] >>> e % 32 & 255);
return i
}
function Ft(t, e) {
var i, s, r, n, a;
t[e >> 5] |= 128 << e % 32,
t[14 + (e + 64 >>> 9 << 4)] = e;
var o = 1732584193, h = -271733879 , u = -1732584194 , l = 271733878;
for (i = 0; i < t.length; i += 16)
s = o,
r = h,
n = u,
a = l,
o = Dt(o, h, u, l, t[i], 7, -680876936),
l = Dt(l, o, h, u, t[i + 1], 12, -389564586),
u = Dt(u, l, o, h, t[i + 2], 17, 606105819),
h = Dt(h, u, l, o, t[i + 3], 22, -1044525330),
o = Dt(o, h, u, l, t[i + 4], 7, -176418897),
l = Dt(l, o, h, u, t[i + 5], 12, 1200080426),
u = Dt(u, l, o, h, t[i + 6], 17, -1473231341),
h = Dt(h, u, l, o, t[i + 7], 22, -45705983),
o = Dt(o, h, u, l, t[i + 8], 7, 1770035416),
l = Dt(l, o, h, u, t[i + 9], 12, -1958414417),
u = Dt(u, l, o, h, t[i + 10], 17, -42063),
h = Dt(h, u, l, o, t[i + 11], 22, -1990404162),
o = Dt(o, h, u, l, t[i + 12], 7, 1804603682),
l = Dt(l, o, h, u, t[i + 13], 12, -40341101),
u = Dt(u, l, o, h, t[i + 14], 17, -1502002290),
o = bt(o, h = Dt(h, u, l, o, t[i + 15], 22, 1236535329), u, l, t[i + 1], 5, -165796510),
l = bt(l, o, h, u, t[i + 6], 9, -1069501632),
u = bt(u, l, o, h, t[i + 11], 14, 643717713),
h = bt(h, u, l, o, t[i], 20, -373897302),
o = bt(o, h, u, l, t[i + 5], 5, -701558691),
l = bt(l, o, h, u, t[i + 10], 9, 38016083),
u = bt(u, l, o, h, t[i + 15], 14, -660478335),
h = bt(h, u, l, o, t[i + 4], 20, -405537848),
o = bt(o, h, u, l, t[i + 9], 5, 568446438),
l = bt(l, o, h, u, t[i + 14], 9, -1019803690),
u = bt(u, l, o, h, t[i + 3], 14, -187363961),
h = bt(h, u, l, o, t[i + 8], 20, 1163531501),
o = bt(o, h, u, l, t[i + 13], 5, -1444681467),
l = bt(l, o, h, u, t[i + 2], 9, -51403784),
u = bt(u, l, o, h, t[i + 7], 14, 1735328473),
o = Nt(o, h = bt(h, u, l, o, t[i + 12], 20, -1926607734), u, l, t[i + 5], 4, -378558),
l = Nt(l, o, h, u, t[i + 8], 11, -2022574463),
u = Nt(u, l, o, h, t[i + 11], 16, 1839030562),
h = Nt(h, u, l, o, t[i + 14], 23, -35309556),
o = Nt(o, h, u, l, t[i + 1], 4, -1530992060),
l = Nt(l, o, h, u, t[i + 4], 11, 1272893353),
u = Nt(u, l, o, h, t[i + 7], 16, -155497632),
h = Nt(h, u, l, o, t[i + 10], 23, -1094730640),
o = Nt(o, h, u, l, t[i + 13], 4, 681279174),
l = Nt(l, o, h, u, t[i], 11, -358537222),
u = Nt(u, l, o, h, t[i + 3], 16, -722521979),
h = Nt(h, u, l, o, t[i + 6], 23, 76029189),
o = Nt(o, h, u, l, t[i + 9], 4, -640364487),
l = Nt(l, o, h, u, t[i + 12], 11, -421815835),
u = Nt(u, l, o, h, t[i + 15], 16, 530742520),
o = Mt(o, h = Nt(h, u, l, o, t[i + 2], 23, -995338651), u, l, t[i], 6, -198630844),
l = Mt(l, o, h, u, t[i + 7], 10, 1126891415),
u = Mt(u, l, o, h, t[i + 14], 15, -1416354905),
h = Mt(h, u, l, o, t[i + 5], 21, -57434055),
o = Mt(o, h, u, l, t[i + 12], 6, 1700485571),
l = Mt(l, o, h, u, t[i + 3], 10, -1894986606),
u = Mt(u, l, o, h, t[i + 10], 15, -1051523),
h = Mt(h, u, l, o, t[i + 1], 21, -2054922799),
o = Mt(o, h, u, l, t[i + 8], 6, 1873313359),
l = Mt(l, o, h, u, t[i + 15], 10, -30611744),
u = Mt(u, l, o, h, t[i + 6], 15, -1560198380),
h = Mt(h, u, l, o, t[i + 13], 21, 1309151649),
o = Mt(o, h, u, l, t[i + 4], 6, -145523070),
l = Mt(l, o, h, u, t[i + 11], 10, -1120210379),
u = Mt(u, l, o, h, t[i + 2], 15, 718787259),
h = Mt(h, u, l, o, t[i + 9], 21, -343485551),
o = Ut(o, s),
h = Ut(h, r),
u = Ut(u, n),
l = Ut(l, a);
return [o, h, u, l]
}
function xt(t) {
var e, i = [];
for (i[(t.length >> 2) - 1] = void 0,
e = 0; e < i.length; e += 1)
i[e] = 0;
var s = 8 * t.length;
for (e = 0; e < s; e += 8)
i[e >> 5] |= (255 & t.charCodeAt(e / 8)) << e % 32;
return i
}
function Ut(t, e) {
var i = (65535 & t) + (65535 & e);
return (t >> 16) + (e >> 16) + (i >> 16) << 16 | 65535 & i
}
function wt(t, e, i, s, r, n) {
return Ut((a = Ut(Ut(e, t), Ut(s, n))) << (o = r) | a >>> 32 - o, i);
var a, o
}
function Dt(t, e, i, s, r, n, a) {
return wt(e & i | ~e & s, t, e, r, n, a)
}
function bt(t, e, i, s, r, n, a) {
return wt(e & s | i & ~s, t, e, r, n, a)
}
function Nt(t, e, i, s, r, n, a) {
return wt(e ^ i ^ s, t, e, r, n, a)
}
function Mt(t, e, i, s, r, n, a) {
return wt(i ^ (e | ~s), t, e, r, n, a)
}
"sCdnType": "AL",
"sStreamName": "367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus",
"sFlvUrl": "http://al.flv.****.com/src",
"sFlvUrlSuffix": "flv",
"sFlvAntiCode": "wsSecret=e6770ce10579d5dfe7f036351db3832f&wsTime=63763818&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&exsphd=264_500,&t=103",
我们以 AL
这个源为例:
let sStreamName = "367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus"
let wsTime = "637652b0"
let fm = "RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D"
let url = 'https://al.flv.****.com/src/'+getUrl(sStreamName, wsTime , fm )+"&ratio=2000&uid=2209349442&uuid=805253282&t=103&sv=2110211124"
console.log(url)
"https://al.flv.****.com/src/367138632-367138632-1576848417538179072-734400720-10057-A-0-1-imgplus.flv?wsSecret=c3c8fad04a27af2cf36c8304a7914249&wsTime=637652b0&seqid=1670821788710&ctype=tars_mobile&ver=1&fs=bgct&sphdcdn=al_7-tx_3-js_3-ws_7-bd_2-hw_2&sphdDC=****&sphd=264_*-265_*&t=103&exsphd=264_500,264_2000,&ratio=2000&uid=2209349442&uuid=805253282&t=103&sv=2110211124"
因测试需要,getUrl
中的时间我根据请求的时间写死了,实际是需要根据请求页面返回的时间来算,wsTime
是与时间有关的;
直播源的对象在: HNF_GLOBAL_INIT.roomInfo.tLiveInfo.tLiveStreamInfo.vStreamInfo