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',
80 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
84 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
85 'thumbnail': r
're:^https?://.*\.jpg$',
87 'uploader_id': 'badkids',
91 'skip_download': True,
94 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
97 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
98 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
99 'uploader': 'dailyapril',
100 'uploader_id': 'dailyapril',
105 'md5': 'd8b7c174568da61d774ef0203159bf97',
107 'id': '20160502_c4c62b9d_174361386_1',
109 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
110 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
111 'uploader': 'dailyapril',
112 'uploader_id': 'dailyapril',
113 'upload_date': '20160502',
117 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
119 'id': '20160502_39e739bb_174361386_2',
121 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
122 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
123 'uploader': 'dailyapril',
124 'uploader_id': 'dailyapril',
125 'upload_date': '20160502',
130 'skip_download': True,
134 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
136 'id': '20170411_BE689A0E_190960999_1_2_h',
139 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
141 'uploader_id': 'dasl8121',
142 'upload_date': '20170411',
146 'skip_download': True,
150 'url': 'http://vod.afreecatv.com/PLAYER/STATION/32028439',
152 'id': '20180327_27901457_202289533_1',
154 'title': '[생]빨개요♥ (part 1)',
155 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
156 'uploader': '[SA]서아',
157 'uploader_id': 'bjdyrksu',
158 'upload_date': '20180327',
162 'skip_download': True,
164 'expected_warnings': ['adult content'],
166 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
167 'only_matching': True,
169 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
170 'only_matching': True,
172 'url': 'http://vod.afreecatv.com/player/15055030',
173 'only_matching': True,
177 def parse_video_key(key
):
179 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
181 video_key
['upload_date'] = m
.group('upload_date')
182 video_key
['part'] = int(m
.group('part'))
185 def _perform_login(self
, username
, password
):
190 'szPassword': password
,
192 'szScriptVar': 'oLoginRet',
196 response
= self
._download
_json
(
197 'https://login.afreecatv.com/app/LoginAction.php', None,
198 'Logging in', data
=urlencode_postdata(login_form
))
201 -4: 'Your account has been suspended due to a violation of our terms and policies.',
202 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
203 -6: 'https://login.afreecatv.com/membership/changeMember.php',
204 -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.",
205 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
206 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
207 -12: 'https://member.afreecatv.com/app/user_security.php',
208 0: 'The username does not exist or you have entered the wrong password.',
209 -1: 'The username does not exist or you have entered the wrong password.',
210 -3: 'You have entered your username/password incorrectly.',
211 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
212 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
213 -32008: 'You have failed to log in. Please contact our Help Center.',
216 result
= int_or_none(response
.get('RESULT'))
218 error
= _ERRORS
.get(result
, 'You have failed to log in.')
219 raise ExtractorError(
220 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
223 def _real_extract(self
, url
):
224 video_id
= self
._match
_id
(url
)
226 webpage
= self
._download
_webpage
(url
, video_id
)
228 if re
.search(r
'alert\(["\']This video has been deleted
', webpage):
229 raise ExtractorError(
230 'Video
%s has been deleted
' % video_id, expected=True)
232 station_id = self._search_regex(
233 r'nStationNo\s
*=\s
*(\d
+)', webpage, 'station
')
234 bbs_id = self._search_regex(
235 r'nBbsNo\s
*=\s
*(\d
+)', webpage, 'bbs
')
236 video_id = self._search_regex(
237 r'nTitleNo\s
*=\s
*(\d
+)', webpage, 'title
', default=video_id)
243 'nTitleNo
': video_id,
244 'nStationNo
': station_id,
248 query['partialView
'] = 'SKIP_ADULT
'
250 query['adultView
'] = 'ADULT_VIEW
'
251 video_xml = self._download_xml(
252 'http
://afbbs
.afreecatv
.com
:8080/api
/video
/get_video_info
.php
',
253 video_id, 'Downloading video info XML
%s'
254 % (' (skipping adult
)' if partial_view else ''),
259 flag = xpath_text(video_xml, './track
/flag
', 'flag
', default=None)
260 if flag and flag == 'SUCCEED
':
262 if flag == 'PARTIAL_ADULT
':
264 'In accordance
with local laws
and regulations
, underage users are restricted
from watching adult content
. '
265 'Only content suitable
for all ages will be downloaded
. '
266 'Provide account credentials
if you wish to download restricted content
.')
269 elif flag == 'ADULT
':
273 error = 'Only users older than
19 are able to watch this video
. Provide account credentials to download this content
.'
276 raise ExtractorError(
277 '%s said
: %s' % (self.IE_NAME, error), expected=True)
279 raise ExtractorError('Unable to download video info
')
281 video_element = video_xml.findall('./track
/video
')[-1]
282 if video_element is None or video_element.text is None:
283 raise ExtractorError(
284 'Video
%s does
not exist
' % video_id, expected=True)
286 video_url = video_element.text.strip()
288 title = xpath_text(video_xml, './track
/title
', 'title
', fatal=True)
290 uploader = xpath_text(video_xml, './track
/nickname
', 'uploader
')
291 uploader_id = xpath_text(video_xml, './track
/bj_id
', 'uploader
id')
292 duration = int_or_none(xpath_text(
293 video_xml, './track
/duration
', 'duration
'))
294 thumbnail = xpath_text(video_xml, './track
/titleImage
', 'thumbnail
')
297 'uploader
': uploader,
298 'uploader_id
': uploader_id,
299 'thumbnail
': thumbnail,
302 info = common_entry.copy()
306 'duration
': duration,
311 file_elements = video_element.findall('./file')
312 one = len(file_elements) == 1
313 for file_num, file_element in enumerate(file_elements, start=1):
314 file_url = url_or_none(file_element.text)
317 key = file_element.get('key
', '')
318 upload_date = unified_strdate(self._search_regex(
319 r'^
(\d{8}
)_
', key, 'upload date
', default=None))
320 if upload_date is not None:
321 # sometimes the upload date isn't included
in the
file name
322 # instead, another random ID is, which may parse as a valid
323 # date but be wildly out of a reasonable range
324 parsed_date
= date_from_str(upload_date
)
325 if parsed_date
.year
< 2000 or parsed_date
.year
>= 2100:
327 file_duration
= int_or_none(file_element
.get('duration'))
328 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
329 if determine_ext(file_url
) == 'm3u8':
330 formats
= self
._extract
_m
3u8_formats
(
331 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
333 note
='Downloading part %d m3u8 information' % file_num
)
339 if not formats
and not self
.get_param('ignore_no_formats'):
341 file_info
= common_entry
.copy()
344 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
345 'upload_date': upload_date
,
346 'duration': file_duration
,
349 entries
.append(file_info
)
350 entries_info
= info
.copy()
351 entries_info
.update({
352 '_type': 'multi_video',
360 'uploader': uploader
,
361 'uploader_id': uploader_id
,
362 'duration': duration
,
363 'thumbnail': thumbnail
,
366 if determine_ext(video_url
) == 'm3u8':
367 info
['formats'] = self
._extract
_m
3u8_formats
(
368 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
371 app
, playpath
= video_url
.split('mp4:')
375 'play_path': 'mp4:' + playpath
,
376 'rtmp_live': True, # downloading won't end without this
382 class AfreecaTVLiveIE(AfreecaTVIE
): # XXX: Do not subclass from concrete IE
384 IE_NAME
= 'afreecatv:live'
385 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
387 'url': 'https://play.afreecatv.com/pyh3646/237852185',
391 'title': '【 우루과이 오늘은 무슨일이? 】',
392 'uploader': '박진우[JINU]',
393 'uploader_id': 'pyh3646',
394 'timestamp': 1640661495,
397 'skip': 'Livestream has ended',
399 'url': 'http://play.afreeca.com/pyh3646/237852185',
400 'only_matching': True,
402 'url': 'http://play.afreeca.com/pyh3646',
403 'only_matching': True,
406 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
408 _QUALITIES
= ('sd', 'hd', 'hd2k', 'original')
410 def _real_extract(self
, url
):
411 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
412 password
= self
.get_param('videopassword')
414 info
= self
._download
_json
(self
._LIVE
_API
_URL
, broadcaster_id
, fatal
=False,
415 data
=urlencode_postdata({'bid': broadcaster_id}
)) or {}
416 channel_info
= info
.get('CHANNEL') or {}
417 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
418 broadcast_no
= channel_info
.get('BNO') or broadcast_no
419 password_protected
= channel_info
.get('BPWD')
421 raise ExtractorError(f
'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected
=True)
422 if password_protected
== 'Y' and password
is None:
423 raise ExtractorError(
424 'This livestream is protected by a password, use the --video-password option',
428 quality_key
= qualities(self
._QUALITIES
)
429 for quality_str
in self
._QUALITIES
:
432 'stream_type': 'common',
434 'quality': quality_str
,
436 if password
is not None:
437 params
['pwd'] = password
438 aid_response
= self
._download
_json
(
439 self
._LIVE
_API
_URL
, broadcast_no
, fatal
=False,
440 data
=urlencode_postdata(params
),
441 note
=f
'Downloading access token for {quality_str} stream',
442 errnote
=f
'Unable to download access token for {quality_str} stream')
443 aid
= traverse_obj(aid_response
, ('CHANNEL', 'AID'))
447 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
448 stream_info
= self
._download
_json
(
449 f
'{stream_base_url}/broad_stream_assign.html', broadcast_no
, fatal
=False,
451 'return_type': channel_info
.get('CDN', 'gcp_cdn'),
452 'broad_key': f
'{broadcast_no}-common-{quality_str}-hls',
454 note
=f
'Downloading metadata for {quality_str} stream',
455 errnote
=f
'Unable to download metadata for {quality_str} stream') or {}
457 if stream_info
.get('view_url'):
459 'format_id': quality_str
,
460 'url': update_url_query(stream_info
['view_url'], {'aid': aid}
),
463 'quality': quality_key(quality_str
),
466 station_info
= self
._download
_json
(
467 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
468 query
={'szBjId': broadcaster_id}
, fatal
=False,
469 note
='Downloading channel metadata', errnote
='Unable to download channel metadata') or {}
473 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
474 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
475 'uploader_id': broadcaster_id
,
476 'timestamp': unified_timestamp(station_info
.get('broad_start')),
482 class AfreecaTVUserIE(InfoExtractor
):
483 IE_NAME
= 'afreecatv:user'
484 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
486 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
490 'title': 'ryuryu24 - review',
492 'playlist_count': 218,
494 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
498 'title': 'parang1995 - highlight',
500 'playlist_count': 997,
502 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
506 'title': 'ryuryu24 - all',
508 'playlist_count': 221,
510 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
514 'title': 'ryuryu24 - balloonclip',
520 def _fetch_page(self
, user_id
, user_type
, page
):
522 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
523 query
={'page': page, 'per_page': self._PER_PAGE, 'orderby': 'reg_date'}
,
524 note
=f
'Downloading {user_type} video page {page}')
525 for item
in info
['data']:
526 yield self
.url_result(
527 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
529 def _real_extract(self
, url
):
530 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
531 user_type
= user_type
or 'all'
532 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
533 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')