Fix douyu

Took @yan12125 's advice, and thanks to @yan12125 .
This fix closes #580
This commit is contained in:
BuildTools 2015-09-07 11:10:38 +08:00 committed by Mort Yao
parent 8e53ba72af
commit eb141c1908

View File

@ -4,14 +4,24 @@ __all__ = ['douyutv_download']
from ..common import *
import json
import hashlib
import time
def douyutv_download(url, output_dir = '.', merge = True, info_only = False, **kwargs):
room_id = url[url.rfind('/')+1:]
content = get_html("http://www.douyutv.com/api/client/room/"+room_id)
#Thanks to @yan12125 for providing decoding method!!
suffix = 'room/%s?aid=android&client_sys=android&time=%d' % (room_id, int(time.time()))
sign = hashlib.md5((suffix + '1231').encode('ascii')).hexdigest()
json_request_url = "http://www.douyutv.com/api/v1/%s&auth=%s" % (suffix, sign)
content = get_html(json_request_url)
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)
title = data.get('room_name')
show_status = data.get('show_status')
if show_status is not "1":
raise ValueError("The live stream is not online! (Errno:%s)" % server_status)
real_url = data.get('rtmp_url')+'/'+data.get('rtmp_live')
print_info(site_info, title, 'flv', float('inf'))