2 from __future__ import unicode_literals
4 from .common import InfoExtractor
11 class PandaTVIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?panda\.tv/(?P<id>[0-9]+)'
15 'url': 'http://www.panda.tv/66666',
24 'skip_download': True,
26 'skip': 'Live stream is offline',
28 'url': 'https://www.panda.tv/66666',
29 'only_matching': True,
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
35 config = self._download_json(
36 'https://www.panda.tv/api_room_v2?roomid=%s' % video_id, video_id)
38 error_code = config.get('errno', 0)
41 '%s returned error %s: %s'
42 % (self.IE_NAME, error_code, config['errmsg']),
46 video_info = data['videoinfo']
48 # 2 = live, 3 = offline
49 if video_info.get('status') != '2':
51 'Live stream is offline', expected=True)
53 title = data['roominfo']['name']
54 uploader = data.get('hostinfo', {}).get('name')
55 room_key = video_info['room_key']
56 stream_addr = video_info.get(
57 'stream_addr', {'OD': '1', 'HD': '1', 'SD': '1'})
59 # Reverse engineered from web player swf
60 # (http://s6.pdim.gs/static/07153e425f581151.swf at the moment of
62 plflag0, plflag1 = video_info['plflag'].split('_')
63 plflag0 = int(plflag0) - 1
67 live_panda = 'live_panda' if plflag0 < 1 else ''
69 plflag_auth = self._parse_json(video_info['plflag_list'], video_id)
70 sign = plflag_auth['auth']['sign']
71 ts = plflag_auth['auth']['time']
72 rid = plflag_auth['auth']['rid']
74 quality_key = qualities(['OD', 'HD', 'SD'])
75 suffix = ['_small', '_mid', '']
77 for k, v in stream_addr.items():
80 quality = quality_key(k)
83 for pref, (ext, pl) in enumerate((('m3u8', '-hls'), ('flv', ''))):
85 'url': 'https://pl%s%s.live.panda.tv/live_panda/%s%s%s.%s?sign=%s&ts=%s&rid=%s'
86 % (pl, plflag1, room_key, live_panda, suffix[quality], ext, sign, ts, rid),
87 'format_id': '%s-%s' % (k, ext),
89 'source_preference': pref,
91 self._sort_formats(formats)
95 'title': self._live_title(title),