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 self
._sort
_formats
(formats
)
342 file_info
= common_entry
.copy()
345 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
346 'upload_date': upload_date
,
347 'duration': file_duration
,
350 entries
.append(file_info
)
351 entries_info
= info
.copy()
352 entries_info
.update({
353 '_type': 'multi_video',
361 'uploader': uploader
,
362 'uploader_id': uploader_id
,
363 'duration': duration
,
364 'thumbnail': thumbnail
,
367 if determine_ext(video_url
) == 'm3u8':
368 info
['formats'] = self
._extract
_m
3u8_formats
(
369 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
372 app
, playpath
= video_url
.split('mp4:')
376 'play_path': 'mp4:' + playpath
,
377 'rtmp_live': True, # downloading won't end without this
383 class AfreecaTVLiveIE(AfreecaTVIE
):
385 IE_NAME
= 'afreecatv:live'
386 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
388 'url': 'https://play.afreecatv.com/pyh3646/237852185',
392 'title': '【 우루과이 오늘은 무슨일이? 】',
393 'uploader': '박진우[JINU]',
394 'uploader_id': 'pyh3646',
395 'timestamp': 1640661495,
398 'skip': 'Livestream has ended',
400 'url': 'http://play.afreeca.com/pyh3646/237852185',
401 'only_matching': True,
403 'url': 'http://play.afreeca.com/pyh3646',
404 'only_matching': True,
407 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
409 _QUALITIES
= ('sd', 'hd', 'hd2k', 'original')
411 def _real_extract(self
, url
):
412 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
413 password
= self
.get_param('videopassword')
415 info
= self
._download
_json
(self
._LIVE
_API
_URL
, broadcaster_id
, fatal
=False,
416 data
=urlencode_postdata({'bid': broadcaster_id}
)) or {}
417 channel_info
= info
.get('CHANNEL') or {}
418 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
419 broadcast_no
= channel_info
.get('BNO') or broadcast_no
420 password_protected
= channel_info
.get('BPWD')
422 raise ExtractorError(f
'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected
=True)
423 if password_protected
== 'Y' and password
is None:
424 raise ExtractorError(
425 'This livestream is protected by a password, use the --video-password option',
429 quality_key
= qualities(self
._QUALITIES
)
430 for quality_str
in self
._QUALITIES
:
433 'stream_type': 'common',
435 'quality': quality_str
,
437 if password
is not None:
438 params
['pwd'] = password
439 aid_response
= self
._download
_json
(
440 self
._LIVE
_API
_URL
, broadcast_no
, fatal
=False,
441 data
=urlencode_postdata(params
),
442 note
=f
'Downloading access token for {quality_str} stream',
443 errnote
=f
'Unable to download access token for {quality_str} stream')
444 aid
= traverse_obj(aid_response
, ('CHANNEL', 'AID'))
448 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
449 stream_info
= self
._download
_json
(
450 f
'{stream_base_url}/broad_stream_assign.html', broadcast_no
, fatal
=False,
452 'return_type': channel_info
.get('CDN', 'gcp_cdn'),
453 'broad_key': f
'{broadcast_no}-common-{quality_str}-hls',
455 note
=f
'Downloading metadata for {quality_str} stream',
456 errnote
=f
'Unable to download metadata for {quality_str} stream') or {}
458 if stream_info
.get('view_url'):
460 'format_id': quality_str
,
461 'url': update_url_query(stream_info
['view_url'], {'aid': aid}
),
464 'quality': quality_key(quality_str
),
467 self
._sort
_formats
(formats
)
469 station_info
= self
._download
_json
(
470 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
471 query
={'szBjId': broadcaster_id}
, fatal
=False,
472 note
='Downloading channel metadata', errnote
='Unable to download channel metadata') or {}
476 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
477 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
478 'uploader_id': broadcaster_id
,
479 'timestamp': unified_timestamp(station_info
.get('broad_start')),
485 class AfreecaTVUserIE(InfoExtractor
):
486 IE_NAME
= 'afreecatv:user'
487 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
489 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
493 'title': 'ryuryu24 - review',
495 'playlist_count': 218,
497 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
501 'title': 'parang1995 - highlight',
503 'playlist_count': 997,
505 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
509 'title': 'ryuryu24 - all',
511 'playlist_count': 221,
513 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
517 'title': 'ryuryu24 - balloonclip',
523 def _fetch_page(self
, user_id
, user_type
, page
):
525 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
526 query
={'page': page, 'per_page': self._PER_PAGE, 'orderby': 'reg_date'}
,
527 note
=f
'Downloading {user_type} video page {page}')
528 for item
in info
['data']:
529 yield self
.url_result(
530 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
532 def _real_extract(self
, url
):
533 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
534 user_type
= user_type
or 'all'
535 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
536 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')