2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_xpath
26 class AfreecaTVIE(InfoExtractor
):
28 IE_DESC
= 'afreecatv.com'
32 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
34 /app/(?:index|read_ucc_bbs)\.cgi|
35 /player/[Pp]layer\.(?:swf|html)
37 vod\.afreecatv\.com/(PLAYER/STATION|player)/
41 _NETRC_MACHINE
= 'afreecatv'
43 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
44 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
48 'title': '데일리 에이프릴 요정들의 시상식!',
49 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
50 'uploader': 'dailyapril',
51 'uploader_id': 'dailyapril',
52 'upload_date': '20160503',
54 'skip': 'Video is gone',
56 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
59 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
60 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
61 'uploader': 'dailyapril',
62 'uploader_id': 'dailyapril',
66 'md5': 'd8b7c174568da61d774ef0203159bf97',
70 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
71 'upload_date': '20160502',
74 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
78 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
79 'upload_date': '20160502',
82 'skip': 'Video is gone',
84 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
88 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
89 'thumbnail': r
're:^https?://.*\.jpg$',
91 'uploader_id': 'badkids',
95 'skip_download': True,
98 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
101 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
102 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
103 'uploader': 'dailyapril',
104 'uploader_id': 'dailyapril',
109 'md5': 'd8b7c174568da61d774ef0203159bf97',
111 'id': '20160502_c4c62b9d_174361386_1',
113 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
114 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
115 'uploader': 'dailyapril',
116 'uploader_id': 'dailyapril',
117 'upload_date': '20160502',
121 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
123 'id': '20160502_39e739bb_174361386_2',
125 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
126 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
127 'uploader': 'dailyapril',
128 'uploader_id': 'dailyapril',
129 'upload_date': '20160502',
134 'skip_download': True,
138 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
140 'id': '20170411_BE689A0E_190960999_1_2_h',
143 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
145 'uploader_id': 'dasl8121',
146 'upload_date': '20170411',
150 'skip_download': True,
154 'url': 'http://vod.afreecatv.com/PLAYER/STATION/32028439',
156 'id': '20180327_27901457_202289533_1',
158 'title': '[생]빨개요♥ (part 1)',
159 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
160 'uploader': '[SA]서아',
161 'uploader_id': 'bjdyrksu',
162 'upload_date': '20180327',
166 'skip_download': True,
168 'expected_warnings': ['adult content'],
170 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
171 'only_matching': True,
173 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
174 'only_matching': True,
176 'url': 'http://vod.afreecatv.com/player/15055030',
177 'only_matching': True,
181 def parse_video_key(key
):
183 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
185 video_key
['upload_date'] = m
.group('upload_date')
186 video_key
['part'] = int(m
.group('part'))
189 def _perform_login(self
, username
, password
):
194 'szPassword': password
,
196 'szScriptVar': 'oLoginRet',
200 response
= self
._download
_json
(
201 'https://login.afreecatv.com/app/LoginAction.php', None,
202 'Logging in', data
=urlencode_postdata(login_form
))
205 -4: 'Your account has been suspended due to a violation of our terms and policies.',
206 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
207 -6: 'https://login.afreecatv.com/membership/changeMember.php',
208 -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.",
209 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
210 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
211 -12: 'https://member.afreecatv.com/app/user_security.php',
212 0: 'The username does not exist or you have entered the wrong password.',
213 -1: 'The username does not exist or you have entered the wrong password.',
214 -3: 'You have entered your username/password incorrectly.',
215 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
216 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
217 -32008: 'You have failed to log in. Please contact our Help Center.',
220 result
= int_or_none(response
.get('RESULT'))
222 error
= _ERRORS
.get(result
, 'You have failed to log in.')
223 raise ExtractorError(
224 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
227 def _real_extract(self
, url
):
228 video_id
= self
._match
_id
(url
)
230 webpage
= self
._download
_webpage
(url
, video_id
)
232 if re
.search(r
'alert\(["\']This video has been deleted
', webpage):
233 raise ExtractorError(
234 'Video
%s has been deleted
' % video_id, expected=True)
236 station_id = self._search_regex(
237 r'nStationNo\s
*=\s
*(\d
+)', webpage, 'station
')
238 bbs_id = self._search_regex(
239 r'nBbsNo\s
*=\s
*(\d
+)', webpage, 'bbs
')
240 video_id = self._search_regex(
241 r'nTitleNo\s
*=\s
*(\d
+)', webpage, 'title
', default=video_id)
247 'nTitleNo
': video_id,
248 'nStationNo
': station_id,
252 query['partialView
'] = 'SKIP_ADULT
'
254 query['adultView
'] = 'ADULT_VIEW
'
255 video_xml = self._download_xml(
256 'http
://afbbs
.afreecatv
.com
:8080/api
/video
/get_video_info
.php
',
257 video_id, 'Downloading video info XML
%s'
258 % (' (skipping adult
)' if partial_view else ''),
263 flag = xpath_text(video_xml, './track
/flag
', 'flag
', default=None)
264 if flag and flag == 'SUCCEED
':
266 if flag == 'PARTIAL_ADULT
':
268 'In accordance
with local laws
and regulations
, underage users are restricted
from watching adult content
. '
269 'Only content suitable
for all ages will be downloaded
. '
270 'Provide account credentials
if you wish to download restricted content
.')
273 elif flag == 'ADULT
':
277 error = 'Only users older than
19 are able to watch this video
. Provide account credentials to download this content
.'
280 raise ExtractorError(
281 '%s said
: %s' % (self.IE_NAME, error), expected=True)
283 raise ExtractorError('Unable to download video info
')
285 video_element = video_xml.findall(compat_xpath('./track
/video
'))[-1]
286 if video_element is None or video_element.text is None:
287 raise ExtractorError(
288 'Video
%s does
not exist
' % video_id, expected=True)
290 video_url = video_element.text.strip()
292 title = xpath_text(video_xml, './track
/title
', 'title
', fatal=True)
294 uploader = xpath_text(video_xml, './track
/nickname
', 'uploader
')
295 uploader_id = xpath_text(video_xml, './track
/bj_id
', 'uploader
id')
296 duration = int_or_none(xpath_text(
297 video_xml, './track
/duration
', 'duration
'))
298 thumbnail = xpath_text(video_xml, './track
/titleImage
', 'thumbnail
')
301 'uploader
': uploader,
302 'uploader_id
': uploader_id,
303 'thumbnail
': thumbnail,
306 info = common_entry.copy()
310 'duration
': duration,
315 file_elements = video_element.findall(compat_xpath('./file'))
316 one = len(file_elements) == 1
317 for file_num, file_element in enumerate(file_elements, start=1):
318 file_url = url_or_none(file_element.text)
321 key = file_element.get('key
', '')
322 upload_date = unified_strdate(self._search_regex(
323 r'^
(\d{8}
)_
', key, 'upload date
', default=None))
324 if upload_date is not None:
325 # sometimes the upload date isn't included
in the
file name
326 # instead, another random ID is, which may parse as a valid
327 # date but be wildly out of a reasonable range
328 parsed_date
= date_from_str(upload_date
)
329 if parsed_date
.year
< 2000 or parsed_date
.year
>= 2100:
331 file_duration
= int_or_none(file_element
.get('duration'))
332 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
333 if determine_ext(file_url
) == 'm3u8':
334 formats
= self
._extract
_m
3u8_formats
(
335 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
337 note
='Downloading part %d m3u8 information' % file_num
)
343 if not formats
and not self
.get_param('ignore_no_formats'):
345 self
._sort
_formats
(formats
)
346 file_info
= common_entry
.copy()
349 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
350 'upload_date': upload_date
,
351 'duration': file_duration
,
354 entries
.append(file_info
)
355 entries_info
= info
.copy()
356 entries_info
.update({
357 '_type': 'multi_video',
365 'uploader': uploader
,
366 'uploader_id': uploader_id
,
367 'duration': duration
,
368 'thumbnail': thumbnail
,
371 if determine_ext(video_url
) == 'm3u8':
372 info
['formats'] = self
._extract
_m
3u8_formats
(
373 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
376 app
, playpath
= video_url
.split('mp4:')
380 'play_path': 'mp4:' + playpath
,
381 'rtmp_live': True, # downloading won't end without this
387 class AfreecaTVLiveIE(AfreecaTVIE
):
389 IE_NAME
= 'afreecatv:live'
390 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
392 'url': 'https://play.afreecatv.com/pyh3646/237852185',
396 'title': '【 우루과이 오늘은 무슨일이? 】',
397 'uploader': '박진우[JINU]',
398 'uploader_id': 'pyh3646',
399 'timestamp': 1640661495,
402 'skip': 'Livestream has ended',
404 'url': 'http://play.afreeca.com/pyh3646/237852185',
405 'only_matching': True,
407 'url': 'http://play.afreeca.com/pyh3646',
408 'only_matching': True,
411 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
413 _QUALITIES
= ('sd', 'hd', 'hd2k', 'original')
415 def _real_extract(self
, url
):
416 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
417 password
= self
.get_param('videopassword')
419 info
= self
._download
_json
(self
._LIVE
_API
_URL
, broadcaster_id
, fatal
=False,
420 data
=urlencode_postdata({'bid': broadcaster_id}
)) or {}
421 channel_info
= info
.get('CHANNEL') or {}
422 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
423 broadcast_no
= channel_info
.get('BNO') or broadcast_no
424 password_protected
= channel_info
.get('BPWD')
426 raise ExtractorError(f
'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected
=True)
427 if password_protected
== 'Y' and password
is None:
428 raise ExtractorError(
429 'This livestream is protected by a password, use the --video-password option',
433 quality_key
= qualities(self
._QUALITIES
)
434 for quality_str
in self
._QUALITIES
:
437 'stream_type': 'common',
439 'quality': quality_str
,
441 if password
is not None:
442 params
['pwd'] = password
443 aid_response
= self
._download
_json
(
444 self
._LIVE
_API
_URL
, broadcast_no
, fatal
=False,
445 data
=urlencode_postdata(params
),
446 note
=f
'Downloading access token for {quality_str} stream',
447 errnote
=f
'Unable to download access token for {quality_str} stream')
448 aid
= traverse_obj(aid_response
, ('CHANNEL', 'AID'))
452 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
453 stream_info
= self
._download
_json
(
454 f
'{stream_base_url}/broad_stream_assign.html', broadcast_no
, fatal
=False,
456 'return_type': channel_info
.get('CDN', 'gcp_cdn'),
457 'broad_key': f
'{broadcast_no}-common-{quality_str}-hls',
459 note
=f
'Downloading metadata for {quality_str} stream',
460 errnote
=f
'Unable to download metadata for {quality_str} stream') or {}
462 if stream_info
.get('view_url'):
464 'format_id': quality_str
,
465 'url': update_url_query(stream_info
['view_url'], {'aid': aid}
),
468 'quality': quality_key(quality_str
),
471 self
._sort
_formats
(formats
)
473 station_info
= self
._download
_json
(
474 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
475 query
={'szBjId': broadcaster_id}
, fatal
=False,
476 note
='Downloading channel metadata', errnote
='Unable to download channel metadata') or {}
480 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
481 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
482 'uploader_id': broadcaster_id
,
483 'timestamp': unified_timestamp(station_info
.get('broad_start')),
489 class AfreecaTVUserIE(InfoExtractor
):
490 IE_NAME
= 'afreecatv:user'
491 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
493 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
497 'title': 'ryuryu24 - review',
499 'playlist_count': 218,
501 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
505 'title': 'parang1995 - highlight',
507 'playlist_count': 997,
509 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
513 'title': 'ryuryu24 - all',
515 'playlist_count': 221,
517 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
521 'title': 'ryuryu24 - balloonclip',
527 def _fetch_page(self
, user_id
, user_type
, page
):
529 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
530 query
={'page': page, 'per_page': self._PER_PAGE, 'orderby': 'reg_date'}
,
531 note
=f
'Downloading {user_type} video page {page}')
532 for item
in info
['data']:
533 yield self
.url_result(
534 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
536 def _real_extract(self
, url
):
537 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
538 user_type
= user_type
or 'all'
539 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
540 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')