2 from __future__
import unicode_literals
7 from .naver
import NaverBaseIE
24 class VLiveBaseIE(NaverBaseIE
):
25 _NETRC_MACHINE
= 'vlive'
28 def _real_initialize(self
):
29 if not self
._logged
_in
:
30 VLiveBaseIE
._logged
_in
= self
._login
()
33 email
, password
= self
._get
_login
_info
()
37 LOGIN_URL
= 'https://www.vlive.tv/auth/email/login'
38 self
._request
_webpage
(
39 LOGIN_URL
, None, note
='Downloading login cookies')
41 self
._download
_webpage
(
42 LOGIN_URL
, None, note
='Logging in',
43 data
=urlencode_postdata({'email': email, 'pwd': password}
),
46 'Content-Type': 'application/x-www-form-urlencoded'
49 login_info
= self
._download
_json
(
50 'https://www.vlive.tv/auth/loginInfo', None,
51 note
='Checking login status',
52 headers
={'Referer': 'https://www.vlive.tv/home'}
)
54 if not try_get(login_info
, lambda x
: x
['message']['login'], bool):
55 raise ExtractorError('Unable to log in', expected
=True)
58 def _call_api(self
, path_template
, video_id
, fields
=None, query_add
={}, note
=None):
60 note
= 'Downloading %s JSON metadata' % path_template
.split('/')[-1].split('-')[0]
61 query
= {'appId': '8c6cc7b45d2568fb668be6e05b6e5a3b', 'gcc': 'KR', 'platformType': 'PC'}
63 query
['fields'] = fields
65 query
.update(query_add
)
67 return self
._download
_json
(
68 'https://www.vlive.tv/globalv-web/vam-web/' + path_template
% video_id
, video_id
,
69 note
, headers
={'Referer': 'https://www.vlive.tv/'}
, query
=query
)
70 except ExtractorError
as e
:
71 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
72 self
.raise_login_required(json
.loads(e
.cause
.read().decode('utf-8'))['message'])
76 class VLiveIE(VLiveBaseIE
):
78 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/(?:video|embed)/(?P<id>[0-9]+)'
80 'url': 'http://www.vlive.tv/video/1326',
81 'md5': 'cc7314812855ce56de70a06a27314983',
85 'title': "Girl's Day's Broadcast",
86 'creator': "Girl's Day",
88 'uploader_id': 'muploader_a',
91 'url': 'http://www.vlive.tv/video/16937',
98 'subtitles': 'mincount:12',
99 'uploader_id': 'muploader_j',
102 'skip_download': True,
105 'url': 'https://www.vlive.tv/video/129100',
106 'md5': 'ca2569453b79d66e5b919e5d308bff6b',
110 'title': '[V LIVE] [BTS+] Run BTS! 2019 - EP.71 :: Behind the scene',
113 'subtitles': 'mincount:10',
115 'skip': 'This video is only available for CH+ subscribers',
117 'url': 'https://www.vlive.tv/embed/1326',
118 'only_matching': True,
120 # works only with gcc=KR
121 'url': 'https://www.vlive.tv/video/225019',
122 'only_matching': True,
124 'url': 'https://www.vlive.tv/video/223906',
129 'playlist_mincount': 120
132 def _real_extract(self
, url
):
133 video_id
= self
._match
_id
(url
)
135 post
= self
._call
_api
(
136 'post/v1.0/officialVideoPost-%s', video_id
,
137 'author{nickname},channel{channelCode,channelName},officialVideo{commentCount,exposeStatus,likeCount,playCount,playTime,status,title,type,vodId},playlist{playlistSeq,totalCount,name}')
139 playlist
= post
.get('playlist')
140 if not playlist
or self
.get_param('noplaylist'):
143 'Downloading just video %s because of --no-playlist'
146 video
= post
['officialVideo']
147 return self
._get
_vlive
_info
(post
, video
, video_id
)
149 playlist_name
= playlist
.get('name')
150 playlist_id
= str_or_none(playlist
.get('playlistSeq'))
151 playlist_count
= str_or_none(playlist
.get('totalCount'))
153 playlist
= self
._call
_api
(
154 'playlist/v1.0/playlist-%s/posts', playlist_id
, 'data', {'limit': playlist_count}
)
157 for video_data
in playlist
['data']:
158 video
= video_data
.get('officialVideo')
159 video_id
= str_or_none(video
.get('videoSeq'))
160 entries
.append(self
._get
_vlive
_info
(video_data
, video
, video_id
))
162 return self
.playlist_result(entries
, playlist_id
, playlist_name
)
164 def _get_vlive_info(self
, post
, video
, video_id
):
165 def get_common_fields():
166 channel
= post
.get('channel') or {}
168 'title': video
.get('title'),
169 'creator': post
.get('author', {}).get('nickname'),
170 'channel': channel
.get('channelName'),
171 'channel_id': channel
.get('channelCode'),
172 'duration': int_or_none(video
.get('playTime')),
173 'view_count': int_or_none(video
.get('playCount')),
174 'like_count': int_or_none(video
.get('likeCount')),
175 'comment_count': int_or_none(video
.get('commentCount')),
178 video_type
= video
.get('type')
179 if video_type
== 'VOD':
180 inkey
= self
._call
_api
('video/v1.0/vod/%s/inkey', video_id
)['inkey']
181 vod_id
= video
['vodId']
182 info_dict
= merge_dicts(
184 self
._extract
_video
_info
(video_id
, vod_id
, inkey
))
185 thumbnail
= video
.get('thumb')
187 if not info_dict
.get('thumbnails') and info_dict
.get('thumbnail'):
188 info_dict
['thumbnails'] = [{'url': info_dict.pop('thumbnail')}
]
189 info_dict
.setdefault('thumbnails', []).append({'url': thumbnail, 'preference': 1}
)
191 elif video_type
== 'LIVE':
192 status
= video
.get('status')
193 if status
== 'ON_AIR':
194 stream_url
= self
._call
_api
(
195 'old/v3/live/%s/playInfo',
196 video_id
)['result']['adaptiveStreamUrl']
197 formats
= self
._extract
_m
3u8_formats
(stream_url
, video_id
, 'mp4')
198 self
._sort
_formats
(formats
)
199 info
= get_common_fields()
201 'title': self
._live
_title
(video
['title']),
207 elif status
== 'ENDED':
208 raise ExtractorError(
209 'Uploading for replay. Please wait...', expected
=True)
210 elif status
== 'RESERVED':
211 raise ExtractorError('Coming soon!', expected
=True)
212 elif video
.get('exposeStatus') == 'CANCEL':
213 raise ExtractorError(
214 'We are sorry, but the live broadcast has been canceled.',
217 raise ExtractorError('Unknown status ' + status
)
220 class VLivePostIE(VLiveBaseIE
):
221 IE_NAME
= 'vlive:post'
222 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/post/(?P<id>\d-\d+)'
225 'url': 'https://www.vlive.tv/post/1-20088044',
228 'title': 'Hola estrellitas la tierra les dice hola (si era así no?) Ha...',
229 'description': 'md5:fab8a1e50e6e51608907f46c7fa4b407',
234 'url': 'https://www.vlive.tv/post/1-20087926',
237 'title': 'James Corden: And so, the baby becamos the Papa💜😭💪😭',
241 _FVIDEO_TMPL
= 'fvideo/v1.0/fvideo-%%s/%s'
243 def _real_extract(self
, url
):
244 post_id
= self
._match
_id
(url
)
246 post
= self
._call
_api
(
247 'post/v1.0/post-%s', post_id
,
248 'attachments{video},officialVideo{videoSeq},plainBody,title')
250 video_seq
= str_or_none(try_get(
251 post
, lambda x
: x
['officialVideo']['videoSeq']))
253 return self
.url_result(
254 'http://www.vlive.tv/video/' + video_seq
,
255 VLiveIE
.ie_key(), video_seq
)
257 title
= post
['title']
259 for idx
, video
in enumerate(post
['attachments']['video'].values()):
260 video_id
= video
.get('videoId')
263 upload_type
= video
.get('uploadType')
264 upload_info
= video
.get('uploadInfo') or {}
266 if upload_type
== 'SOS':
267 download
= self
._call
_api
(
268 self
._FVIDEO
_TMPL
% 'sosPlayInfo', video_id
)['videoUrl']['download']
270 for f_id
, f_url
in download
.items():
274 'height': int_or_none(f_id
[:-1]),
276 self
._sort
_formats
(formats
)
280 'thumbnail': upload_info
.get('imageUrl'),
282 elif upload_type
== 'V':
283 vod_id
= upload_info
.get('videoId')
286 inkey
= self
._call
_api
(self
._FVIDEO
_TMPL
% 'inKey', video_id
)['inKey']
287 entry
= self
._extract
_video
_info
(video_id
, vod_id
, inkey
)
289 entry
['title'] = '%s_part%s' % (title
, idx
)
290 entries
.append(entry
)
291 return self
.playlist_result(
292 entries
, post_id
, title
, strip_or_none(post
.get('plainBody')))
295 class VLiveChannelIE(VLiveBaseIE
):
296 IE_NAME
= 'vlive:channel'
297 _VALID_URL
= r
'https?://(?:channels\.vlive\.tv|(?:(?:www|m)\.)?vlive\.tv/channel)/(?P<channel_id>[0-9A-Z]+)(?:/board/(?P<posts_id>\d+))?'
299 'url': 'http://channels.vlive.tv/FCD4B',
304 'playlist_mincount': 110
306 'url': 'https://www.vlive.tv/channel/FCD4B',
307 'only_matching': True,
309 'url': 'https://www.vlive.tv/channel/FCD4B/board/3546',
312 'title': 'MAMAMOO - Star Board',
314 'playlist_mincount': 880
317 def _entries(self
, posts_id
, board_name
):
319 posts_path
= 'post/v1.0/board-%s/posts'
320 query_add
= {'limit': 100, 'sortType': 'LATEST'}
322 posts_path
= 'post/v1.0/channel-%s/starPosts'
323 query_add
= {'limit': 100}
325 for page_num
in itertools
.count(1):
326 video_list
= self
._call
_api
(
327 posts_path
, posts_id
, 'channel{channelName},contentType,postId,title,url', query_add
,
328 note
=f
'Downloading playlist page {page_num}')
330 for video
in try_get(video_list
, lambda x
: x
['data'], list) or []:
331 video_id
= str(video
.get('postId'))
332 video_title
= str_or_none(video
.get('title'))
333 video_url
= url_or_none(video
.get('url'))
334 if not all((video_id
, video_title
, video_url
)) or video
.get('contentType') != 'VIDEO':
336 channel_name
= try_get(video
, lambda x
: x
['channel']['channelName'], compat_str
)
337 yield self
.url_result(video_url
, VLivePostIE
.ie_key(), video_id
, video_title
, channel
=channel_name
)
339 after
= try_get(video_list
, lambda x
: x
['paging']['nextParams']['after'], compat_str
)
342 query_add
['after'] = after
344 def _real_extract(self
, url
):
345 channel_id
, posts_id
= self
._match
_valid
_url
(url
).groups()
349 board
= self
._call
_api
(
350 'board/v1.0/board-%s', posts_id
, 'title,boardType')
351 board_name
= board
.get('title') or 'Unknown'
352 if board
.get('boardType') not in ('STAR', 'VLIVE_PLUS'):
353 raise ExtractorError(f
'Board {board_name!r} is not supported', expected
=True)
355 entries
= self
._entries
(posts_id
or channel_id
, board_name
)
356 first_video
= next(entries
)
357 channel_name
= first_video
['channel']
359 return self
.playlist_result(
360 itertools
.chain([first_video
], entries
),
361 f
'{channel_id}-{posts_id}' if posts_id
else channel_id
,
362 f
'{channel_name} - {board_name}' if channel_name
and board_name
else channel_name
)