1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-07-27 19:10:32 +08:00

新增AcFun直播

This commit is contained in:
wbt5 2020-08-09 11:05:07 +08:00
parent acfa09c0b6
commit dbb54c8e89

45
acfun.py Normal file
View File

@ -0,0 +1,45 @@
# AcFun直播https://live.acfun.cn/
# 默认最高画质
import requests
import json
def acfun(rid):
headers = {
'content-type': 'application/x-www-form-urlencoded',
'cookie': '_did=H5_',
'referer': 'https://m.acfun.cn/'
}
url = 'https://id.app.acfun.cn/rest/app/visitor/login'
data = 'sid=acfun.api.visitor'
with requests.Session() as s:
res = s.post(url, data=data, headers=headers).json()
userid = res['userId']
visitor_st = res['acfun.api.visitor_st']
url = 'https://api.kuaishouzt.com/rest/zt/live/web/startPlay'
params = {
'subBiz': 'mainApp',
'kpn': 'ACFUN_APP',
'kpf': 'PC_WEB',
'userId': userid,
'did': 'H5_',
'acfun.api.visitor_st': visitor_st
}
data = 'authorId={}&pullStreamType=FLV'.format(rid)
res = s.post(url, params=params, data=data, headers=headers).json()
if res['result'] == 1:
data = res['data']
videoplayres = json.loads(data['videoPlayRes'])
liveadaptivemanifest, = videoplayres['liveAdaptiveManifest']
adaptationset = liveadaptivemanifest['adaptationSet']
representation = adaptationset['representation'][-1]
real_url = representation['url']
return real_url
else:
raise Exception('直播已关闭')
if __name__ == '__main__':
r = input('输入AcFun直播间号\n')
print(acfun(r))