forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbs.py
85 lines (74 loc) · 2.59 KB
/
kbs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
# @Time: 2021/5/22 8:02
# @Project: real-url
# @Author: wbt5
# @Blog: https://wbt5.com
import hashlib
import time
from urllib.parse import parse_qsl, urlsplit
import requests
class KBS:
"""
- 腾讯体育直播,看比赛频道 https://kbs.sports.qq.com/
- 直播间地址类似:https://sports.qq.com/kbsweb/game.htm?mid=100006:2337840,需要其中的mid
- 只能获取免费观看的直播间
- 请求参数params中的defn:蓝光fhd、超清shd、高清hd、标清sd,未登陆时最高获取超清,蓝光需VIP。
"""
def __init__(self, rid):
var = dict(parse_qsl(urlsplit(rid).query))
mid = var.get('mid')
with requests.Session() as self.s:
res = requests.get(f'https://matchweb.sports.qq.com/kbs/matchDetail?mid={mid}').json()
self.vid = res['data']['liveId']
self.livepid = res['data']['programId']
def get_real_url(self):
tt = int(time.time())
week = int(time.strftime('%w'))
s = ('06fc1464', '4244ce1b', '77de31c5', 'e0149fa2', '60394ced', '2da639f0', 'c2f0cf9f')
ha = f'{s[week - 1]}{self.vid}{tt}*#06#40201'
ckey = hashlib.md5(ha.encode('utf-8')).hexdigest()
params = {
'cmd': 2,
'cnlid': self.vid,
'pla': 0,
'stream': 2,
'system': 0,
'appVer': '3.0.0.142',
'encryptVer': f'7.{7 if week == 0 else week}',
'qq': 0,
'device': 'PC',
'guid': 'f56776a1fa52e9c8c4987bfecfbf0503',
'defn': 'shd', # shd默认超清
'host': 'qq.com',
'livepid': self.livepid,
'logintype': 1,
'vip_status': 1,
'livequeue': 1,
'fntick': tt,
'tm': tt,
'sdtfrom': 1107,
'platform': 40201,
'cKey': ckey,
'queueStatus': 0,
'sphttps': 1,
'authext': '{}',
'auth_ext': '{}',
'auth_from': 40001,
# 'callback': 'txvlive_videoinfoget_2767135792',
}
res = self.s.get('https://infozb6.video.qq.com/', params=params).json()
playurl = res.get('playurl', 0)
if res['errinfo']:
raise Exception('errinfo')
else:
return playurl
def get_real_url(rid):
try:
kbs = KBS(rid)
return kbs.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入腾讯体育直播间地址:\n')
print(get_real_url(r))