mirror of
https://github.com/wbt5/real-url.git
synced 2025-06-17 00:09:58 +08:00
🐛 Fix 酷狗繁星直播
-修复不同频道直播间无法获取的问题 -仅保留HLS格式直播流 -优化代码
This commit is contained in:
parent
a81a75fa8c
commit
58d4d88942
50
kugou.py
50
kugou.py
@ -6,17 +6,53 @@ 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:
|
||||
response1 = requests.get('https://fx1.service.kugou.com/video/pc/live/pull/v3/streamaddr?roomId={}&ch=fx&version=1.0&streamType=1-2-5&platform=7&ua=fx-flash&kugouId=0&layout=1'.format(self.rid)).json()
|
||||
response2 = requests.get('https://fx1.service.kugou.com/video/mo/live/pull/h5/v3/streamaddr?roomId={}&platform=18&version=1000&streamType=3-6&liveType=1&ch=fx&ua=fx-mobile-h5&kugouId=0&layout=1'.format(self.rid)).json()
|
||||
real_url_flv = response1.get('data').get('horizontal')[0].get('httpflv')[0]
|
||||
real_url_hls = response2.get('data').get('horizontal')[0].get('httpshls')[0]
|
||||
except:
|
||||
raise Exception('直播间不存在或未开播')
|
||||
return {"flv": real_url_flv, "hls": real_url_hls}
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user