4 from .common
import InfoExtractor
22 class AfreecaTVIE(InfoExtractor
):
24 IE_DESC
= 'afreecatv.com'
28 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
30 /app/(?:index|read_ucc_bbs)\.cgi|
31 /player/[Pp]layer\.(?:swf|html)
33 vod\.afreecatv\.com/(PLAYER/STATION|player)/
37 _NETRC_MACHINE
= 'afreecatv'
39 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
40 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
44 'title': '데일리 에이프릴 요정들의 시상식!',
45 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
46 'uploader': 'dailyapril',
47 'uploader_id': 'dailyapril',
48 'upload_date': '20160503',
50 'skip': 'Video is gone',
52 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
55 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
56 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
57 'uploader': 'dailyapril',
58 'uploader_id': 'dailyapril',
62 'md5': 'd8b7c174568da61d774ef0203159bf97',
66 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
67 'upload_date': '20160502',
70 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
74 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
75 'upload_date': '20160502',
78 'skip': 'Video is gone',
81 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
83 'id': '20170411_BE689A0E_190960999_1_2_h',
86 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
88 'uploader_id': 'dasl8121',
89 'upload_date': '20170411',
93 'skip_download': True,
97 'url': 'https://vod.afreecatv.com/player/97267690',
99 'id': '20180327_27901457_202289533_1',
101 'title': '[생]빨개요♥ (part 1)',
102 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
103 'uploader': '[SA]서아',
104 'uploader_id': 'bjdyrksu',
105 'upload_date': '20180327',
109 'skip_download': True,
111 'skip': 'The VOD does not exist',
113 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
114 'only_matching': True,
116 'url': 'https://vod.afreecatv.com/player/96753363',
118 'id': '20230108_9FF5BEE1_244432674_1',
120 'uploader_id': 'rlantnghks',
123 'thumbnail': 'http://videoimg.afreecatv.com/php/SnapshotLoad.php?rowKey=20230108_9FF5BEE1_244432674_1_r',
124 'upload_date': '20230108',
128 'skip_download': True,
133 def parse_video_key(key
):
135 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
137 video_key
['upload_date'] = m
.group('upload_date')
138 video_key
['part'] = int(m
.group('part'))
141 def _perform_login(self
, username
, password
):
146 'szPassword': password
,
148 'szScriptVar': 'oLoginRet',
152 response
= self
._download
_json
(
153 'https://login.afreecatv.com/app/LoginAction.php', None,
154 'Logging in', data
=urlencode_postdata(login_form
))
157 -4: 'Your account has been suspended due to a violation of our terms and policies.',
158 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
159 -6: 'https://login.afreecatv.com/membership/changeMember.php',
160 -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.",
161 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
162 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
163 -12: 'https://member.afreecatv.com/app/user_security.php',
164 0: 'The username does not exist or you have entered the wrong password.',
165 -1: 'The username does not exist or you have entered the wrong password.',
166 -3: 'You have entered your username/password incorrectly.',
167 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
168 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
169 -32008: 'You have failed to log in. Please contact our Help Center.',
172 result
= int_or_none(response
.get('RESULT'))
174 error
= _ERRORS
.get(result
, 'You have failed to log in.')
175 raise ExtractorError(
176 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
179 def _real_extract(self
, url
):
180 video_id
= self
._match
_id
(url
)
185 data
= self
._download
_json
(
186 'https://api.m.afreecatv.com/station/video/a/view',
187 video_id
, headers
={'Referer': url
}, data
=urlencode_postdata({
188 'nTitleNo': video_id
,
191 if traverse_obj(data
, ('code', {int}
)) == -6221:
192 raise ExtractorError('The VOD does not exist', expected
=True)
194 'nTitleNo': video_id
,
195 'nStationNo': data
['station_no'],
196 'nBbsNo': data
['bbs_no'],
199 query
['partialView'] = 'SKIP_ADULT'
201 query
['adultView'] = 'ADULT_VIEW'
202 video_xml
= self
._download
_xml
(
203 'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php',
204 video_id
, 'Downloading video info XML%s'
205 % (' (skipping adult)' if partial_view
else ''),
210 flag
= xpath_text(video_xml
, './track/flag', 'flag', default
=None)
211 if flag
and flag
== 'SUCCEED':
213 if flag
== 'PARTIAL_ADULT':
215 'In accordance with local laws and regulations, underage users are restricted from watching adult content. '
216 'Only content suitable for all ages will be downloaded. '
217 'Provide account credentials if you wish to download restricted content.')
220 elif flag
== 'ADULT':
224 error
= 'Only users older than 19 are able to watch this video. Provide account credentials to download this content.'
227 raise ExtractorError(
228 '%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
230 raise ExtractorError('Unable to download video info')
232 video_element
= video_xml
.findall('./track/video')[-1]
233 if video_element
is None or video_element
.text
is None:
234 raise ExtractorError(
235 'Video %s does not exist' % video_id
, expected
=True)
237 video_url
= video_element
.text
.strip()
239 title
= xpath_text(video_xml
, './track/title', 'title', fatal
=True)
241 uploader
= xpath_text(video_xml
, './track/nickname', 'uploader')
242 uploader_id
= xpath_text(video_xml
, './track/bj_id', 'uploader id')
243 duration
= int_or_none(xpath_text(
244 video_xml
, './track/duration', 'duration'))
245 thumbnail
= xpath_text(video_xml
, './track/titleImage', 'thumbnail')
248 'uploader': uploader
,
249 'uploader_id': uploader_id
,
250 'thumbnail': thumbnail
,
253 info
= common_entry
.copy()
257 'duration': duration
,
262 file_elements
= video_element
.findall('./file')
263 one
= len(file_elements
) == 1
264 for file_num
, file_element
in enumerate(file_elements
, start
=1):
265 file_url
= url_or_none(file_element
.text
)
268 key
= file_element
.get('key', '')
269 upload_date
= unified_strdate(self
._search
_regex
(
270 r
'^(\d{8})_', key
, 'upload date', default
=None))
271 if upload_date
is not None:
272 # sometimes the upload date isn't included in the file name
273 # instead, another random ID is, which may parse as a valid
274 # date but be wildly out of a reasonable range
275 parsed_date
= date_from_str(upload_date
)
276 if parsed_date
.year
< 2000 or parsed_date
.year
>= 2100:
278 file_duration
= int_or_none(file_element
.get('duration'))
279 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
280 if determine_ext(file_url
) == 'm3u8':
281 formats
= self
._extract
_m
3u8_formats
(
282 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
284 note
='Downloading part %d m3u8 information' % file_num
)
290 if not formats
and not self
.get_param('ignore_no_formats'):
292 file_info
= common_entry
.copy()
295 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
296 'upload_date': upload_date
,
297 'duration': file_duration
,
300 entries
.append(file_info
)
301 entries_info
= info
.copy()
302 entries_info
.update({
303 '_type': 'multi_video',
311 'uploader': uploader
,
312 'uploader_id': uploader_id
,
313 'duration': duration
,
314 'thumbnail': thumbnail
,
317 if determine_ext(video_url
) == 'm3u8':
318 info
['formats'] = self
._extract
_m
3u8_formats
(
319 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
322 app
, playpath
= video_url
.split('mp4:')
326 'play_path': 'mp4:' + playpath
,
327 'rtmp_live': True, # downloading won't end without this
333 class AfreecaTVLiveIE(AfreecaTVIE
): # XXX: Do not subclass from concrete IE
335 IE_NAME
= 'afreecatv:live'
336 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
338 'url': 'https://play.afreecatv.com/pyh3646/237852185',
342 'title': '【 우루과이 오늘은 무슨일이? 】',
343 'uploader': '박진우[JINU]',
344 'uploader_id': 'pyh3646',
345 'timestamp': 1640661495,
348 'skip': 'Livestream has ended',
350 'url': 'http://play.afreeca.com/pyh3646/237852185',
351 'only_matching': True,
353 'url': 'http://play.afreeca.com/pyh3646',
354 'only_matching': True,
357 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
359 _QUALITIES
= ('sd', 'hd', 'hd2k', 'original')
361 def _real_extract(self
, url
):
362 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
363 password
= self
.get_param('videopassword')
365 info
= self
._download
_json
(self
._LIVE
_API
_URL
, broadcaster_id
, fatal
=False,
366 data
=urlencode_postdata({'bid': broadcaster_id
})) or {}
367 channel_info
= info
.get('CHANNEL') or {}
368 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
369 broadcast_no
= channel_info
.get('BNO') or broadcast_no
370 password_protected
= channel_info
.get('BPWD')
372 raise ExtractorError(f
'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected
=True)
373 if password_protected
== 'Y' and password
is None:
374 raise ExtractorError(
375 'This livestream is protected by a password, use the --video-password option',
379 quality_key
= qualities(self
._QUALITIES
)
380 for quality_str
in self
._QUALITIES
:
383 'stream_type': 'common',
385 'quality': quality_str
,
387 if password
is not None:
388 params
['pwd'] = password
389 aid_response
= self
._download
_json
(
390 self
._LIVE
_API
_URL
, broadcast_no
, fatal
=False,
391 data
=urlencode_postdata(params
),
392 note
=f
'Downloading access token for {quality_str} stream',
393 errnote
=f
'Unable to download access token for {quality_str} stream')
394 aid
= traverse_obj(aid_response
, ('CHANNEL', 'AID'))
398 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
399 stream_info
= self
._download
_json
(
400 f
'{stream_base_url}/broad_stream_assign.html', broadcast_no
, fatal
=False,
402 'return_type': channel_info
.get('CDN', 'gcp_cdn'),
403 'broad_key': f
'{broadcast_no}-common-{quality_str}-hls',
405 note
=f
'Downloading metadata for {quality_str} stream',
406 errnote
=f
'Unable to download metadata for {quality_str} stream') or {}
408 if stream_info
.get('view_url'):
410 'format_id': quality_str
,
411 'url': update_url_query(stream_info
['view_url'], {'aid': aid
}),
414 'quality': quality_key(quality_str
),
417 station_info
= self
._download
_json
(
418 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
419 query
={'szBjId': broadcaster_id
}, fatal
=False,
420 note
='Downloading channel metadata', errnote
='Unable to download channel metadata') or {}
424 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
425 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
426 'uploader_id': broadcaster_id
,
427 'timestamp': unified_timestamp(station_info
.get('broad_start')),
433 class AfreecaTVUserIE(InfoExtractor
):
434 IE_NAME
= 'afreecatv:user'
435 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
437 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
441 'title': 'ryuryu24 - review',
443 'playlist_count': 218,
445 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
449 'title': 'parang1995 - highlight',
451 'playlist_count': 997,
453 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
457 'title': 'ryuryu24 - all',
459 'playlist_count': 221,
461 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
465 'title': 'ryuryu24 - balloonclip',
471 def _fetch_page(self
, user_id
, user_type
, page
):
473 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
474 query
={'page': page
, 'per_page': self
._PER
_PAGE
, 'orderby': 'reg_date'},
475 note
=f
'Downloading {user_type} video page {page}')
476 for item
in info
['data']:
477 yield self
.url_result(
478 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
480 def _real_extract(self
, url
):
481 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
482 user_type
= user_type
or 'all'
483 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
484 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')