steven7851 2017-03-05 20:17:46 +08:00 committed by GitHub
parent 6c87cbde10
commit bea95ed3d3

View File

@ -6,8 +6,6 @@ from ..common import *
import json
import hashlib
import time
import uuid
import urllib.parse, urllib.request
def douyutv_download(url, output_dir = '.', merge = True, info_only = False, **kwargs):
html = get_content(url)
@ -28,24 +26,19 @@ def douyutv_download(url, output_dir = '.', merge = True, info_only = False, **k
if show_status is not "1":
raise ValueError("The live stream is not online! (Errno:%s)" % server_status)
tt = int(time.time() / 60)
did = uuid.uuid4().hex.upper()
sign_content = '{room_id}{did}A12Svb&%1UUmf@hC{tt}'.format(room_id = room_id, did = did, tt = tt)
sign = hashlib.md5(sign_content.encode('utf-8')).hexdigest()
tt = int(time.time())
sign_content = 'lapi/live/thirdPart/getPlay/%s?aid=pcclient&rate=0&time=%s9TUk5fjjUjg9qIMH3sdnh' % (room_id, tt)
sign = hashlib.md5(sign_content.encode('ascii')).hexdigest()
json_request_url = "http://www.douyu.com/lapi/live/getPlay/%s" % room_id
payload = {'cdn': 'ws', 'rate': '0', 'tt': tt, 'did': did, 'sign': sign}
postdata = urllib.parse.urlencode(payload)
req = urllib.request.Request(json_request_url, postdata.encode('utf-8'))
with urllib.request.urlopen(req) as response:
content = response.read()
data = json.loads(content.decode('utf-8'))['data']
json_request_url = "http://coapi.douyucdn.cn/lapi/live/thirdPart/getPlay/%s?rate=0" % room_id
headers = {'auth': sign, 'time': str(tt), 'aid': 'pcclient'}
content = get_content(json_request_url, headers = headers)
data = json.loads(content)['data']
server_status = data.get('error',0)
if server_status is not 0:
raise ValueError("Server returned error:%s" % server_status)
real_url = data.get('rtmp_url')+'/'+data.get('rtmp_live')
real_url = data.get('live_url')
print_info(site_info, title, 'flv', float('inf'))
if not info_only: