2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from .naver
import NaverBaseIE
10 from ..compat
import compat_str
19 class VLiveIE(NaverBaseIE
):
21 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/(?:video|post)/(?P<id>(?:\d-)?[0-9]+)'
22 _NETRC_MACHINE
= 'vlive'
24 'url': 'https://www.vlive.tv/video/1326',
25 'md5': 'cc7314812855ce56de70a06a27314983',
29 'title': "[V LIVE] Girl's Day's Broadcast",
30 'creator': "Girl's Day",
32 'uploader_id': 'muploader_a',
36 'url': 'https://vlive.tv/post/1-18244258',
37 'md5': 'cc7314812855ce56de70a06a27314983',
41 'title': "[V LIVE] Girl's Day's Broadcast",
42 'creator': "Girl's Day",
44 'uploader_id': 'muploader_a',
48 'url': 'https://www.vlive.tv/video/16937',
52 'title': '[V LIVE] 첸백시 걍방',
55 'subtitles': 'mincount:12',
56 'uploader_id': 'muploader_j',
59 'skip_download': True,
62 'url': 'https://www.vlive.tv/video/129100',
63 'md5': 'ca2569453b79d66e5b919e5d308bff6b',
67 'title': '[V LIVE] [BTS+] Run BTS! 2019 - EP.71 :: Behind the scene',
70 'subtitles': 'mincount:10',
72 'skip': 'This video is only available for CH+ subscribers',
76 def suitable(cls
, url
):
77 return False if VLivePlaylistIE
.suitable(url
) else super(VLiveIE
, cls
).suitable(url
)
79 def _real_initialize(self
):
83 email
, password
= self
._get
_login
_info
()
84 if None in (email
, password
):
88 login_info
= self
._download
_json
(
89 'https://www.vlive.tv/auth/loginInfo', None,
90 note
='Downloading login info',
91 headers
={'Referer': 'https://www.vlive.tv/home'}
)
93 login_info
, lambda x
: x
['message']['login'], bool) or False
95 LOGIN_URL
= 'https://www.vlive.tv/auth/email/login'
96 self
._request
_webpage
(
97 LOGIN_URL
, None, note
='Downloading login cookies')
99 self
._download
_webpage
(
100 LOGIN_URL
, None, note
='Logging in',
101 data
=urlencode_postdata({'email': email, 'pwd': password}
),
103 'Referer': LOGIN_URL
,
104 'Content-Type': 'application/x-www-form-urlencoded'
107 if not is_logged_in():
108 raise ExtractorError('Unable to log in', expected
=True)
110 def _real_extract(self
, url
):
111 # url may match on a post or a video url with a post_id potentially matching a video_id
112 working_id
= self
._match
_id
(url
)
113 webpage
= self
._download
_webpage
(url
, working_id
)
115 PARAMS_RE
= r
'window\.__PRELOADED_STATE__\s*=\s*({.*});?\s*</script>'
116 PARAMS_FIELD
= 'params'
118 params
= self
._search
_regex
(
119 PARAMS_RE
, webpage
, PARAMS_FIELD
, default
='', flags
=re
.DOTALL
)
120 params
= self
._parse
_json
(params
, working_id
, fatal
=False)
122 video_params
= try_get(params
, lambda x
: x
["postDetail"]["post"]["officialVideo"], dict)
124 if video_params
is None:
125 error
= try_get(params
, lambda x
: x
["postDetail"]["error"], dict)
126 error_data
= try_get(error
, lambda x
: x
["data"], dict)
127 error_video
= try_get(error_data
, lambda x
: x
["officialVideo"], dict)
128 error_msg
= try_get(error
, lambda x
: x
["message"], compat_str
)
129 product_type
= try_get(error_data
,
130 [lambda x
: x
["officialVideo"]["productType"],
131 lambda x
: x
["board"]["boardType"]],
134 if error_video
is not None:
135 if product_type
in ('VLIVE_PLUS', 'VLIVE+'):
136 self
.raise_login_required('This video is only available with V LIVE+.')
137 elif error_msg
is not None:
138 raise ExtractorError('V LIVE reported the following error: %s' % error_msg
)
140 raise ExtractorError('Failed to extract video parameters.')
142 raise ExtractorError('Url does not appear to be a video post.', expected
=True)
144 raise ExtractorError('Failed to extract video parameters.')
146 video_id
= working_id
if 'video' in url
else str(video_params
["videoSeq"])
148 video_type
= video_params
["type"]
149 if video_type
in ('VOD'):
150 encoding_status
= video_params
["encodingStatus"]
151 if encoding_status
== 'COMPLETE':
152 return self
._replay
(video_id
, webpage
, params
, video_params
)
154 raise ExtractorError('VOD encoding not yet complete. Please try again later.',
156 elif video_type
in ('LIVE'):
157 video_status
= video_params
["status"]
158 if video_status
in ('RESERVED'):
159 raise ExtractorError('Coming soon!', expected
=True)
160 elif video_status
in ('ENDED', 'END'):
161 raise ExtractorError('Uploading for replay. Please wait...', expected
=True)
163 return self
._live
(video_id
, webpage
, params
)
165 raise ExtractorError('Unknown video type %s' % video_type
)
167 def _get_common_fields(self
, webpage
, params
):
168 title
= self
._og
_search
_title
(webpage
)
169 description
= self
._html
_search
_meta
(
170 ['og:description', 'description', 'twitter:description'],
171 webpage
, 'description', default
=None)
172 creator
= (try_get(params
, lambda x
: x
["channel"]["channel"]["channelName"], compat_str
)
173 or self
._search
_regex
(r
'on (.*) channel', description
or '', 'creator', fatal
=False))
174 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
178 'thumbnail': thumbnail
,
181 def _live(self
, video_id
, webpage
, params
):
182 LIVE_INFO_ENDPOINT
= 'https://www.vlive.tv/globalv-web/vam-web/old/v3/live/%s/playInfo' % video_id
183 play_info
= self
._download
_json
(LIVE_INFO_ENDPOINT
, video_id
,
184 headers
={"referer": "https://www.vlive.tv"}
)
186 streams
= try_get(play_info
, lambda x
: x
["result"]["streamList"], list) or []
189 for stream
in streams
:
190 formats
.extend(self
._extract
_m
3u8_formats
(
191 stream
['serviceUrl'], video_id
, 'mp4',
192 fatal
=False, live
=True))
193 self
._sort
_formats
(formats
)
195 info
= self
._get
_common
_fields
(webpage
, params
)
197 'title': self
._live
_title
(info
['title']),
204 def _replay(self
, video_id
, webpage
, params
, video_params
):
205 long_video_id
= video_params
["vodId"]
207 VOD_KEY_ENDPOINT
= 'https://www.vlive.tv/globalv-web/vam-web/video/v1.0/vod/%s/inkey' % video_id
208 key_json
= self
._download
_json
(VOD_KEY_ENDPOINT
, video_id
,
209 headers
={"referer": "https://www.vlive.tv"}
)
210 key
= key_json
["inkey"]
213 self
._get
_common
_fields
(webpage
, params
),
214 self
._extract
_video
_info
(video_id
, long_video_id
, key
))
217 class VLiveChannelIE(InfoExtractor
):
218 IE_NAME
= 'vlive:channel'
219 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?(?:channels\.vlive\.tv/|vlive\.tv/channels?/)(?P<id>[0-9A-Z]+)'
221 'url': 'https://channels.vlive.tv/FCD4B',
226 'playlist_mincount': 110
228 'url': 'https://www.vlive.tv/channel/FCD4B',
233 'playlist_mincount': 110
235 _APP_ID
= '8c6cc7b45d2568fb668be6e05b6e5a3b'
237 def _real_extract(self
, url
):
238 channel_code
= self
._match
_id
(url
)
240 webpage
= self
._download
_webpage
(
241 'http://channels.vlive.tv/%s/video' % channel_code
, channel_code
)
245 app_js_url
= self
._search
_regex
(
246 r
'<script[^>]+src=(["\'])(?P
<url
>http
.+?
/app\
.js
.*?
)\
1',
247 webpage, 'app js
', default=None, group='url
')
250 app_js = self._download_webpage(
251 app_js_url, channel_code, 'Downloading app JS
', fatal=False)
253 app_id = self._search_regex(
254 r'Global\
.VFAN_APP_ID\s
*=\s
*[\'"]([^\'"]+)[\'"]',
255 app_js, 'app id', default=None)
257 app_id = app_id or self._APP_ID
259 channel_info = self._download_json(
260 'http://api.vfan.vlive.tv/vproxy/channelplus/decodeChannelCode',
261 channel_code, note='Downloading decode channel code',
264 'channelCode': channel_code,
265 '_': int(time.time())
268 channel_seq = channel_info['result']['channelSeq']
272 for page_num in itertools.count(1):
273 video_list = self._download_json(
274 'http://api.vfan.vlive.tv/vproxy/channelplus/getChannelVideoList',
275 channel_code, note='Downloading channel list page #%d' % page_num,
278 'channelSeq': channel_seq,
279 # Large values of maxNumOfRows (~300 or above) may cause
280 # empty responses (see [1]), e.g. this happens for [2] that
281 # has more than 300 videos.
282 # 1. https://github.com/ytdl-org/youtube-dl/issues/13830
283 # 2. http://channels.vlive.tv/EDBF.
285 '_': int(time.time()),
291 channel_name = try_get(
293 lambda x: x['result']['channelInfo']['channelName'],
297 video_list, lambda x: x['result']['videoList'], list)
302 video_id = video.get('videoSeq')
305 video_id = compat_str(video_id)
308 'http://www.vlive.tv/video/%s' % video_id,
309 ie=VLiveIE.ie_key(), video_id=video_id))
311 return self.playlist_result(
312 entries, channel_code, channel_name)
315 class VLivePlaylistIE(InfoExtractor):
316 IE_NAME = 'vlive:playlist'
317 _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<video_id>[0-9]+)/playlist/(?P<id>[0-9]+)'
318 _VIDEO_URL_TEMPLATE = 'http://www.vlive.tv/video/%s'
320 # regular working playlist
321 'url': 'https://www.vlive.tv/video/117956/playlist/117963',
324 'title': '아이돌룸(IDOL ROOM) 41회 - (여자)아이들'
326 'playlist_mincount': 10
328 # playlist with no playlistVideoSeqs
329 'url': 'http://www.vlive.tv/video/22867/playlist/22912',
333 'title': '[V LIVE] Valentine Day Message from MINA',
338 'skip_download': True,
342 def _build_video_result(self, video_id, message):
343 self.to_screen(message)
344 return self.url_result(
345 self._VIDEO_URL_TEMPLATE % video_id,
346 ie=VLiveIE.ie_key(), video_id=video_id)
348 def _real_extract(self, url):
349 mobj = re.match(self._VALID_URL, url)
350 video_id, playlist_id = mobj.group('video_id', 'id')
352 if self._downloader.params.get('noplaylist'):
353 return self._build_video_result(
355 'Downloading just video %s because of --no-playlist'
359 'Downloading playlist %s - add --no-playlist to just download video'
362 webpage = self._download_webpage(
363 'http://www.vlive.tv/video/%s/playlist/%s'
364 % (video_id, playlist_id), playlist_id)
366 raw_item_ids = self._search_regex(
367 r'playlistVideoSeqs\s*=\s*(\[[^]]+\])', webpage,
368 'playlist video seqs', default=None, fatal=False)
371 return self._build_video_result(
373 'Downloading just video %s because no playlist was found'
376 item_ids = self._parse_json(raw_item_ids, playlist_id)
380 self._VIDEO_URL_TEMPLATE % item_id, ie=VLiveIE.ie_key(),
381 video_id=compat_str(item_id))
382 for item_id in item_ids]
384 playlist_name = self._html_search_regex(
385 r'<div[^>]+class="[^
"]*multicam_playlist[^>]*>\s*<h3[^>]+>([^<]+)',
386 webpage, 'playlist title', fatal=False)
388 return self.playlist_result(entries, playlist_id, playlist_name)