From 7329d7cd6e958e11e934f1c6cee28e8d4f550847 Mon Sep 17 00:00:00 2001 From: i7az Date: Thu, 22 Sep 2022 01:54:19 +0800 Subject: [PATCH] douyu m3u8 --- douyu.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/douyu.py b/douyu.py index b2db890..11e7dec 100644 --- a/douyu.py +++ b/douyu.py @@ -3,7 +3,7 @@ import hashlib import re import time - +import json import execjs import requests @@ -79,13 +79,13 @@ def get_js(self): js = execjs.compile(func_sign) params = js.call('sign', self.rid, self.did, self.t10) - params += '&ver=219032101&rid={}&rate=-1'.format(self.rid) + params += '&ver=219032101&rid={}&rate=0'.format(self.rid) url = 'https://m.douyu.com/api/room/ratestream' res = self.s.post(url, params=params).text key = re.search(r'(\d{1,8}[0-9a-zA-Z]+)_?\d{0,4}(.m3u8|/playlist)', res).group(1) - return key + return res def get_pc_js(self, cdn='ws-h5', rate=0): """ @@ -129,9 +129,14 @@ def get_real_url(self): real_url = {} real_url["flv1"] = "http://akm-tct.douyucdn.cn/live/{}.flv?uuid=".format(key) real_url["flv2"] = "http://ws-tct.douyucdn.cn/live/{}.flv?uuid=".format(key) + try: + real_url["m3u8"] = json.loads(s.get_js())["data"]["url"] + except: + pass return real_url if __name__ == '__main__': r = input('输入斗鱼直播间号:\n') s = DouYu(r) print(s.get_real_url()) +