3 from .common
import InfoExtractor
4 from ..networking
import Request
18 from ..utils
.traversal
import traverse_obj
21 class AfreecaTVBaseIE(InfoExtractor
):
22 _NETRC_MACHINE
= 'afreecatv'
24 def _perform_login(self
, username
, password
):
29 'szPassword': password
,
31 'szScriptVar': 'oLoginRet',
35 response
= self
._download
_json
(
36 'https://login.sooplive.co.kr/app/LoginAction.php', None,
37 'Logging in', data
=urlencode_postdata(login_form
))
40 -4: 'Your account has been suspended due to a violation of our terms and policies.',
41 -5: 'https://member.sooplive.co.kr/app/user_delete_progress.php',
42 -6: 'https://login.sooplive.co.kr/membership/changeMember.php',
43 -8: "Hello! Soop here.\nThe username you have entered belongs to \n an account that requires a legal guardian's consent. \nIf you wish to use our services without restriction, \nplease make sure to go through the necessary verification process.",
44 -9: 'https://member.sooplive.co.kr/app/pop_login_block.php',
45 -11: 'https://login.sooplive.co.kr/afreeca/second_login.php',
46 -12: 'https://member.sooplive.co.kr/app/user_security.php',
47 0: 'The username does not exist or you have entered the wrong password.',
48 -1: 'The username does not exist or you have entered the wrong password.',
49 -3: 'You have entered your username/password incorrectly.',
50 -7: 'You cannot use your Global Soop account to access Korean Soop.',
51 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
52 -32008: 'You have failed to log in. Please contact our Help Center.',
55 result
= int_or_none(response
.get('RESULT'))
57 error
= _ERRORS
.get(result
, 'You have failed to log in.')
59 f
'Unable to login: {self.IE_NAME} said: {error}',
62 def _call_api(self
, endpoint
, display_id
, data
=None, headers
=None, query
=None):
63 return self
._download
_json
(Request(
64 f
'https://api.m.sooplive.co.kr/{endpoint}',
65 data
=data
, headers
=headers
, query
=query
,
66 extensions
={'legacy_ssl': True}), display_id
,
67 'Downloading API JSON', 'Unable to download API JSON')
70 def _fixup_thumb(thumb_url
):
71 if not url_or_none(thumb_url
):
73 # Core would determine_ext as 'php' from the url, so we need to provide the real ext
74 # See: https://github.com/yt-dlp/yt-dlp/issues/11537
75 return [{'url': thumb_url
, 'ext': 'jpg'}]
78 class AfreecaTVIE(AfreecaTVBaseIE
):
80 IE_DESC
= 'sooplive.co.kr'
81 _VALID_URL
= r
'https?://vod\.(?:sooplive\.co\.kr|afreecatv\.com)/(?:PLAYER/STATION|player)/(?P<id>\d+)/?(?:$|[?#&])'
83 'url': 'https://vod.sooplive.co.kr/player/96753363',
85 'id': '20230108_9FF5BEE1_244432674_1',
87 'uploader_id': 'rlantnghks',
90 'thumbnail': r
're:https?://videoimg\.sooplive\.co/.kr/.+',
91 'upload_date': '20230108',
92 'timestamp': 1673218805,
96 'skip_download': True,
100 'url': 'http://vod.sooplive.co.kr/PLAYER/STATION/20515605',
102 'id': '20170411_BE689A0E_190960999_1_2_h',
105 'thumbnail': r
're:https?://(?:video|st)img\.sooplive\.co\.kr/.+',
107 'uploader_id': 'dasl8121',
108 'upload_date': '20170411',
109 'timestamp': 1491929865,
113 'skip_download': True,
117 'url': 'https://vod.sooplive.co.kr/player/97267690',
119 'id': '20180327_27901457_202289533_1',
121 'title': '[생]빨개요♥ (part 1)',
122 'thumbnail': r
're:https?://(?:video|st)img\.sooplive\.co\.kr/.+',
123 'uploader': '[SA]서아',
124 'uploader_id': 'bjdyrksu',
125 'upload_date': '20180327',
129 'skip_download': True,
131 'skip': 'The VOD does not exist',
134 'url': 'https://vod.sooplive.co.kr/player/70395877',
135 'only_matching': True,
138 'url': 'https://vod.sooplive.co.kr/player/104647403',
139 'only_matching': True,
142 'url': 'https://vod.sooplive.co.kr/player/81669846',
143 'only_matching': True,
146 def _real_extract(self
, url
):
147 video_id
= self
._match
_id
(url
)
148 data
= self
._call
_api
(
149 'station/video/a/view', video_id
, headers
={'Referer': url
},
150 data
=urlencode_postdata({
151 'nTitleNo': video_id
,
155 error_code
= traverse_obj(data
, ('code', {int}
))
156 if error_code
== -6221:
157 raise ExtractorError('The VOD does not exist', expected
=True)
158 elif error_code
== -6205:
159 raise ExtractorError('This VOD is private', expected
=True)
161 common_info
= traverse_obj(data
, {
162 'title': ('title', {str}
),
163 'uploader': ('writer_nick', {str}
),
164 'uploader_id': ('bj_id', {str}
),
165 'duration': ('total_file_duration', {int_or_none(scale
=1000)}),
166 'thumbnails': ('thumb', {self
._fixup
_thumb
}),
170 for file_num
, file_element
in enumerate(
171 traverse_obj(data
, ('files', lambda _
, v
: url_or_none(v
['file']))), start
=1):
172 file_url
= file_element
['file']
173 if determine_ext(file_url
) == 'm3u8':
174 formats
= self
._extract
_m
3u8_formats
(
175 file_url
, video_id
, 'mp4', m3u8_id
='hls',
176 note
=f
'Downloading part {file_num} m3u8 information')
185 'id': file_element
.get('file_info_key') or f
'{video_id}_{file_num}',
186 'title': f
'{common_info.get("title") or "Untitled"} (part {file_num})',
188 **traverse_obj(file_element
, {
189 'duration': ('duration', {int_or_none(scale
=1000)}),
190 'timestamp': ('file_start', {unified_timestamp}
),
194 if traverse_obj(data
, ('adult_status', {str}
)) == 'notLogin':
196 self
.raise_login_required(
197 'Only users older than 19 are able to watch this video', method
='password')
199 'In accordance with local laws and regulations, underage users are '
200 'restricted from watching adult content. Only content suitable for all '
201 f
'ages will be downloaded. {self._login_hint("password")}')
203 if not entries
and traverse_obj(data
, ('sub_upload_type', {str}
)):
204 self
.raise_login_required('This VOD is for subscribers only', method
='password')
206 if len(entries
) == 1:
209 'title': common_info
.get('title'),
212 common_info
['timestamp'] = traverse_obj(entries
, (..., 'timestamp'), get_all
=False)
214 return self
.playlist_result(entries
, video_id
, multi_video
=True, **common_info
)
217 class AfreecaTVCatchStoryIE(AfreecaTVBaseIE
):
218 IE_NAME
= 'soop:catchstory'
219 IE_DESC
= 'sooplive.co.kr catch story'
220 _VALID_URL
= r
'https?://vod\.(?:sooplive\.co\.kr|afreecatv\.com)/player/(?P<id>\d+)/catchstory'
222 'url': 'https://vod.sooplive.co.kr/player/103247/catchstory',
229 def _real_extract(self
, url
):
230 video_id
= self
._match
_id
(url
)
231 data
= self
._call
_api
(
232 'catchstory/a/view', video_id
, headers
={'Referer': url
},
233 query
={'aStoryListIdx': '', 'nStoryIdx': video_id
})
235 return self
.playlist_result(self
._entries
(data
), video_id
)
237 def _entries(self
, data
):
238 # 'files' is always a list with 1 element
239 yield from traverse_obj(data
, (
240 'data', lambda _
, v
: v
['story_type'] == 'catch',
241 'catch_list', lambda _
, v
: v
['files'][0]['file'], {
242 'id': ('files', 0, 'file_info_key', {str}
),
243 'url': ('files', 0, 'file', {url_or_none}
),
244 'duration': ('files', 0, 'duration', {int_or_none(scale
=1000)}),
245 'title': ('title', {str}
),
246 'uploader': ('writer_nick', {str}
),
247 'uploader_id': ('writer_id', {str}
),
248 'thumbnails': ('thumb', {self
._fixup
_thumb
}),
249 'timestamp': ('write_timestamp', {int_or_none}
),
253 class AfreecaTVLiveIE(AfreecaTVBaseIE
):
254 IE_NAME
= 'soop:live'
255 IE_DESC
= 'sooplive.co.kr livestreams'
256 _VALID_URL
= r
'https?://play\.(?:sooplive\.co\.kr|afreecatv\.com)/(?P<id>[^/?#]+)(?:/(?P<bno>\d+))?'
258 'url': 'https://play.sooplive.co.kr/pyh3646/237852185',
262 'title': '【 우루과이 오늘은 무슨일이? 】',
263 'uploader': '박진우[JINU]',
264 'uploader_id': 'pyh3646',
265 'timestamp': 1640661495,
268 'skip': 'Livestream has ended',
270 'url': 'https://play.sooplive.co.kr/pyh3646/237852185',
271 'only_matching': True,
273 'url': 'https://play.sooplive.co.kr/pyh3646',
274 'only_matching': True,
277 _LIVE_API_URL
= 'https://live.sooplive.co.kr/afreeca/player_live_api.php'
279 'gcp_cdn', # live-global-cdn-v02.sooplive.co.kr
280 'gs_cdn_pc_app', # pc-app.stream.sooplive.co.kr
281 'gs_cdn_mobile_web', # mobile-web.stream.sooplive.co.kr
282 'gs_cdn_pc_web', # pc-web.stream.sooplive.co.kr
285 'gs_cdn', # chromecast.afreeca.gscdn.com (cannot resolve)
286 'gs_cdn_chromecast', # chromecast.stream.sooplive.co.kr (HTTP Error 400)
287 'azure_cdn', # live-global-cdn-v01.sooplive.co.kr (cannot resolve)
288 'aws_cf', # live-global-cdn-v03.sooplive.co.kr (cannot resolve)
289 'kt_cdn', # kt.stream.sooplive.co.kr (HTTP Error 400)
292 def _extract_formats(self
, channel_info
, broadcast_no
, aid
):
293 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.sooplive.co.kr'
295 # If user has not passed CDN IDs, try API-provided CDN ID followed by other working CDN IDs
296 default_cdn_ids
= orderedSet([
297 *traverse_obj(channel_info
, ('CDN', {str}
, all
, lambda _
, v
: v
not in self
._BAD
_CDNS
)),
300 cdn_ids
= self
._configuration
_arg
('cdn', default_cdn_ids
)
302 for attempt
, cdn_id
in enumerate(cdn_ids
, start
=1):
303 m3u8_url
= traverse_obj(self
._download
_json
(
304 urljoin(stream_base_url
, 'broad_stream_assign.html'), broadcast_no
,
305 f
'Downloading {cdn_id} stream info', f
'Unable to download {cdn_id} stream info',
307 'return_type': cdn_id
,
308 'broad_key': f
'{broadcast_no}-common-master-hls',
309 }), ('view_url', {url_or_none}
))
311 return self
._extract
_m
3u8_formats
(
312 m3u8_url
, broadcast_no
, 'mp4', m3u8_id
='hls', query
={'aid': aid
},
313 headers
={'Referer': 'https://play.sooplive.co.kr/'})
314 except ExtractorError
as e
:
315 if attempt
== len(cdn_ids
):
318 f
'{e.cause or e.msg}. Retrying... (attempt {attempt} of {len(cdn_ids)})')
320 def _real_extract(self
, url
):
321 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
322 channel_info
= traverse_obj(self
._download
_json
(
323 self
._LIVE
_API
_URL
, broadcaster_id
, data
=urlencode_postdata({'bid': broadcaster_id
})),
324 ('CHANNEL', {dict}
)) or {}
326 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
327 broadcast_no
= channel_info
.get('BNO') or broadcast_no
329 result
= channel_info
.get('RESULT')
331 raise UserNotLive(video_id
=broadcaster_id
)
333 self
.raise_login_required(
334 'This channel is streaming for subscribers only', method
='password')
335 raise ExtractorError('Unable to extract broadcast number')
337 password
= self
.get_param('videopassword')
338 if channel_info
.get('BPWD') == 'Y' and password
is None:
339 raise ExtractorError(
340 'This livestream is protected by a password, use the --video-password option',
343 token_info
= traverse_obj(self
._download
_json
(
344 self
._LIVE
_API
_URL
, broadcast_no
, 'Downloading access token for stream',
345 'Unable to download access token for stream', data
=urlencode_postdata(filter_dict({
347 'stream_type': 'common',
351 }))), ('CHANNEL', {dict}
)) or {}
352 aid
= token_info
.get('AID')
354 result
= token_info
.get('RESULT')
356 raise ExtractorError('This livestream has ended', expected
=True)
358 self
.raise_login_required('This livestream is for subscribers only', method
='password')
359 raise ExtractorError('Unable to extract access token')
361 formats
= self
._extract
_formats
(channel_info
, broadcast_no
, aid
)
363 station_info
= traverse_obj(self
._download
_json
(
364 'https://st.sooplive.co.kr/api/get_station_status.php', broadcast_no
,
365 'Downloading channel metadata', 'Unable to download channel metadata',
366 query
={'szBjId': broadcaster_id
}, fatal
=False), {dict}
) or {}
370 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
371 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
372 'uploader_id': broadcaster_id
,
373 'timestamp': unified_timestamp(station_info
.get('broad_start')),
376 'http_headers': {'Referer': url
},
380 class AfreecaTVUserIE(AfreecaTVBaseIE
):
381 IE_NAME
= 'soop:user'
382 _VALID_URL
= r
'https?://ch\.(?:sooplive\.co\.kr|afreecatv\.com)/(?P<id>[^/?#]+)/vods/?(?P<slug_type>[^/?#]+)?'
384 'url': 'https://ch.sooplive.co.kr/ryuryu24/vods/review',
388 'title': 'ryuryu24 - review',
390 'playlist_count': 218,
392 'url': 'https://ch.sooplive.co.kr/parang1995/vods/highlight',
396 'title': 'parang1995 - highlight',
398 'playlist_count': 997,
400 'url': 'https://ch.sooplive.co.kr/ryuryu24/vods',
404 'title': 'ryuryu24 - all',
406 'playlist_count': 221,
408 'url': 'https://ch.sooplive.co.kr/ryuryu24/vods/balloonclip',
412 'title': 'ryuryu24 - balloonclip',
418 def _fetch_page(self
, user_id
, user_type
, page
):
420 info
= self
._download
_json
(f
'https://chapi.sooplive.co.kr/api/{user_id}/vods/{user_type}', user_id
,
421 query
={'page': page
, 'per_page': self
._PER
_PAGE
, 'orderby': 'reg_date'},
422 note
=f
'Downloading {user_type} video page {page}')
423 for item
in info
['data']:
424 yield self
.url_result(
425 f
'https://vod.sooplive.co.kr/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
427 def _real_extract(self
, url
):
428 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
429 user_type
= user_type
or 'all'
430 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
431 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')