]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pandatv.py
c86d7077127e2da252bd90db257bc152aa18e166
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?roomid=%s' % video_id
, video_id
)
38 error_code
= config
.get('errno', 0)
39 if error_code
is not 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 quality_key
= qualities(['OD', 'HD', 'SD'])
70 suffix
= ['_small', '_mid', '']
72 for k
, v
in stream_addr
.items():
75 quality
= quality_key(k
)
78 for pref
, (ext
, pl
) in enumerate((('m3u8', '-hls'), ('flv', ''))):
80 'url': 'https://pl%s%s.live.panda.tv/live_panda/%s%s%s.%s'
81 % (pl
, plflag1
, room_key
, live_panda
, suffix
[quality
], ext
),
82 'format_id': '%s-%s' % (k
, ext
),
84 'source_preference': pref
,
86 self
._sort
_formats
(formats
)
90 'title': self
._live
_title
(title
),