From 96efd75ad1b549a5e6e0cf4225d81963f92183af Mon Sep 17 00:00:00 2001 From: hcwhan Date: Tue, 31 Oct 2017 15:34:13 +0800 Subject: [PATCH 1/2] Update douyutv API --- youtube_dl/extractor/douyutv.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/youtube_dl/extractor/douyutv.py b/youtube_dl/extractor/douyutv.py index 9757f4422..9f7ec4264 100644 --- a/youtube_dl/extractor/douyutv.py +++ b/youtube_dl/extractor/douyutv.py @@ -82,29 +82,22 @@ class DouyuTVIE(InfoExtractor): room_id = self._html_search_regex( r'"room_id\\?"\s*:\s*(\d+),', page, 'room id') - # Grab metadata from mobile API - room = self._download_json( - 'http://m.douyu.com/html5/live?roomId=%s' % room_id, video_id, + # Grab metadata from PC client API + api_url = "http://www.douyutv.com/api/v1/" + args = "room/%s?aid=wp&client_sys=wp&time=%d" % (room_id, int(time.time())) + auth_md5 = (args + "zNzMV1y4EMxOHS6I5WKm").encode("utf-8") + auth_str = hashlib.md5(auth_md5).hexdigest() + json_request_url = "%s%s&auth=%s" % (api_url, args, auth_str) + + room = self._download_json(json_request_url, video_id, note='Downloading room info')['data'] # 1 = live, 2 = offline if room.get('show_status') == '2': raise ExtractorError('Live stream is offline', expected=True) - # Grab the URL from PC client API # The m3u8 url from mobile API requires re-authentication every 5 minutes - tt = int(time.time()) - signContent = 'lapi/live/thirdPart/getPlay/%s?aid=pcclient&rate=0&time=%d9TUk5fjjUjg9qIMH3sdnh' % (room_id, tt) - sign = hashlib.md5(signContent.encode('ascii')).hexdigest() - video_url = self._download_json( - 'http://coapi.douyucdn.cn/lapi/live/thirdPart/getPlay/' + room_id, - video_id, note='Downloading video URL info', - query={'rate': 0}, headers={ - 'auth': sign, - 'time': str(tt), - 'aid': 'pcclient' - })['data']['live_url'] - + video_url = room.get('rtmp_url') + '/' + room.get('rtmp_live') title = self._live_title(unescapeHTML(room['room_name'])) description = room.get('show_details') thumbnail = room.get('room_src') From e4312bf80695e6d2d23de11d47acacff60b9f67a Mon Sep 17 00:00:00 2001 From: hcwhan Date: Tue, 31 Oct 2017 15:40:24 +0800 Subject: [PATCH 2/2] Update pandatv API add auth --- youtube_dl/extractor/pandatv.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/pandatv.py b/youtube_dl/extractor/pandatv.py index c86d70771..4527decee 100644 --- a/youtube_dl/extractor/pandatv.py +++ b/youtube_dl/extractor/pandatv.py @@ -6,7 +6,7 @@ from ..utils import ( ExtractorError, qualities, ) - +import json class PandaTVIE(InfoExtractor): IE_DESC = '熊猫TV' @@ -33,7 +33,7 @@ class PandaTVIE(InfoExtractor): video_id = self._match_id(url) config = self._download_json( - 'https://www.panda.tv/api_room?roomid=%s' % video_id, video_id) + 'https://www.panda.tv/api_room_v2?roomid=%s' % video_id, video_id) error_code = config.get('errno', 0) if error_code is not 0: @@ -66,6 +66,11 @@ class PandaTVIE(InfoExtractor): plflag1 = '4' live_panda = 'live_panda' if plflag0 < 1 else '' + plflag_auth = json.loads(video_info["plflag_list"]) + sign = plflag_auth["auth"]["sign"] + ts = plflag_auth["auth"]["time"] + rid = plflag_auth["auth"]["rid"] + quality_key = qualities(['OD', 'HD', 'SD']) suffix = ['_small', '_mid', ''] formats = [] @@ -77,8 +82,8 @@ class PandaTVIE(InfoExtractor): continue for pref, (ext, pl) in enumerate((('m3u8', '-hls'), ('flv', ''))): formats.append({ - 'url': 'https://pl%s%s.live.panda.tv/live_panda/%s%s%s.%s' - % (pl, plflag1, room_key, live_panda, suffix[quality], ext), + 'url': 'https://pl%s%s.live.panda.tv/live_panda/%s%s%s.%s?sign=%s&ts=%s&rid=%s' + % (pl, plflag1, room_key, live_panda, suffix[quality], ext, sign, ts, rid), 'format_id': '%s-%s' % (k, ext), 'quality': quality, 'source_preference': pref,