mirror of
https://github.com/wbt5/real-url.git
synced 2025-07-24 17:41:45 +08:00
⚡ Improve 优酷轮播台
-优化代码
This commit is contained in:
parent
7a0320b762
commit
3d0b32c531
22
youku.py
22
youku.py
@ -13,28 +13,32 @@ import json
|
|||||||
class YouKu:
|
class YouKu:
|
||||||
|
|
||||||
def __init__(self, rid):
|
def __init__(self, rid):
|
||||||
|
"""
|
||||||
|
获取优酷轮播台的流媒体地址
|
||||||
|
Args:
|
||||||
|
rid: 直播间url中id=8019610,其中id即为房间号
|
||||||
|
"""
|
||||||
self.rid = rid
|
self.rid = rid
|
||||||
|
self.s = requests.Session()
|
||||||
|
|
||||||
def get_real_url(self):
|
def get_real_url(self):
|
||||||
try:
|
try:
|
||||||
tt = str(int(time.time() * 1000))
|
tt = str(int(time.time() * 1000))
|
||||||
data = json.dumps({'liveId': self.rid, 'app': 'Pc'}, separators=(',', ':'))
|
data = json.dumps({'liveId': self.rid, 'app': 'Pc'}, separators=(',', ':'))
|
||||||
url = 'https://acs.youku.com/h5/mtop.youku.live.com.livefullinfo/1.0/?appKey=24679788'
|
url = 'https://acs.youku.com/h5/mtop.youku.live.com.livefullinfo/1.0/?appKey=24679788'
|
||||||
s = requests.Session()
|
cookies = self.s.get(url).cookies
|
||||||
cookies = s.get(url).cookies
|
token = cookies.get_dict().get('_m_h5_tk')[0:32]
|
||||||
token = requests.utils.dict_from_cookiejar(cookies).get('_m_h5_tk')[0:32]
|
sign = hashlib.md5(f'{token}&{tt}&24679788&{data}'.encode('utf-8')).hexdigest()
|
||||||
sign = hashlib.md5((token + '&' + tt + '&' + '24679788' + '&' + data).encode('utf-8')).hexdigest()
|
|
||||||
params = {
|
params = {
|
||||||
't': tt,
|
't': tt,
|
||||||
'sign': sign,
|
'sign': sign,
|
||||||
'data': data
|
'data': data
|
||||||
}
|
}
|
||||||
response = s.get(url, params=params).json()
|
response = self.s.get(url, params=params).json()
|
||||||
# name = response.get('data').get('data').get('name')
|
|
||||||
streamname = response.get('data').get('data').get('stream')[0].get('streamName')
|
streamname = response.get('data').get('data').get('stream')[0].get('streamName')
|
||||||
real_url = 'http://lvo-live.youku.com/vod2live/{}_mp4hd2v3.m3u8?&expire=21600&psid=1&ups_ts={}&vkey='.format(
|
real_url = f'https://lvo-live.youku.com/vod2live/{streamname}_mp4hd2v3.m3u8?&expire=21600&psid=1&ups_ts=' \
|
||||||
streamname, int(time.time()))
|
f'{int(time.time())}&vkey= '
|
||||||
except:
|
except Exception:
|
||||||
raise Exception('请求错误')
|
raise Exception('请求错误')
|
||||||
return real_url
|
return real_url
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user