- if show_status == '2':
- raise ExtractorError(
- 'Live stream is offline', expected=True)
-
- base_url = data['rtmp_url']
- live_path = data['rtmp_live']
-
- title = self._live_title(unescapeHTML(data['room_name']))
- description = data.get('show_details')
- thumbnail = data.get('room_src')
-
- uploader = data.get('nickname')
- uploader_id = data.get('owner_uid')
-
- multi_formats = data.get('rtmp_multi_bitrate')
- if not isinstance(multi_formats, dict):
- multi_formats = {}
- multi_formats['live'] = live_path
-
- formats = [{
- 'url': '%s/%s' % (base_url, format_path),
- 'format_id': format_id,
- 'preference': 1 if format_id == 'live' else 0,
- } for format_id, format_path in multi_formats.items()]
- self._sort_formats(formats)
+ 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']
+
+ title = self._live_title(unescapeHTML(room['room_name']))
+ description = room.get('show_details')
+ thumbnail = room.get('room_src')
+ uploader = room.get('nickname')