2 from __future__ import unicode_literals
8 from .common import InfoExtractor
17 from ..compat import compat_urllib_parse_urlencode
20 class VLiveIE(InfoExtractor):
22 _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
24 'url': 'http://www.vlive.tv/video/1326',
25 'md5': 'cc7314812855ce56de70a06a27314983',
29 'title': "[V LIVE] Girl's Day's Broadcast",
30 'creator': "Girl's Day",
34 'url': 'http://www.vlive.tv/video/16937',
38 'title': '[V LIVE] 첸백시 걍방',
41 'subtitles': 'mincount:12',
44 'skip_download': True,
48 def _real_extract(self, url):
49 video_id = self._match_id(url)
51 webpage = self._download_webpage(
52 'http://www.vlive.tv/video/%s' % video_id, video_id)
54 VIDEO_PARAMS_RE = r'\bvlive\.video\.init\(([^)]+)'
55 VIDEO_PARAMS_FIELD = 'video params'
57 params = self._parse_json(self._search_regex(
58 VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD, default=''), video_id,
59 transform_source=lambda s: '[' + s + ']', fatal=False)
61 if not params or len(params) < 7:
62 params = self._search_regex(
63 VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD)
64 params = [p.strip(r'"') for p in re.split(r'\s*,\s*', params)]
66 status, long_video_id, key = params[2], params[5], params[6]
67 status = remove_start(status, 'PRODUCT_')
69 if status == 'LIVE_ON_AIR' or status == 'BIG_EVENT_ON_AIR':
70 return self._live(video_id, webpage)
71 elif status == 'VOD_ON_AIR' or status == 'BIG_EVENT_INTRO':
72 if long_video_id and key:
73 return self._replay(video_id, webpage, long_video_id, key)
75 status = 'COMING_SOON'
77 if status == 'LIVE_END':
78 raise ExtractorError('Uploading for replay. Please wait...',
80 elif status == 'COMING_SOON':
81 raise ExtractorError('Coming soon!', expected=True)
82 elif status == 'CANCELED':
83 raise ExtractorError('We are sorry, '
84 'but the live broadcast has been canceled.',
87 raise ExtractorError('Unknown status %s' % status)
89 def _get_common_fields(self, webpage):
90 title = self._og_search_title(webpage)
91 creator = self._html_search_regex(
92 r'<div[^>]+class="info_area"[^>]*>\s*<a\s+[^>]*>([^<]+)',
93 webpage, 'creator', fatal=False)
94 thumbnail = self._og_search_thumbnail(webpage)
98 'thumbnail': thumbnail,
101 def _live(self, video_id, webpage):
102 init_page = self._download_webpage(
103 'http://www.vlive.tv/video/init/view',
104 video_id, note='Downloading live webpage',
105 data=urlencode_postdata({'videoSeq': video_id}),
107 'Referer': 'http://www.vlive.tv/video/%s' % video_id,
108 'Content-Type': 'application/x-www-form-urlencoded'
111 live_params = self._search_regex(
112 r'"liveStreamInfo"\s*:\s*(".*"),',
113 init_page, 'live stream info')
114 live_params = self._parse_json(live_params, video_id)
115 live_params = self._parse_json(live_params, video_id)
118 for vid in live_params.get('resolutions', []):
119 formats.extend(self._extract_m3u8_formats(
120 vid['cdnUrl'], video_id, 'mp4',
121 m3u8_id=vid.get('name'),
122 fatal=False, live=True))
123 self._sort_formats(formats)
125 info = self._get_common_fields(webpage)
127 'title': self._live_title(info['title']),
134 def _replay(self, video_id, webpage, long_video_id, key):
135 playinfo = self._download_json(
136 'http://global.apis.naver.com/rmcnmv/rmcnmv/vod_play_videoInfo.json?%s'
137 % compat_urllib_parse_urlencode({
138 'videoId': long_video_id,
141 'doct': 'json', # document type (xml or json)
142 'cpt': 'vtt', # captions type (vtt or ttml)
146 'url': vid['source'],
147 'format_id': vid.get('encodingOption', {}).get('name'),
148 'abr': float_or_none(vid.get('bitrate', {}).get('audio')),
149 'vbr': float_or_none(vid.get('bitrate', {}).get('video')),
150 'width': int_or_none(vid.get('encodingOption', {}).get('width')),
151 'height': int_or_none(vid.get('encodingOption', {}).get('height')),
152 'filesize': int_or_none(vid.get('size')),
153 } for vid in playinfo.get('videos', {}).get('list', []) if vid.get('source')]
154 self._sort_formats(formats)
156 view_count = int_or_none(playinfo.get('meta', {}).get('count'))
159 for caption in playinfo.get('captions', {}).get('list', []):
160 lang = dict_get(caption, ('locale', 'language', 'country', 'label'))
161 if lang and caption.get('source'):
164 'url': caption['source']}]
166 info = self._get_common_fields(webpage)
170 'view_count': view_count,
171 'subtitles': subtitles,
176 class VLiveChannelIE(InfoExtractor):
177 IE_NAME = 'vlive:channel'
178 _VALID_URL = r'https?://channels\.vlive\.tv/(?P<id>[0-9A-Z]+)/video'
180 'url': 'http://channels.vlive.tv/FCD4B/video',
185 'playlist_mincount': 110
187 _APP_ID = '8c6cc7b45d2568fb668be6e05b6e5a3b'
189 def _real_extract(self, url):
190 channel_code = self._match_id(url)
192 webpage = self._download_webpage(
193 'http://channels.vlive.tv/%s/video' % channel_code, channel_code)
194 app_js_url = self._search_regex(
195 r'(http[^\'\"\s]+app\.js)', webpage, 'app js', default='')
198 app_js = self._download_webpage(app_js_url, channel_code, 'app js')
199 app_id = self._search_regex(
200 r'Global\.VFAN_APP_ID\s*=\s*[\'"]([^\'"]+)[\'"]',
201 app_js, 'app id', default=self._APP_ID)
203 app_id = self._APP_ID
205 channel_info = self._download_json(
206 'http://api.vfan.vlive.tv/vproxy/channelplus/decodeChannelCode',
207 channel_code, note='decode channel code',
208 query={'app_id': app_id, 'channelCode': channel_code, '_': int(time.time())})
210 channel_seq = channel_info['result']['channelSeq']
214 for page_num in itertools.count(1):
215 video_list = self._download_json(
216 'http://api.vfan.vlive.tv/vproxy/channelplus/getChannelVideoList',
217 channel_code, note='channel list %d' % page_num,
220 'channelSeq': channel_seq,
221 'maxNumOfRows': 1000,
222 '_': int(time.time()),
227 channel_name = video_list['result']['channelInfo']['channelName']
229 if not video_list['result'].get('videoList'):
232 for video in video_list['result']['videoList']:
233 video_id = str(video['videoSeq'])
236 'http://www.vlive.tv/video/%s' % video_id, 'Vlive', video_id))
238 return self.playlist_result(
239 entries, channel_code, channel_name)