2 from __future__
import unicode_literals
7 from .naver
import NaverBaseIE
25 class VLiveBaseIE(NaverBaseIE
):
26 _NETRC_MACHINE
= 'vlive'
29 def _real_initialize(self
):
30 if not self
._logged
_in
:
31 VLiveBaseIE
._logged
_in
= self
._login
()
34 email
, password
= self
._get
_login
_info
()
38 LOGIN_URL
= 'https://www.vlive.tv/auth/email/login'
39 self
._request
_webpage
(
40 LOGIN_URL
, None, note
='Downloading login cookies')
42 self
._download
_webpage
(
43 LOGIN_URL
, None, note
='Logging in',
44 data
=urlencode_postdata({'email': email, 'pwd': password}
),
47 'Content-Type': 'application/x-www-form-urlencoded'
50 login_info
= self
._download
_json
(
51 'https://www.vlive.tv/auth/loginInfo', None,
52 note
='Checking login status',
53 headers
={'Referer': 'https://www.vlive.tv/home'}
)
55 if not try_get(login_info
, lambda x
: x
['message']['login'], bool):
56 raise ExtractorError('Unable to log in', expected
=True)
59 def _call_api(self
, path_template
, video_id
, fields
=None, query_add
={}, note
=None):
61 note
= 'Downloading %s JSON metadata' % path_template
.split('/')[-1].split('-')[0]
62 query
= {'appId': '8c6cc7b45d2568fb668be6e05b6e5a3b', 'gcc': 'KR', 'platformType': 'PC'}
64 query
['fields'] = fields
66 query
.update(query_add
)
68 return self
._download
_json
(
69 'https://www.vlive.tv/globalv-web/vam-web/' + path_template
% video_id
, video_id
,
70 note
, headers
={'Referer': 'https://www.vlive.tv/'}
, query
=query
)
71 except ExtractorError
as e
:
72 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
73 self
.raise_login_required(json
.loads(e
.cause
.read().decode('utf-8'))['message'])
77 class VLiveIE(VLiveBaseIE
):
79 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/(?:video|embed)/(?P<id>[0-9]+)'
81 'url': 'http://www.vlive.tv/video/1326',
82 'md5': 'cc7314812855ce56de70a06a27314983',
86 'title': "Girl's Day's Broadcast",
87 'creator': "Girl's Day",
89 'uploader_id': 'muploader_a',
90 'upload_date': '20150817',
91 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
92 'timestamp': 1439816449,
95 'skip_download': True,
98 'url': 'http://www.vlive.tv/video/16937',
105 'subtitles': 'mincount:12',
106 'uploader_id': 'muploader_j',
107 'upload_date': '20161112',
108 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
109 'timestamp': 1478923074,
112 'skip_download': True,
115 'url': 'https://www.vlive.tv/video/129100',
116 'md5': 'ca2569453b79d66e5b919e5d308bff6b',
120 'title': '[V LIVE] [BTS+] Run BTS! 2019 - EP.71 :: Behind the scene',
123 'subtitles': 'mincount:10',
125 'skip': 'This video is only available for CH+ subscribers',
127 'url': 'https://www.vlive.tv/embed/1326',
128 'only_matching': True,
130 # works only with gcc=KR
131 'url': 'https://www.vlive.tv/video/225019',
132 'only_matching': True,
134 'url': 'https://www.vlive.tv/video/223906',
139 'playlist_mincount': 120
142 def _real_extract(self
, url
):
143 video_id
= self
._match
_id
(url
)
145 post
= self
._call
_api
(
146 'post/v1.0/officialVideoPost-%s', video_id
,
147 'author{nickname},channel{channelCode,channelName},officialVideo{commentCount,exposeStatus,likeCount,playCount,playTime,status,title,type,vodId},playlist{playlistSeq,totalCount,name}')
149 playlist
= post
.get('playlist')
150 if not playlist
or self
.get_param('noplaylist'):
153 'Downloading just video %s because of --no-playlist'
156 video
= post
['officialVideo']
157 return self
._get
_vlive
_info
(post
, video
, video_id
)
159 playlist_name
= playlist
.get('name')
160 playlist_id
= str_or_none(playlist
.get('playlistSeq'))
161 playlist_count
= str_or_none(playlist
.get('totalCount'))
163 playlist
= self
._call
_api
(
164 'playlist/v1.0/playlist-%s/posts', playlist_id
, 'data', {'limit': playlist_count}
)
167 for video_data
in playlist
['data']:
168 video
= video_data
.get('officialVideo')
169 video_id
= str_or_none(video
.get('videoSeq'))
170 entries
.append(self
._get
_vlive
_info
(video_data
, video
, video_id
))
172 return self
.playlist_result(entries
, playlist_id
, playlist_name
)
174 def _get_vlive_info(self
, post
, video
, video_id
):
175 def get_common_fields():
176 channel
= post
.get('channel') or {}
178 'title': video
.get('title'),
179 'creator': post
.get('author', {}).get('nickname'),
180 'channel': channel
.get('channelName'),
181 'channel_id': channel
.get('channelCode'),
182 'duration': int_or_none(video
.get('playTime')),
183 'view_count': int_or_none(video
.get('playCount')),
184 'like_count': int_or_none(video
.get('likeCount')),
185 'comment_count': int_or_none(video
.get('commentCount')),
186 'timestamp': int_or_none(video
.get('createdAt'), scale
=1000),
187 'thumbnail': video
.get('thumb'),
190 video_type
= video
.get('type')
191 if video_type
== 'VOD':
192 inkey
= self
._call
_api
('video/v1.0/vod/%s/inkey', video_id
)['inkey']
193 vod_id
= video
['vodId']
194 info_dict
= merge_dicts(
196 self
._extract
_video
_info
(video_id
, vod_id
, inkey
))
197 thumbnail
= video
.get('thumb')
199 if not info_dict
.get('thumbnails') and info_dict
.get('thumbnail'):
200 info_dict
['thumbnails'] = [{'url': info_dict.pop('thumbnail')}
]
201 info_dict
.setdefault('thumbnails', []).append({'url': thumbnail, 'preference': 1}
)
203 elif video_type
== 'LIVE':
204 status
= video
.get('status')
205 if status
== 'ON_AIR':
206 stream_url
= self
._call
_api
(
207 'old/v3/live/%s/playInfo',
208 video_id
)['result']['adaptiveStreamUrl']
209 formats
= self
._extract
_m
3u8_formats
(stream_url
, video_id
, 'mp4')
210 self
._sort
_formats
(formats
)
211 info
= get_common_fields()
213 'title': video
['title'],
219 elif status
== 'ENDED':
220 raise ExtractorError(
221 'Uploading for replay. Please wait...', expected
=True)
222 elif status
== 'RESERVED':
223 raise ExtractorError('Coming soon!', expected
=True)
224 elif video
.get('exposeStatus') == 'CANCEL':
225 raise ExtractorError(
226 'We are sorry, but the live broadcast has been canceled.',
229 raise ExtractorError('Unknown status ' + status
)
232 class VLivePostIE(VLiveBaseIE
):
233 IE_NAME
= 'vlive:post'
234 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/post/(?P<id>\d-\d+)'
237 'url': 'https://www.vlive.tv/post/1-20088044',
240 'title': 'Hola estrellitas la tierra les dice hola (si era así no?) Ha...',
241 'description': 'md5:fab8a1e50e6e51608907f46c7fa4b407',
246 'url': 'https://www.vlive.tv/post/1-20087926',
249 'title': 'James Corden: And so, the baby becamos the Papa💜😭💪😭',
253 _FVIDEO_TMPL
= 'fvideo/v1.0/fvideo-%%s/%s'
255 def _real_extract(self
, url
):
256 post_id
= self
._match
_id
(url
)
258 post
= self
._call
_api
(
259 'post/v1.0/post-%s', post_id
,
260 'attachments{video},officialVideo{videoSeq},plainBody,title')
262 video_seq
= str_or_none(try_get(
263 post
, lambda x
: x
['officialVideo']['videoSeq']))
265 return self
.url_result(
266 'http://www.vlive.tv/video/' + video_seq
,
267 VLiveIE
.ie_key(), video_seq
)
269 title
= post
['title']
271 for idx
, video
in enumerate(post
['attachments']['video'].values()):
272 video_id
= video
.get('videoId')
275 upload_type
= video
.get('uploadType')
276 upload_info
= video
.get('uploadInfo') or {}
278 if upload_type
== 'SOS':
279 download
= self
._call
_api
(
280 self
._FVIDEO
_TMPL
% 'sosPlayInfo', video_id
)['videoUrl']['download']
282 for f_id
, f_url
in download
.items():
286 'height': int_or_none(f_id
[:-1]),
288 self
._sort
_formats
(formats
)
292 'thumbnail': upload_info
.get('imageUrl'),
294 elif upload_type
== 'V':
295 vod_id
= upload_info
.get('videoId')
298 inkey
= self
._call
_api
(self
._FVIDEO
_TMPL
% 'inKey', video_id
)['inKey']
299 entry
= self
._extract
_video
_info
(video_id
, vod_id
, inkey
)
301 entry
['title'] = '%s_part%s' % (title
, idx
)
302 entries
.append(entry
)
303 return self
.playlist_result(
304 entries
, post_id
, title
, strip_or_none(post
.get('plainBody')))
307 class VLiveChannelIE(VLiveBaseIE
):
308 IE_NAME
= 'vlive:channel'
309 _VALID_URL
= r
'https?://(?:channels\.vlive\.tv|(?:(?:www|m)\.)?vlive\.tv/channel)/(?P<channel_id>[0-9A-Z]+)(?:/board/(?P<posts_id>\d+))?'
311 'url': 'http://channels.vlive.tv/FCD4B',
316 'playlist_mincount': 110
318 'url': 'https://www.vlive.tv/channel/FCD4B',
319 'only_matching': True,
321 'url': 'https://www.vlive.tv/channel/FCD4B/board/3546',
324 'title': 'MAMAMOO - Star Board',
326 'playlist_mincount': 880
329 def _entries(self
, posts_id
, board_name
):
331 posts_path
= 'post/v1.0/board-%s/posts'
332 query_add
= {'limit': 100, 'sortType': 'LATEST'}
334 posts_path
= 'post/v1.0/channel-%s/starPosts'
335 query_add
= {'limit': 100}
337 for page_num
in itertools
.count(1):
338 video_list
= self
._call
_api
(
339 posts_path
, posts_id
, 'channel{channelName},contentType,postId,title,url', query_add
,
340 note
=f
'Downloading playlist page {page_num}')
342 for video
in try_get(video_list
, lambda x
: x
['data'], list) or []:
343 video_id
= str(video
.get('postId'))
344 video_title
= str_or_none(video
.get('title'))
345 video_url
= url_or_none(video
.get('url'))
346 if not all((video_id
, video_title
, video_url
)) or video
.get('contentType') != 'VIDEO':
348 channel_name
= try_get(video
, lambda x
: x
['channel']['channelName'], compat_str
)
349 yield self
.url_result(video_url
, VLivePostIE
.ie_key(), video_id
, video_title
, channel
=channel_name
)
351 after
= try_get(video_list
, lambda x
: x
['paging']['nextParams']['after'], compat_str
)
354 query_add
['after'] = after
356 def _real_extract(self
, url
):
357 channel_id
, posts_id
= self
._match
_valid
_url
(url
).groups()
361 board
= self
._call
_api
(
362 'board/v1.0/board-%s', posts_id
, 'title,boardType')
363 board_name
= board
.get('title') or 'Unknown'
364 if board
.get('boardType') not in ('STAR', 'VLIVE_PLUS'):
365 raise ExtractorError(f
'Board {board_name!r} is not supported', expected
=True)
367 entries
= LazyList(self
._entries
(posts_id
or channel_id
, board_name
))
368 channel_name
= entries
[0]['channel']
370 return self
.playlist_result(
372 f
'{channel_id}-{posts_id}' if posts_id
else channel_id
,
373 f
'{channel_name} - {board_name}' if channel_name
and board_name
else channel_name
)