forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 4
/
youku.py
53 lines (44 loc) · 1.99 KB
/
youku.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
# 获取@优酷轮播台@的真实流媒体地址。
# 优酷轮播台是优酷直播live.youku.com下的一个子栏目,轮播一些经典电影电视剧,个人感觉要比其他直播平台影视区的画质要好,
# 而且没有平台水印和主播自己贴的乱七八糟的字幕遮挡。
# liveId 是如下形式直播间链接:
# “https://vku.youku.com/live/ilproom?spm=a2hcb.20025885.m_16249_c_59932.d_11&id=8019610&scm=20140670.rcmd.16249.live_8019610”中的8019610字段。
import requests
import time
import hashlib
import json
class YouKu:
def __init__(self, rid):
self.rid = rid
def get_real_url(self):
try:
tt = str(int(time.time() * 1000))
data = json.dumps({'liveId': self.rid, 'app': 'Pc'}, separators=(',', ':'))
url = 'https://acs.youku.com/h5/mtop.youku.live.com.livefullinfo/1.0/?appKey=24679788'
s = requests.Session()
cookies = s.get(url).cookies
token = requests.utils.dict_from_cookiejar(cookies).get('_m_h5_tk')[0:32]
sign = hashlib.md5((token + '&' + tt + '&' + '24679788' + '&' + data).encode('utf-8')).hexdigest()
params = {
't': tt,
'sign': sign,
'data': data
}
response = 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')
real_url = 'http://lvo-live.youku.com/vod2live/{}_mp4hd2v3.m3u8?&expire=21600&psid=1&ups_ts={}&vkey='.format(
streamname, int(time.time()))
except:
raise Exception('请求错误')
return real_url
def get_real_url(rid):
try:
yk = YouKu(rid)
return yk.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入优酷轮播台房间号:\n')
print(get_real_url(r))