3 from .common
import InfoExtractor
17 from ..utils
.traversal
import traverse_obj
20 class AfreecaTVBaseIE(InfoExtractor
):
21 _NETRC_MACHINE
= 'afreecatv'
23 def _perform_login(self
, username
, password
):
28 'szPassword': password
,
30 'szScriptVar': 'oLoginRet',
34 response
= self
._download
_json
(
35 'https://login.afreecatv.com/app/LoginAction.php', None,
36 'Logging in', data
=urlencode_postdata(login_form
))
39 -4: 'Your account has been suspended due to a violation of our terms and policies.',
40 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
41 -6: 'https://login.afreecatv.com/membership/changeMember.php',
42 -8: "Hello! AfreecaTV 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.",
43 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
44 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
45 -12: 'https://member.afreecatv.com/app/user_security.php',
46 0: 'The username does not exist or you have entered the wrong password.',
47 -1: 'The username does not exist or you have entered the wrong password.',
48 -3: 'You have entered your username/password incorrectly.',
49 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
50 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
51 -32008: 'You have failed to log in. Please contact our Help Center.',
54 result
= int_or_none(response
.get('RESULT'))
56 error
= _ERRORS
.get(result
, 'You have failed to log in.')
58 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
62 class AfreecaTVIE(AfreecaTVBaseIE
):
64 IE_DESC
= 'afreecatv.com'
68 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
70 /app/(?:index|read_ucc_bbs)\.cgi|
71 /player/[Pp]layer\.(?:swf|html)
73 vod\.afreecatv\.com/(PLAYER/STATION|player)/
78 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
79 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
83 'title': '데일리 에이프릴 요정들의 시상식!',
84 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
85 'uploader': 'dailyapril',
86 'uploader_id': 'dailyapril',
87 'upload_date': '20160503',
89 'skip': 'Video is gone',
91 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
94 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
95 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
96 'uploader': 'dailyapril',
97 'uploader_id': 'dailyapril',
101 'md5': 'd8b7c174568da61d774ef0203159bf97',
105 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
106 'upload_date': '20160502',
109 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
113 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
114 'upload_date': '20160502',
117 'skip': 'Video is gone',
120 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
122 'id': '20170411_BE689A0E_190960999_1_2_h',
125 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
127 'uploader_id': 'dasl8121',
128 'upload_date': '20170411',
129 'timestamp': 1491929865,
133 'skip_download': True,
137 'url': 'https://vod.afreecatv.com/player/97267690',
139 'id': '20180327_27901457_202289533_1',
141 'title': '[생]빨개요♥ (part 1)',
142 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
143 'uploader': '[SA]서아',
144 'uploader_id': 'bjdyrksu',
145 'upload_date': '20180327',
149 'skip_download': True,
151 'skip': 'The VOD does not exist',
153 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
154 'only_matching': True,
156 'url': 'https://vod.afreecatv.com/player/96753363',
158 'id': '20230108_9FF5BEE1_244432674_1',
160 'uploader_id': 'rlantnghks',
163 'thumbnail': r
're:https?://videoimg\.afreecatv\.com/.+',
164 'upload_date': '20230108',
165 'timestamp': 1673218805,
169 'skip_download': True,
173 'url': 'https://vod.afreecatv.com/player/70395877',
174 'only_matching': True,
177 'url': 'https://vod.afreecatv.com/player/104647403',
178 'only_matching': True,
181 'url': 'https://vod.afreecatv.com/player/81669846',
182 'only_matching': True,
185 def _real_extract(self
, url
):
186 video_id
= self
._match
_id
(url
)
187 data
= self
._download
_json
(
188 'https://api.m.afreecatv.com/station/video/a/view', video_id
,
189 headers
={'Referer': url}
, data
=urlencode_postdata({
190 'nTitleNo': video_id
,
194 error_code
= traverse_obj(data
, ('code', {int}
))
195 if error_code
== -6221:
196 raise ExtractorError('The VOD does not exist', expected
=True)
197 elif error_code
== -6205:
198 raise ExtractorError('This VOD is private', expected
=True)
200 common_info
= traverse_obj(data
, {
201 'title': ('title', {str}
),
202 'uploader': ('writer_nick', {str}
),
203 'uploader_id': ('bj_id', {str}
),
204 'duration': ('total_file_duration', {functools.partial(int_or_none, scale=1000)}
),
205 'thumbnail': ('thumb', {url_or_none}
),
209 for file_num
, file_element
in enumerate(
210 traverse_obj(data
, ('files', lambda _
, v
: url_or_none(v
['file']))), start
=1):
211 file_url
= file_element
['file']
212 if determine_ext(file_url
) == 'm3u8':
213 formats
= self
._extract
_m
3u8_formats
(
214 file_url
, video_id
, 'mp4', m3u8_id
='hls',
215 note
=f
'Downloading part {file_num} m3u8 information')
224 'id': file_element
.get('file_info_key') or f
'{video_id}_{file_num}',
225 'title': f
'{common_info.get("title") or "Untitled"} (part {file_num})',
227 **traverse_obj(file_element
, {
228 'duration': ('duration', {functools.partial(int_or_none, scale=1000)}
),
229 'timestamp': ('file_start', {unified_timestamp}
),
233 if traverse_obj(data
, ('adult_status', {str}
)) == 'notLogin':
235 self
.raise_login_required(
236 'Only users older than 19 are able to watch this video', method
='password')
238 'In accordance with local laws and regulations, underage users are '
239 'restricted from watching adult content. Only content suitable for all '
240 f
'ages will be downloaded. {self._login_hint("password")}')
242 if not entries
and traverse_obj(data
, ('sub_upload_type', {str}
)):
243 self
.raise_login_required('This VOD is for subscribers only', method
='password')
245 if len(entries
) == 1:
248 'title': common_info
.get('title'),
251 common_info
['timestamp'] = traverse_obj(entries
, (..., 'timestamp'), get_all
=False)
253 return self
.playlist_result(entries
, video_id
, multi_video
=True, **common_info
)
256 class AfreecaTVLiveIE(AfreecaTVBaseIE
):
257 IE_NAME
= 'afreecatv:live'
258 IE_DESC
= 'afreecatv.com livestreams'
259 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
261 'url': 'https://play.afreecatv.com/pyh3646/237852185',
265 'title': '【 우루과이 오늘은 무슨일이? 】',
266 'uploader': '박진우[JINU]',
267 'uploader_id': 'pyh3646',
268 'timestamp': 1640661495,
271 'skip': 'Livestream has ended',
273 'url': 'https://play.afreecatv.com/pyh3646/237852185',
274 'only_matching': True,
276 'url': 'https://play.afreecatv.com/pyh3646',
277 'only_matching': True,
280 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
282 'gcp_cdn', # live-global-cdn-v02.afreecatv.com
283 'gs_cdn_pc_app', # pc-app.stream.afreecatv.com
284 'gs_cdn_mobile_web', # mobile-web.stream.afreecatv.com
285 'gs_cdn_pc_web', # pc-web.stream.afreecatv.com
288 'gs_cdn', # chromecast.afreeca.gscdn.com (cannot resolve)
289 'gs_cdn_chromecast', # chromecast.stream.afreecatv.com (HTTP Error 400)
290 'azure_cdn', # live-global-cdn-v01.afreecatv.com (cannot resolve)
291 'aws_cf', # live-global-cdn-v03.afreecatv.com (cannot resolve)
292 'kt_cdn', # kt.stream.afreecatv.com (HTTP Error 400)
295 def _extract_formats(self
, channel_info
, broadcast_no
, aid
):
296 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
298 # If user has not passed CDN IDs, try API-provided CDN ID followed by other working CDN IDs
299 default_cdn_ids
= orderedSet([
300 *traverse_obj(channel_info
, ('CDN', {str}
, all
, lambda _
, v
: v
not in self
._BAD
_CDNS
)),
303 cdn_ids
= self
._configuration
_arg
('cdn', default_cdn_ids
)
305 for attempt
, cdn_id
in enumerate(cdn_ids
, start
=1):
306 m3u8_url
= traverse_obj(self
._download
_json
(
307 urljoin(stream_base_url
, 'broad_stream_assign.html'), broadcast_no
,
308 f
'Downloading {cdn_id} stream info', f
'Unable to download {cdn_id} stream info',
310 'return_type': cdn_id
,
311 'broad_key': f
'{broadcast_no}-common-master-hls',
312 }), ('view_url', {url_or_none}
))
314 return self
._extract
_m
3u8_formats
(
315 m3u8_url
, broadcast_no
, 'mp4', m3u8_id
='hls', query
={'aid': aid}
,
316 headers
={'Referer': 'https://play.afreecatv.com/'}
)
317 except ExtractorError
as e
:
318 if attempt
== len(cdn_ids
):
321 f
'{e.cause or e.msg}. Retrying... (attempt {attempt} of {len(cdn_ids)})')
323 def _real_extract(self
, url
):
324 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
325 channel_info
= traverse_obj(self
._download
_json
(
326 self
._LIVE
_API
_URL
, broadcaster_id
, data
=urlencode_postdata({'bid': broadcaster_id}
)),
327 ('CHANNEL', {dict}
)) or {}
329 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
330 broadcast_no
= channel_info
.get('BNO') or broadcast_no
332 raise UserNotLive(video_id
=broadcaster_id
)
334 password
= self
.get_param('videopassword')
335 if channel_info
.get('BPWD') == 'Y' and password
is None:
336 raise ExtractorError(
337 'This livestream is protected by a password, use the --video-password option',
340 token_info
= traverse_obj(self
._download
_json
(
341 self
._LIVE
_API
_URL
, broadcast_no
, 'Downloading access token for stream',
342 'Unable to download access token for stream', data
=urlencode_postdata(filter_dict({
344 'stream_type': 'common',
348 }))), ('CHANNEL', {dict}
)) or {}
349 aid
= token_info
.get('AID')
351 result
= token_info
.get('RESULT')
353 raise ExtractorError('This livestream has ended', expected
=True)
355 self
.raise_login_required('This livestream is for subscribers only', method
='password')
356 raise ExtractorError('Unable to extract access token')
358 formats
= self
._extract
_formats
(channel_info
, broadcast_no
, aid
)
360 station_info
= traverse_obj(self
._download
_json
(
361 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
362 'Downloading channel metadata', 'Unable to download channel metadata',
363 query
={'szBjId': broadcaster_id}
, fatal
=False), {dict}
) or {}
367 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
368 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
369 'uploader_id': broadcaster_id
,
370 'timestamp': unified_timestamp(station_info
.get('broad_start')),
373 'http_headers': {'Referer': url}
,
377 class AfreecaTVUserIE(InfoExtractor
):
378 IE_NAME
= 'afreecatv:user'
379 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
381 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
385 'title': 'ryuryu24 - review',
387 'playlist_count': 218,
389 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
393 'title': 'parang1995 - highlight',
395 'playlist_count': 997,
397 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
401 'title': 'ryuryu24 - all',
403 'playlist_count': 221,
405 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
409 'title': 'ryuryu24 - balloonclip',
415 def _fetch_page(self
, user_id
, user_type
, page
):
417 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
418 query
={'page': page, 'per_page': self._PER_PAGE, 'orderby': 'reg_date'}
,
419 note
=f
'Downloading {user_type} video page {page}')
420 for item
in info
['data']:
421 yield self
.url_result(
422 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
424 def _real_extract(self
, url
):
425 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
426 user_type
= user_type
or 'all'
427 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
428 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')