]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pandatv.py
133cc9b884c656b9f1ab66c0af7f446cd68a7fbd
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
11 class PandaTVIE(InfoExtractor
):
13 _VALID_URL
= r
'http://(?:www\.)?panda\.tv/(?P<id>[0-9]+)'
15 'url': 'http://www.panda.tv/10091',
24 'skip_download': True,
26 'skip': 'Live stream is offline',
29 def _real_extract(self
, url
):
30 video_id
= self
._match
_id
(url
)
32 config
= self
._download
_json
(
33 'http://www.panda.tv/api_room?roomid=%s' % video_id
, video_id
)
35 error_code
= config
.get('errno', 0)
36 if error_code
is not 0:
38 '%s returned error %s: %s'
39 % (self
.IE_NAME
, error_code
, config
['errmsg']),
43 video_info
= data
['videoinfo']
45 # 2 = live, 3 = offline
46 if video_info
.get('status') != '2':
48 'Live stream is offline', expected
=True)
50 title
= data
['roominfo']['name']
51 uploader
= data
.get('hostinfo', {}).get('name')
52 room_key
= video_info
['room_key']
53 stream_addr
= video_info
.get(
54 'stream_addr', {'OD': '1', 'HD': '1', 'SD': '1'})
56 # Reverse engineered from web player swf
57 # (http://s6.pdim.gs/static/07153e425f581151.swf at the moment of
59 plflag0
, plflag1
= video_info
['plflag'].split('_')
60 plflag0
= int(plflag0
) - 1
64 live_panda
= 'live_panda' if plflag0
< 1 else ''
66 quality_key
= qualities(['OD', 'HD', 'SD'])
67 suffix
= ['_small', '_mid', '']
69 for k
, v
in stream_addr
.items():
72 quality
= quality_key(k
)
75 for pref
, (ext
, pl
) in enumerate((('m3u8', '-hls'), ('flv', ''))):
77 'url': 'http://pl%s%s.live.panda.tv/live_panda/%s%s%s.%s'
78 % (pl
, plflag1
, room_key
, live_panda
, suffix
[quality
], ext
),
79 'format_id': '%s-%s' % (k
, ext
),
81 'source_preference': pref
,
83 self
._sort
_formats
(formats
)
87 'title': self
._live
_title
(title
),