2 from __future__ import unicode_literals
8 from .common import InfoExtractor
10 compat_urllib_parse_urlencode,
24 class VLiveIE(InfoExtractor):
26 _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
27 _NETRC_MACHINE = 'vlive'
29 'url': 'http://www.vlive.tv/video/1326',
30 'md5': 'cc7314812855ce56de70a06a27314983',
34 'title': "[V LIVE] Girl's Day's Broadcast",
35 'creator': "Girl's Day",
39 'url': 'http://www.vlive.tv/video/16937',
43 'title': '[V LIVE] 첸백시 걍방',
46 'subtitles': 'mincount:12',
49 'skip_download': True,
52 'url': 'https://www.vlive.tv/video/129100',
53 'md5': 'ca2569453b79d66e5b919e5d308bff6b',
57 'title': "[V LIVE] [BTS+] Run BTS! 2019 - EP.71 :: Behind the scene",
60 'subtitles': 'mincount:10',
62 'skip': 'This video is only available for CH+ subscribers',
66 def suitable(cls, url):
67 return False if VLivePlaylistIE.suitable(url) else super(VLiveIE, cls).suitable(url)
69 def _real_initialize(self):
73 email, password = self._get_login_info()
74 if None in (email, password):
78 login_info = self._download_json(
79 'https://www.vlive.tv/auth/loginInfo', None,
80 note='Downloading login info',
81 headers={'Referer': 'https://www.vlive.tv/home'})
83 return try_get(login_info,
84 lambda x: x['message']['login'], bool) or False
89 LOGIN_URL = 'https://www.vlive.tv/auth/email/login'
90 self._request_webpage(LOGIN_URL, None,
91 note='Downloading login cookies')
93 self._download_webpage(
94 LOGIN_URL, None, note='Logging in',
95 data=urlencode_postdata({'email': email, 'pwd': password}),
98 'Content-Type': 'application/x-www-form-urlencoded'
101 if not is_logged_in():
102 raise ExtractorError('Unable to log in', expected=True)
104 def _real_extract(self, url):
105 video_id = self._match_id(url)
107 webpage = self._download_webpage(
108 'https://www.vlive.tv/video/%s' % video_id, video_id)
110 VIDEO_PARAMS_RE = r'\bvlive\.video\.init\(([^)]+)'
111 VIDEO_PARAMS_FIELD = 'video params'
113 params = self._parse_json(self._search_regex(
114 VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD, default=''), video_id,
115 transform_source=lambda s: '[' + s + ']', fatal=False)
117 if not params or len(params) < 7:
118 params = self._search_regex(
119 VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD)
120 params = [p.strip(r'"') for p in re.split(r'\s*,\s*', params)]
122 status, long_video_id, key = params[2], params[5], params[6]
123 status = remove_start(status, 'PRODUCT_')
125 if status in ('LIVE_ON_AIR', 'BIG_EVENT_ON_AIR'):
126 return self._live(video_id, webpage)
127 elif status in ('VOD_ON_AIR', 'BIG_EVENT_INTRO'):
128 return self._replay(video_id, webpage, long_video_id, key)
130 if status == 'LIVE_END':
131 raise ExtractorError('Uploading for replay. Please wait...',
133 elif status == 'COMING_SOON':
134 raise ExtractorError('Coming soon!', expected=True)
135 elif status == 'CANCELED':
136 raise ExtractorError('We are sorry, '
137 'but the live broadcast has been canceled.',
139 elif status == 'ONLY_APP':
140 raise ExtractorError('Unsupported video type', expected=True)
142 raise ExtractorError('Unknown status %s' % status)
144 def _get_common_fields(self, webpage):
145 title = self._og_search_title(webpage)
146 creator = self._html_search_regex(
147 r'<div[^>]+class="info_area"[^>]*>\s*(?:<em[^>]*>.*</em\s*>\s*)?<a\s+[^>]*>([^<]+)',
148 webpage, 'creator', fatal=False)
149 thumbnail = self._og_search_thumbnail(webpage)
153 'thumbnail': thumbnail,
156 def _live(self, video_id, webpage):
157 init_page = self._download_init_page(video_id)
159 live_params = self._search_regex(
160 r'"liveStreamInfo"\s*:\s*(".*"),',
161 init_page, 'live stream info')
162 live_params = self._parse_json(live_params, video_id)
163 live_params = self._parse_json(live_params, video_id)
166 for vid in live_params.get('resolutions', []):
167 formats.extend(self._extract_m3u8_formats(
168 vid['cdnUrl'], video_id, 'mp4',
169 m3u8_id=vid.get('name'),
170 fatal=False, live=True))
171 self._sort_formats(formats)
173 info = self._get_common_fields(webpage)
175 'title': self._live_title(info['title']),
182 def _replay(self, video_id, webpage, long_video_id, key):
183 if '' in (long_video_id, key):
184 init_page = self._download_init_page(video_id)
185 video_info = self._parse_json(self._search_regex(
186 r'(?s)oVideoStatus\s*=\s*({.*})', init_page, 'video info'),
188 if video_info['status'] == 'NEED_CHANNEL_PLUS':
189 self.raise_login_required(
190 'This video is only available for CH+ subscribers')
191 long_video_id, key = video_info['vid'], video_info['inkey']
193 playinfo = self._download_json(
194 'http://global.apis.naver.com/rmcnmv/rmcnmv/vod_play_videoInfo.json?%s'
195 % compat_urllib_parse_urlencode({
196 'videoId': long_video_id,
199 'doct': 'json', # document type (xml or json)
200 'cpt': 'vtt', # captions type (vtt or ttml)
204 'url': vid['source'],
205 'format_id': vid.get('encodingOption', {}).get('name'),
206 'abr': float_or_none(vid.get('bitrate', {}).get('audio')),
207 'vbr': float_or_none(vid.get('bitrate', {}).get('video')),
208 'width': int_or_none(vid.get('encodingOption', {}).get('width')),
209 'height': int_or_none(vid.get('encodingOption', {}).get('height')),
210 'filesize': int_or_none(vid.get('size')),
211 } for vid in playinfo.get('videos', {}).get('list', []) if vid.get('source')]
212 self._sort_formats(formats)
214 view_count = int_or_none(playinfo.get('meta', {}).get('count'))
217 for caption in playinfo.get('captions', {}).get('list', []):
218 lang = dict_get(caption, ('locale', 'language', 'country', 'label'))
219 if lang and caption.get('source'):
222 'url': caption['source']}]
224 info = self._get_common_fields(webpage)
228 'view_count': view_count,
229 'subtitles': subtitles,
233 def _download_init_page(self, video_id):
234 return self._download_webpage(
235 'https://www.vlive.tv/video/init/view',
236 video_id, note='Downloading live webpage',
237 data=urlencode_postdata({'videoSeq': video_id}),
239 'Referer': 'https://www.vlive.tv/video/%s' % video_id,
240 'Content-Type': 'application/x-www-form-urlencoded'
244 class VLiveChannelIE(InfoExtractor):
245 IE_NAME = 'vlive:channel'
246 _VALID_URL = r'https?://channels\.vlive\.tv/(?P<id>[0-9A-Z]+)'
248 'url': 'http://channels.vlive.tv/FCD4B',
253 'playlist_mincount': 110
255 _APP_ID = '8c6cc7b45d2568fb668be6e05b6e5a3b'
257 def _real_extract(self, url):
258 channel_code = self._match_id(url)
260 webpage = self._download_webpage(
261 'http://channels.vlive.tv/%s/video' % channel_code, channel_code)
265 app_js_url = self._search_regex(
266 r'<script[^>]+src=(["\'])(?P<url>http.+?/app\.js.*?)\1',
267 webpage, 'app js', default=None, group='url')
270 app_js = self._download_webpage(
271 app_js_url, channel_code, 'Downloading app JS', fatal=False)
273 app_id = self._search_regex(
274 r'Global\.VFAN_APP_ID\s*=\s*[\'"]([^\'"]+)[\'"]',
275 app_js, 'app id', default=None)
277 app_id = app_id or self._APP_ID
279 channel_info = self._download_json(
280 'http://api.vfan.vlive.tv/vproxy/channelplus/decodeChannelCode',
281 channel_code, note='Downloading decode channel code',
284 'channelCode': channel_code,
285 '_': int(time.time())
288 channel_seq = channel_info['result']['channelSeq']
292 for page_num in itertools.count(1):
293 video_list = self._download_json(
294 'http://api.vfan.vlive.tv/vproxy/channelplus/getChannelVideoList',
295 channel_code, note='Downloading channel list page #%d' % page_num,
298 'channelSeq': channel_seq,
299 # Large values of maxNumOfRows (~300 or above) may cause
300 # empty responses (see [1]), e.g. this happens for [2] that
301 # has more than 300 videos.
302 # 1. https://github.com/ytdl-org/youtube-dl/issues/13830
303 # 2. http://channels.vlive.tv/EDBF.
305 '_': int(time.time()),
311 channel_name = try_get(
313 lambda x: x['result']['channelInfo']['channelName'],
317 video_list, lambda x: x['result']['videoList'], list)
322 video_id = video.get('videoSeq')
325 video_id = compat_str(video_id)
328 'http://www.vlive.tv/video/%s' % video_id,
329 ie=VLiveIE.ie_key(), video_id=video_id))
331 return self.playlist_result(
332 entries, channel_code, channel_name)
335 class VLivePlaylistIE(InfoExtractor):
336 IE_NAME = 'vlive:playlist'
337 _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<video_id>[0-9]+)/playlist/(?P<id>[0-9]+)'
339 'url': 'http://www.vlive.tv/video/22867/playlist/22912',
342 'title': 'Valentine Day Message from TWICE'
344 'playlist_mincount': 9
347 def _real_extract(self, url):
348 mobj = re.match(self._VALID_URL, url)
349 video_id, playlist_id = mobj.group('video_id', 'id')
351 VIDEO_URL_TEMPLATE = 'http://www.vlive.tv/video/%s'
352 if self._downloader.params.get('noplaylist'):
354 'Downloading just video %s because of --no-playlist' % video_id)
355 return self.url_result(
356 VIDEO_URL_TEMPLATE % video_id,
357 ie=VLiveIE.ie_key(), video_id=video_id)
360 'Downloading playlist %s - add --no-playlist to just download video'
363 webpage = self._download_webpage(
364 'http://www.vlive.tv/video/%s/playlist/%s'
365 % (video_id, playlist_id), playlist_id)
367 item_ids = self._parse_json(
369 r'playlistVideoSeqs\s*=\s*(\[[^]]+\])', webpage,
370 'playlist video seqs'),
375 VIDEO_URL_TEMPLATE % item_id, ie=VLiveIE.ie_key(),
376 video_id=compat_str(item_id))
377 for item_id in item_ids]
379 playlist_name = self._html_search_regex(
380 r'<div[^>]+class="[^"]*multicam_playlist[^>]*>\s*<h3[^>]+>([^<]+)',
381 webpage, 'playlist title', fatal=False)
383 return self.playlist_result(entries, playlist_id, playlist_name)