-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
kugou.py
69 lines (60 loc) · 2.27 KB
/
kugou.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
# 获取酷狗繁星直播的真实流媒体地址,默认最高码率。
import requests
class KuGou:
def __init__(self, rid):
"""
酷狗繁星直播
Args:
rid: 房间号
"""
self.rid = rid
self.s = requests.Session()
self.BASE_URL = 'https://fx1.service.kugou.com/video/mo/live/pull/h5/v3/streamaddr'
def get_real_url(self):
params = {
'roomId': self.rid,
'platform': 18,
'version': 1000,
'streamType': '3-6',
'liveType': 1,
'ch': 'fx',
'ua': 'fx-mobile-h5',
'kugouId': 0,
'layout': 1
}
try:
res = self.s.get(self.BASE_URL, params=params).json()
if res['code'] == 1:
raise Exception(f'{res["msg"]},可能是房间号输入错误!')
real_url_hls = res.get('data').get('horizontal')[0].get('httpshls')[0]
except IndexError:
try:
url = f'https://fx1.service.kugou.com/biz/ChannelVServices/' \
f'RoomLiveService.RoomLiveService.getCurrentLiveStarForMob/{self.rid}'
res = self.s.get(url).json()
if res['code'] == 1:
raise Exception(f'{res["msg"]},可能是房间号输入错误!')
roomid = res['data']['roomId']
self.BASE_URL = 'https://fx2.service.kugou.com/video/pc/live/pull/mutiline/streamaddr'
params = {
'std_rid': roomid,
'version': '1.0',
'streamType': '1-2-3-5-6',
'targetLiveTypes': '1-4-5-6',
'ua': 'fx-h5'
}
res = self.s.get(self.BASE_URL, params=params).json()
real_url_hls = res.get('data').get('lines')[-1].get('streamProfiles')[-1]['httpsHls'][-1]
except Exception:
raise Exception('未找到')
return real_url_hls
def get_real_url(rid):
try:
kg = KuGou(rid)
return kg.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入酷狗直播房间号:\n')
print(get_real_url(r))