2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 from ..compat
import compat_urllib_parse_urlencode
17 class VLiveIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
21 'url': 'http://www.vlive.tv/video/1326',
22 'md5': 'cc7314812855ce56de70a06a27314983',
26 'title': "[V LIVE] Girl's Day's Broadcast",
27 'creator': "Girl's Day",
31 'url': 'http://www.vlive.tv/video/16937',
35 'title': '[V LIVE] 첸백시 걍방',
38 'subtitles': 'mincount:12',
41 'skip_download': True,
45 def _real_extract(self
, url
):
46 video_id
= self
._match
_id
(url
)
48 webpage
= self
._download
_webpage
(
49 'http://www.vlive.tv/video/%s' % video_id
, video_id
)
51 video_params
= self
._search
_regex
(
52 r
'\bvlive\.video\.init\(([^)]+)\)',
53 webpage
, 'video params')
54 status
, _
, _
, live_params
, long_video_id
, key
= re
.split(
55 r
'"\s*,\s*"', video_params
)[2:8]
56 status
= remove_start(status
, 'PRODUCT_')
58 if status
== 'LIVE_ON_AIR' or status
== 'BIG_EVENT_ON_AIR':
59 live_params
= self
._parse
_json
('"%s"' % live_params
, video_id
)
60 live_params
= self
._parse
_json
(live_params
, video_id
)
61 return self
._live
(video_id
, webpage
, live_params
)
62 elif status
== 'VOD_ON_AIR' or status
== 'BIG_EVENT_INTRO':
63 if long_video_id
and key
:
64 return self
._replay
(video_id
, webpage
, long_video_id
, key
)
66 status
= 'COMING_SOON'
68 if status
== 'LIVE_END':
69 raise ExtractorError('Uploading for replay. Please wait...',
71 elif status
== 'COMING_SOON':
72 raise ExtractorError('Coming soon!', expected
=True)
73 elif status
== 'CANCELED':
74 raise ExtractorError('We are sorry, '
75 'but the live broadcast has been canceled.',
78 raise ExtractorError('Unknown status %s' % status
)
80 def _get_common_fields(self
, webpage
):
81 title
= self
._og
_search
_title
(webpage
)
82 creator
= self
._html
_search
_regex
(
83 r
'<div[^>]+class="info_area"[^>]*>\s*<a\s+[^>]*>([^<]+)',
84 webpage
, 'creator', fatal
=False)
85 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
89 'thumbnail': thumbnail
,
92 def _live(self
, video_id
, webpage
, live_params
):
94 for vid
in live_params
.get('resolutions', []):
95 formats
.extend(self
._extract
_m
3u8_formats
(
96 vid
['cdnUrl'], video_id
, 'mp4',
97 m3u8_id
=vid
.get('name'),
98 fatal
=False, live
=True))
99 self
._sort
_formats
(formats
)
101 return dict(self
._get
_common
_fields
(webpage
),
106 def _replay(self
, video_id
, webpage
, long_video_id
, key
):
107 playinfo
= self
._download
_json
(
108 'http://global.apis.naver.com/rmcnmv/rmcnmv/vod_play_videoInfo.json?%s'
109 % compat_urllib_parse_urlencode({
110 'videoId': long_video_id
,
113 'doct': 'json', # document type (xml or json)
114 'cpt': 'vtt', # captions type (vtt or ttml)
118 'url': vid
['source'],
119 'format_id': vid
.get('encodingOption', {}).get('name'),
120 'abr': float_or_none(vid
.get('bitrate', {}).get('audio')),
121 'vbr': float_or_none(vid
.get('bitrate', {}).get('video')),
122 'width': int_or_none(vid
.get('encodingOption', {}).get('width')),
123 'height': int_or_none(vid
.get('encodingOption', {}).get('height')),
124 'filesize': int_or_none(vid
.get('size')),
125 } for vid
in playinfo
.get('videos', {}).get('list', []) if vid
.get('source')]
126 self
._sort
_formats
(formats
)
128 view_count
= int_or_none(playinfo
.get('meta', {}).get('count'))
131 for caption
in playinfo
.get('captions', {}).get('list', []):
132 lang
= dict_get(caption
, ('locale', 'language', 'country', 'label'))
133 if lang
and caption
.get('source'):
136 'url': caption
['source']}]
138 return dict(self
._get
_common
_fields
(webpage
),
141 view_count
=view_count
,