]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vlive.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from .naver
import NaverBaseIE
10 from ..compat
import compat_str
20 class VLiveIE(NaverBaseIE
):
22 _VALID_URL
= r
'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
23 _NETRC_MACHINE
= 'vlive'
25 'url': 'http://www.vlive.tv/video/1326',
26 'md5': 'cc7314812855ce56de70a06a27314983',
30 'title': "[V LIVE] Girl's Day's Broadcast",
31 'creator': "Girl's Day",
33 'uploader_id': 'muploader_a',
36 'url': 'http://www.vlive.tv/video/16937',
40 'title': '[V LIVE] 첸백시 걍방',
43 'subtitles': 'mincount:12',
44 'uploader_id': 'muploader_j',
47 'skip_download': True,
50 'url': 'https://www.vlive.tv/video/129100',
51 'md5': 'ca2569453b79d66e5b919e5d308bff6b',
55 'title': '[V LIVE] [BTS+] Run BTS! 2019 - EP.71 :: Behind the scene',
58 'subtitles': 'mincount:10',
60 'skip': 'This video is only available for CH+ subscribers',
64 def suitable(cls
, url
):
65 return False if VLivePlaylistIE
.suitable(url
) else super(VLiveIE
, cls
).suitable(url
)
67 def _real_initialize(self
):
71 email
, password
= self
._get
_login
_info
()
72 if None in (email
, password
):
76 login_info
= self
._download
_json
(
77 'https://www.vlive.tv/auth/loginInfo', None,
78 note
='Downloading login info',
79 headers
={'Referer': 'https://www.vlive.tv/home'})
81 login_info
, lambda x
: x
['message']['login'], bool) or False
83 LOGIN_URL
= 'https://www.vlive.tv/auth/email/login'
84 self
._request
_webpage
(
85 LOGIN_URL
, None, note
='Downloading login cookies')
87 self
._download
_webpage
(
88 LOGIN_URL
, None, note
='Logging in',
89 data
=urlencode_postdata({'email': email
, 'pwd': password
}),
92 'Content-Type': 'application/x-www-form-urlencoded'
95 if not is_logged_in():
96 raise ExtractorError('Unable to log in', expected
=True)
98 def _real_extract(self
, url
):
99 video_id
= self
._match
_id
(url
)
101 webpage
= self
._download
_webpage
(
102 'https://www.vlive.tv/video/%s' % video_id
, video_id
)
104 VIDEO_PARAMS_RE
= r
'\bvlive\.video\.init\(([^)]+)'
105 VIDEO_PARAMS_FIELD
= 'video params'
107 params
= self
._parse
_json
(self
._search
_regex
(
108 VIDEO_PARAMS_RE
, webpage
, VIDEO_PARAMS_FIELD
, default
=''), video_id
,
109 transform_source
=lambda s
: '[' + s
+ ']', fatal
=False)
111 if not params
or len(params
) < 7:
112 params
= self
._search
_regex
(
113 VIDEO_PARAMS_RE
, webpage
, VIDEO_PARAMS_FIELD
)
114 params
= [p
.strip(r
'"') for p
in re
.split(r
'\s*,\s*', params
)]
116 status
, long_video_id
, key
= params
[2], params
[5], params
[6]
117 status
= remove_start(status
, 'PRODUCT_')
119 if status
in ('LIVE_ON_AIR', 'BIG_EVENT_ON_AIR'):
120 return self
._live
(video_id
, webpage
)
121 elif status
in ('VOD_ON_AIR', 'BIG_EVENT_INTRO'):
122 return self
._replay
(video_id
, webpage
, long_video_id
, key
)
124 if status
== 'LIVE_END':
125 raise ExtractorError('Uploading for replay. Please wait...',
127 elif status
== 'COMING_SOON':
128 raise ExtractorError('Coming soon!', expected
=True)
129 elif status
== 'CANCELED':
130 raise ExtractorError('We are sorry, '
131 'but the live broadcast has been canceled.',
133 elif status
== 'ONLY_APP':
134 raise ExtractorError('Unsupported video type', expected
=True)
136 raise ExtractorError('Unknown status %s' % status
)
138 def _get_common_fields(self
, webpage
):
139 title
= self
._og
_search
_title
(webpage
)
140 creator
= self
._html
_search
_regex
(
141 r
'<div[^>]+class="info_area"[^>]*>\s*(?:<em[^>]*>.*?</em\s*>\s*)?<a\s+[^>]*>([^<]+)',
142 webpage
, 'creator', fatal
=False)
143 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
147 'thumbnail': thumbnail
,
150 def _live(self
, video_id
, webpage
):
151 init_page
= self
._download
_init
_page
(video_id
)
153 live_params
= self
._search
_regex
(
154 r
'"liveStreamInfo"\s*:\s*(".*"),',
155 init_page
, 'live stream info')
156 live_params
= self
._parse
_json
(live_params
, video_id
)
157 live_params
= self
._parse
_json
(live_params
, video_id
)
160 for vid
in live_params
.get('resolutions', []):
161 formats
.extend(self
._extract
_m
3u8_formats
(
162 vid
['cdnUrl'], video_id
, 'mp4',
163 m3u8_id
=vid
.get('name'),
164 fatal
=False, live
=True))
165 self
._sort
_formats
(formats
)
167 info
= self
._get
_common
_fields
(webpage
)
169 'title': self
._live
_title
(info
['title']),
176 def _replay(self
, video_id
, webpage
, long_video_id
, key
):
177 if '' in (long_video_id
, key
):
178 init_page
= self
._download
_init
_page
(video_id
)
179 video_info
= self
._parse
_json
(self
._search
_regex
(
180 (r
'(?s)oVideoStatus\s*=\s*({.+?})\s*</script',
181 r
'(?s)oVideoStatus\s*=\s*({.+})'), init_page
, 'video info'),
183 if video_info
.get('status') == 'NEED_CHANNEL_PLUS':
184 self
.raise_login_required(
185 'This video is only available for CH+ subscribers')
186 long_video_id
, key
= video_info
['vid'], video_info
['inkey']
189 self
._get
_common
_fields
(webpage
),
190 self
._extract
_video
_info
(video_id
, long_video_id
, key
))
192 def _download_init_page(self
, video_id
):
193 return self
._download
_webpage
(
194 'https://www.vlive.tv/video/init/view',
195 video_id
, note
='Downloading live webpage',
196 data
=urlencode_postdata({'videoSeq': video_id
}),
198 'Referer': 'https://www.vlive.tv/video/%s' % video_id
,
199 'Content-Type': 'application/x-www-form-urlencoded'
203 class VLiveChannelIE(InfoExtractor
):
204 IE_NAME
= 'vlive:channel'
205 _VALID_URL
= r
'https?://channels\.vlive\.tv/(?P<id>[0-9A-Z]+)'
207 'url': 'http://channels.vlive.tv/FCD4B',
212 'playlist_mincount': 110
214 _APP_ID
= '8c6cc7b45d2568fb668be6e05b6e5a3b'
216 def _real_extract(self
, url
):
217 channel_code
= self
._match
_id
(url
)
219 webpage
= self
._download
_webpage
(
220 'http://channels.vlive.tv/%s/video' % channel_code
, channel_code
)
224 app_js_url
= self
._search
_regex
(
225 r
'<script[^>]+src=(["\'])(?P
<url
>http
.+?
/app\
.js
.*?
)\
1',
226 webpage, 'app js
', default=None, group='url
')
229 app_js = self._download_webpage(
230 app_js_url, channel_code, 'Downloading app JS
', fatal=False)
232 app_id = self._search_regex(
233 r'Global\
.VFAN_APP_ID\s
*=\s
*[\'"]([^\'"]+)[\'"]',
234 app_js, 'app id', default=None)
236 app_id = app_id or self._APP_ID
238 channel_info = self._download_json(
239 'http://api.vfan.vlive.tv/vproxy/channelplus/decodeChannelCode',
240 channel_code, note='Downloading decode channel code',
243 'channelCode': channel_code,
244 '_': int(time.time())
247 channel_seq = channel_info['result']['channelSeq']
251 for page_num in itertools.count(1):
252 video_list = self._download_json(
253 'http://api.vfan.vlive.tv/vproxy/channelplus/getChannelVideoList',
254 channel_code, note='Downloading channel list page #%d' % page_num,
257 'channelSeq': channel_seq,
258 # Large values of maxNumOfRows (~300 or above) may cause
259 # empty responses (see [1]), e.g. this happens for [2] that
260 # has more than 300 videos.
261 # 1. https://github.com/ytdl-org/youtube-dl/issues/13830
262 # 2. http://channels.vlive.tv/EDBF.
264 '_': int(time.time()),
270 channel_name = try_get(
272 lambda x: x['result']['channelInfo']['channelName'],
276 video_list, lambda x: x['result']['videoList'], list)
281 video_id = video.get('videoSeq')
284 video_id = compat_str(video_id)
287 'http://www.vlive.tv/video/%s' % video_id,
288 ie=VLiveIE.ie_key(), video_id=video_id))
290 return self.playlist_result(
291 entries, channel_code, channel_name)
294 class VLivePlaylistIE(InfoExtractor):
295 IE_NAME = 'vlive:playlist'
296 _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<video_id>[0-9]+)/playlist/(?P<id>[0-9]+)'
297 _VIDEO_URL_TEMPLATE = 'http://www.vlive.tv/video/%s'
299 # regular working playlist
300 'url': 'https://www.vlive.tv/video/117956/playlist/117963',
303 'title': '아이돌룸(IDOL ROOM) 41회 - (여자)아이들'
305 'playlist_mincount': 10
307 # playlist with no playlistVideoSeqs
308 'url': 'http://www.vlive.tv/video/22867/playlist/22912',
312 'title': '[V LIVE] Valentine Day Message from MINA',
317 'skip_download': True,
321 def _build_video_result(self, video_id, message):
322 self.to_screen(message)
323 return self.url_result(
324 self._VIDEO_URL_TEMPLATE % video_id,
325 ie=VLiveIE.ie_key(), video_id=video_id)
327 def _real_extract(self, url):
328 mobj = re.match(self._VALID_URL, url)
329 video_id, playlist_id = mobj.group('video_id', 'id')
331 if self._downloader.params.get('noplaylist'):
332 return self._build_video_result(
334 'Downloading just video %s because of --no-playlist'
338 'Downloading playlist %s - add --no-playlist to just download video'
341 webpage = self._download_webpage(
342 'http://www.vlive.tv/video/%s/playlist/%s'
343 % (video_id, playlist_id), playlist_id)
345 raw_item_ids = self._search_regex(
346 r'playlistVideoSeqs\s*=\s*(\[[^]]+\])', webpage,
347 'playlist video seqs', default=None, fatal=False)
350 return self._build_video_result(
352 'Downloading just video %s because no playlist was found'
355 item_ids = self._parse_json(raw_item_ids, playlist_id)
359 self._VIDEO_URL_TEMPLATE % item_id, ie=VLiveIE.ie_key(),
360 video_id=compat_str(item_id))
361 for item_id in item_ids]
363 playlist_name = self._html_search_regex(
364 r'<div[^>]+class="[^
"]*multicam_playlist[^>]*>\s*<h3[^>]+>([^<]+)',
365 webpage, 'playlist title', fatal=False)
367 return self.playlist_result(entries, playlist_id, playlist_name)