2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
25 class AfreecaTVIE(InfoExtractor
):
27 IE_DESC
= 'afreecatv.com'
31 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
33 /app/(?:index|read_ucc_bbs)\.cgi|
34 /player/[Pp]layer\.(?:swf|html)
36 vod\.afreecatv\.com/(PLAYER/STATION|player)/
40 _NETRC_MACHINE
= 'afreecatv'
42 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
43 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
47 'title': '데일리 에이프릴 요정들의 시상식!',
48 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
49 'uploader': 'dailyapril',
50 'uploader_id': 'dailyapril',
51 'upload_date': '20160503',
53 'skip': 'Video is gone',
55 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
58 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
59 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
60 'uploader': 'dailyapril',
61 'uploader_id': 'dailyapril',
65 'md5': 'd8b7c174568da61d774ef0203159bf97',
69 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
70 'upload_date': '20160502',
73 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
77 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
78 'upload_date': '20160502',
81 'skip': 'Video is gone',
83 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
87 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
88 'thumbnail': r
're:^https?://.*\.jpg$',
90 'uploader_id': 'badkids',
94 'skip_download': True,
97 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
100 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
101 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
102 'uploader': 'dailyapril',
103 'uploader_id': 'dailyapril',
108 'md5': 'd8b7c174568da61d774ef0203159bf97',
110 'id': '20160502_c4c62b9d_174361386_1',
112 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
113 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
114 'uploader': 'dailyapril',
115 'uploader_id': 'dailyapril',
116 'upload_date': '20160502',
120 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
122 'id': '20160502_39e739bb_174361386_2',
124 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
125 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
126 'uploader': 'dailyapril',
127 'uploader_id': 'dailyapril',
128 'upload_date': '20160502',
133 'skip_download': True,
137 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
139 'id': '20170411_BE689A0E_190960999_1_2_h',
142 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
144 'uploader_id': 'dasl8121',
145 'upload_date': '20170411',
149 'skip_download': True,
153 'url': 'http://vod.afreecatv.com/PLAYER/STATION/32028439',
155 'id': '20180327_27901457_202289533_1',
157 'title': '[생]빨개요♥ (part 1)',
158 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
159 'uploader': '[SA]서아',
160 'uploader_id': 'bjdyrksu',
161 'upload_date': '20180327',
165 'skip_download': True,
167 'expected_warnings': ['adult content'],
169 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
170 'only_matching': True,
172 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
173 'only_matching': True,
175 'url': 'http://vod.afreecatv.com/player/15055030',
176 'only_matching': True,
180 def parse_video_key(key
):
182 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
184 video_key
['upload_date'] = m
.group('upload_date')
185 video_key
['part'] = int(m
.group('part'))
188 def _perform_login(self
, username
, password
):
193 'szPassword': password
,
195 'szScriptVar': 'oLoginRet',
199 response
= self
._download
_json
(
200 'https://login.afreecatv.com/app/LoginAction.php', None,
201 'Logging in', data
=urlencode_postdata(login_form
))
204 -4: 'Your account has been suspended due to a violation of our terms and policies.',
205 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
206 -6: 'https://login.afreecatv.com/membership/changeMember.php',
207 -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.",
208 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
209 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
210 -12: 'https://member.afreecatv.com/app/user_security.php',
211 0: 'The username does not exist or you have entered the wrong password.',
212 -1: 'The username does not exist or you have entered the wrong password.',
213 -3: 'You have entered your username/password incorrectly.',
214 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
215 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
216 -32008: 'You have failed to log in. Please contact our Help Center.',
219 result
= int_or_none(response
.get('RESULT'))
221 error
= _ERRORS
.get(result
, 'You have failed to log in.')
222 raise ExtractorError(
223 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
226 def _real_extract(self
, url
):
227 video_id
= self
._match
_id
(url
)
229 webpage
= self
._download
_webpage
(url
, video_id
)
231 if re
.search(r
'alert\(["\']This video has been deleted
', webpage):
232 raise ExtractorError(
233 'Video
%s has been deleted
' % video_id, expected=True)
235 station_id = self._search_regex(
236 r'nStationNo\s
*=\s
*(\d
+)', webpage, 'station
')
237 bbs_id = self._search_regex(
238 r'nBbsNo\s
*=\s
*(\d
+)', webpage, 'bbs
')
239 video_id = self._search_regex(
240 r'nTitleNo\s
*=\s
*(\d
+)', webpage, 'title
', default=video_id)
246 'nTitleNo
': video_id,
247 'nStationNo
': station_id,
251 query['partialView
'] = 'SKIP_ADULT
'
253 query['adultView
'] = 'ADULT_VIEW
'
254 video_xml = self._download_xml(
255 'http
://afbbs
.afreecatv
.com
:8080/api
/video
/get_video_info
.php
',
256 video_id, 'Downloading video info XML
%s'
257 % (' (skipping adult
)' if partial_view else ''),
262 flag = xpath_text(video_xml, './track
/flag
', 'flag
', default=None)
263 if flag and flag == 'SUCCEED
':
265 if flag == 'PARTIAL_ADULT
':
267 'In accordance
with local laws
and regulations
, underage users are restricted
from watching adult content
. '
268 'Only content suitable
for all ages will be downloaded
. '
269 'Provide account credentials
if you wish to download restricted content
.')
272 elif flag == 'ADULT
':
276 error = 'Only users older than
19 are able to watch this video
. Provide account credentials to download this content
.'
279 raise ExtractorError(
280 '%s said
: %s' % (self.IE_NAME, error), expected=True)
282 raise ExtractorError('Unable to download video info
')
284 video_element = video_xml.findall('./track
/video
')[-1]
285 if video_element is None or video_element.text is None:
286 raise ExtractorError(
287 'Video
%s does
not exist
' % video_id, expected=True)
289 video_url = video_element.text.strip()
291 title = xpath_text(video_xml, './track
/title
', 'title
', fatal=True)
293 uploader = xpath_text(video_xml, './track
/nickname
', 'uploader
')
294 uploader_id = xpath_text(video_xml, './track
/bj_id
', 'uploader
id')
295 duration = int_or_none(xpath_text(
296 video_xml, './track
/duration
', 'duration
'))
297 thumbnail = xpath_text(video_xml, './track
/titleImage
', 'thumbnail
')
300 'uploader
': uploader,
301 'uploader_id
': uploader_id,
302 'thumbnail
': thumbnail,
305 info = common_entry.copy()
309 'duration
': duration,
314 file_elements = video_element.findall('./file')
315 one = len(file_elements) == 1
316 for file_num, file_element in enumerate(file_elements, start=1):
317 file_url = url_or_none(file_element.text)
320 key = file_element.get('key
', '')
321 upload_date = unified_strdate(self._search_regex(
322 r'^
(\d{8}
)_
', key, 'upload date
', default=None))
323 if upload_date is not None:
324 # sometimes the upload date isn't included
in the
file name
325 # instead, another random ID is, which may parse as a valid
326 # date but be wildly out of a reasonable range
327 parsed_date
= date_from_str(upload_date
)
328 if parsed_date
.year
< 2000 or parsed_date
.year
>= 2100:
330 file_duration
= int_or_none(file_element
.get('duration'))
331 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
332 if determine_ext(file_url
) == 'm3u8':
333 formats
= self
._extract
_m
3u8_formats
(
334 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
336 note
='Downloading part %d m3u8 information' % file_num
)
342 if not formats
and not self
.get_param('ignore_no_formats'):
344 self
._sort
_formats
(formats
)
345 file_info
= common_entry
.copy()
348 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
349 'upload_date': upload_date
,
350 'duration': file_duration
,
353 entries
.append(file_info
)
354 entries_info
= info
.copy()
355 entries_info
.update({
356 '_type': 'multi_video',
364 'uploader': uploader
,
365 'uploader_id': uploader_id
,
366 'duration': duration
,
367 'thumbnail': thumbnail
,
370 if determine_ext(video_url
) == 'm3u8':
371 info
['formats'] = self
._extract
_m
3u8_formats
(
372 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
375 app
, playpath
= video_url
.split('mp4:')
379 'play_path': 'mp4:' + playpath
,
380 'rtmp_live': True, # downloading won't end without this
386 class AfreecaTVLiveIE(AfreecaTVIE
):
388 IE_NAME
= 'afreecatv:live'
389 _VALID_URL
= r
'https?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?'
391 'url': 'https://play.afreecatv.com/pyh3646/237852185',
395 'title': '【 우루과이 오늘은 무슨일이? 】',
396 'uploader': '박진우[JINU]',
397 'uploader_id': 'pyh3646',
398 'timestamp': 1640661495,
401 'skip': 'Livestream has ended',
403 'url': 'http://play.afreeca.com/pyh3646/237852185',
404 'only_matching': True,
406 'url': 'http://play.afreeca.com/pyh3646',
407 'only_matching': True,
410 _LIVE_API_URL
= 'https://live.afreecatv.com/afreeca/player_live_api.php'
412 _QUALITIES
= ('sd', 'hd', 'hd2k', 'original')
414 def _real_extract(self
, url
):
415 broadcaster_id
, broadcast_no
= self
._match
_valid
_url
(url
).group('id', 'bno')
416 password
= self
.get_param('videopassword')
418 info
= self
._download
_json
(self
._LIVE
_API
_URL
, broadcaster_id
, fatal
=False,
419 data
=urlencode_postdata({'bid': broadcaster_id}
)) or {}
420 channel_info
= info
.get('CHANNEL') or {}
421 broadcaster_id
= channel_info
.get('BJID') or broadcaster_id
422 broadcast_no
= channel_info
.get('BNO') or broadcast_no
423 password_protected
= channel_info
.get('BPWD')
425 raise ExtractorError(f
'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected
=True)
426 if password_protected
== 'Y' and password
is None:
427 raise ExtractorError(
428 'This livestream is protected by a password, use the --video-password option',
432 quality_key
= qualities(self
._QUALITIES
)
433 for quality_str
in self
._QUALITIES
:
436 'stream_type': 'common',
438 'quality': quality_str
,
440 if password
is not None:
441 params
['pwd'] = password
442 aid_response
= self
._download
_json
(
443 self
._LIVE
_API
_URL
, broadcast_no
, fatal
=False,
444 data
=urlencode_postdata(params
),
445 note
=f
'Downloading access token for {quality_str} stream',
446 errnote
=f
'Unable to download access token for {quality_str} stream')
447 aid
= traverse_obj(aid_response
, ('CHANNEL', 'AID'))
451 stream_base_url
= channel_info
.get('RMD') or 'https://livestream-manager.afreecatv.com'
452 stream_info
= self
._download
_json
(
453 f
'{stream_base_url}/broad_stream_assign.html', broadcast_no
, fatal
=False,
455 'return_type': channel_info
.get('CDN', 'gcp_cdn'),
456 'broad_key': f
'{broadcast_no}-common-{quality_str}-hls',
458 note
=f
'Downloading metadata for {quality_str} stream',
459 errnote
=f
'Unable to download metadata for {quality_str} stream') or {}
461 if stream_info
.get('view_url'):
463 'format_id': quality_str
,
464 'url': update_url_query(stream_info
['view_url'], {'aid': aid}
),
467 'quality': quality_key(quality_str
),
470 self
._sort
_formats
(formats
)
472 station_info
= self
._download
_json
(
473 'https://st.afreecatv.com/api/get_station_status.php', broadcast_no
,
474 query
={'szBjId': broadcaster_id}
, fatal
=False,
475 note
='Downloading channel metadata', errnote
='Unable to download channel metadata') or {}
479 'title': channel_info
.get('TITLE') or station_info
.get('station_title'),
480 'uploader': channel_info
.get('BJNICK') or station_info
.get('station_name'),
481 'uploader_id': broadcaster_id
,
482 'timestamp': unified_timestamp(station_info
.get('broad_start')),
488 class AfreecaTVUserIE(InfoExtractor
):
489 IE_NAME
= 'afreecatv:user'
490 _VALID_URL
= r
'https?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?'
492 'url': 'https://bj.afreecatv.com/ryuryu24/vods/review',
496 'title': 'ryuryu24 - review',
498 'playlist_count': 218,
500 'url': 'https://bj.afreecatv.com/parang1995/vods/highlight',
504 'title': 'parang1995 - highlight',
506 'playlist_count': 997,
508 'url': 'https://bj.afreecatv.com/ryuryu24/vods',
512 'title': 'ryuryu24 - all',
514 'playlist_count': 221,
516 'url': 'https://bj.afreecatv.com/ryuryu24/vods/balloonclip',
520 'title': 'ryuryu24 - balloonclip',
526 def _fetch_page(self
, user_id
, user_type
, page
):
528 info
= self
._download
_json
(f
'https://bjapi.afreecatv.com/api/{user_id}/vods/{user_type}', user_id
,
529 query
={'page': page, 'per_page': self._PER_PAGE, 'orderby': 'reg_date'}
,
530 note
=f
'Downloading {user_type} video page {page}')
531 for item
in info
['data']:
532 yield self
.url_result(
533 f
'https://vod.afreecatv.com/player/{item["title_no"]}/', AfreecaTVIE
, item
['title_no'])
535 def _real_extract(self
, url
):
536 user_id
, user_type
= self
._match
_valid
_url
(url
).group('id', 'slug_type')
537 user_type
= user_type
or 'all'
538 entries
= OnDemandPagedList(functools
.partial(self
._fetch
_page
, user_id
, user_type
), self
._PER
_PAGE
)
539 return self
.playlist_result(entries
, user_id
, f
'{user_id} - {user_type}')