1
0
mirror of https://github.com/wbt5/real-url.git synced 2026-03-23 00:46:56 +08:00
zhibo-url/kuaishou.py
2019-12-31 22:40:37 +08:00

29 lines
948 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 获取快手直播的真实流媒体地址,默认输出最高画质
# 2019年12月31日更新headers中需要添加cookie失效更换
import requests
import json
import re
def get_real_url(rid):
try:
url = 'https://live.kuaishou.com/u/' + str(rid)
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
'cookie': 'did=web_8ad78a7e9b64441293b9f53788a41109'
}
response = requests.get(url, headers=headers).text
pattern = r'{"liveStream":{"type":"json","json":{"liveStreamId":.*"playUrls":(.*),"coverUrl":'
real_url = json.loads(re.findall(pattern, response)[0])[0]
except:
real_url = '该直播间不存在或未开播'
return real_url
rid = input('请输入快手直播间ID\n')
real_url = get_real_url(rid)
print('该直播源地址为:')
print(real_url)