2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_xpath
20 class AfreecaTVIE(InfoExtractor
):
22 IE_DESC
= 'afreecatv.com'
26 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
28 /app/(?:index|read_ucc_bbs)\.cgi|
29 /player/[Pp]layer\.(?:swf|html)
31 vod\.afreecatv\.com/PLAYER/STATION/
35 _NETRC_MACHINE
= 'afreecatv'
37 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
38 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
42 'title': '데일리 에이프릴 요정들의 시상식!',
43 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
44 'uploader': 'dailyapril',
45 'uploader_id': 'dailyapril',
46 'upload_date': '20160503',
48 'skip': 'Video is gone',
50 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
53 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
54 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
55 'uploader': 'dailyapril',
56 'uploader_id': 'dailyapril',
60 'md5': 'd8b7c174568da61d774ef0203159bf97',
64 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
65 'upload_date': '20160502',
68 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
72 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
73 'upload_date': '20160502',
76 'skip': 'Video is gone',
78 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
82 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
83 'thumbnail': r
're:^https?://.*\.jpg$',
85 'uploader_id': 'badkids',
89 'skip_download': True,
92 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
95 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
96 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
97 'uploader': 'dailyapril',
98 'uploader_id': 'dailyapril',
103 'md5': 'd8b7c174568da61d774ef0203159bf97',
105 'id': '20160502_c4c62b9d_174361386_1',
107 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
108 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
109 'uploader': 'dailyapril',
110 'uploader_id': 'dailyapril',
111 'upload_date': '20160502',
115 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
117 'id': '20160502_39e739bb_174361386_2',
119 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
120 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
121 'uploader': 'dailyapril',
122 'uploader_id': 'dailyapril',
123 'upload_date': '20160502',
128 'skip_download': True,
132 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
134 'id': '20170411_BE689A0E_190960999_1_2_h',
137 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
139 'uploader_id': 'dasl8121',
140 'upload_date': '20170411',
144 'skip_download': True,
148 'url': 'http://vod.afreecatv.com/PLAYER/STATION/32028439',
150 'id': '20180327_27901457_202289533_1',
152 'title': '[생]빨개요♥ (part 1)',
153 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
154 'uploader': '[SA]서아',
155 'uploader_id': 'bjdyrksu',
156 'upload_date': '20180327',
160 'skip_download': True,
162 'expected_warnings': ['adult content'],
164 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
165 'only_matching': True,
167 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
168 'only_matching': True,
172 def parse_video_key(key
):
174 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
176 video_key
['upload_date'] = m
.group('upload_date')
177 video_key
['part'] = int(m
.group('part'))
180 def _real_initialize(self
):
184 username
, password
= self
._get
_login
_info
()
192 'szPassword': password
,
194 'szScriptVar': 'oLoginRet',
198 response
= self
._download
_json
(
199 'https://login.afreecatv.com/app/LoginAction.php', None,
200 'Logging in', data
=urlencode_postdata(login_form
))
203 -4: 'Your account has been suspended due to a violation of our terms and policies.',
204 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
205 -6: 'https://login.afreecatv.com/membership/changeMember.php',
206 -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.",
207 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
208 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
209 -12: 'https://member.afreecatv.com/app/user_security.php',
210 0: 'The username does not exist or you have entered the wrong password.',
211 -1: 'The username does not exist or you have entered the wrong password.',
212 -3: 'You have entered your username/password incorrectly.',
213 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
214 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
215 -32008: 'You have failed to log in. Please contact our Help Center.',
218 result
= int_or_none(response
.get('RESULT'))
220 error
= _ERRORS
.get(result
, 'You have failed to log in.')
221 raise ExtractorError(
222 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
225 def _real_extract(self
, url
):
226 video_id
= self
._match
_id
(url
)
228 webpage
= self
._download
_webpage
(url
, video_id
)
230 if re
.search(r
'alert\(["\']This video has been deleted
', webpage):
231 raise ExtractorError(
232 'Video
%s has been deleted
' % video_id, expected=True)
234 station_id = self._search_regex(
235 r'nStationNo\s
*=\s
*(\d
+)', webpage, 'station
')
236 bbs_id = self._search_regex(
237 r'nBbsNo\s
*=\s
*(\d
+)', webpage, 'bbs
')
238 video_id = self._search_regex(
239 r'nTitleNo\s
*=\s
*(\d
+)', webpage, 'title
', default=video_id)
245 'nTitleNo
': video_id,
246 'nStationNo
': station_id,
250 query['partialView
'] = 'SKIP_ADULT
'
252 query['adultView
'] = 'ADULT_VIEW
'
253 video_xml = self._download_xml(
254 'http
://afbbs
.afreecatv
.com
:8080/api
/video
/get_video_info
.php
',
255 video_id, 'Downloading video info XML
%s'
256 % (' (skipping adult
)' if partial_view else ''),
261 flag = xpath_text(video_xml, './track
/flag
', 'flag
', default=None)
262 if flag and flag == 'SUCCEED
':
264 if flag == 'PARTIAL_ADULT
':
266 'In accordance
with local laws
and regulations
, underage users are restricted
from watching adult content
. '
267 'Only content suitable
for all ages will be downloaded
. '
268 'Provide account credentials
if you wish to download restricted content
.')
271 elif flag == 'ADULT
':
275 error = 'Only users older than
19 are able to watch this video
. Provide account credentials to download this content
.'
278 raise ExtractorError(
279 '%s said
: %s' % (self.IE_NAME, error), expected=True)
281 raise ExtractorError('Unable to download video info
')
283 video_element = video_xml.findall(compat_xpath('./track
/video
'))[-1]
284 if video_element is None or video_element.text is None:
285 raise ExtractorError(
286 'Video
%s does
not exist
' % video_id, expected=True)
288 video_url = video_element.text.strip()
290 title = xpath_text(video_xml, './track
/title
', 'title
', fatal=True)
292 uploader = xpath_text(video_xml, './track
/nickname
', 'uploader
')
293 uploader_id = xpath_text(video_xml, './track
/bj_id
', 'uploader
id')
294 duration = int_or_none(xpath_text(
295 video_xml, './track
/duration
', 'duration
'))
296 thumbnail = xpath_text(video_xml, './track
/titleImage
', 'thumbnail
')
299 'uploader
': uploader,
300 'uploader_id
': uploader_id,
301 'thumbnail
': thumbnail,
304 info = common_entry.copy()
308 'duration
': duration,
313 file_elements = video_element.findall(compat_xpath('./file'))
314 one = len(file_elements) == 1
315 for file_num, file_element in enumerate(file_elements, start=1):
316 file_url = url_or_none(file_element.text)
319 key = file_element.get('key
', '')
320 upload_date = unified_strdate(self._search_regex(
321 r'^
(\d{8}
)_
', key, 'upload date
', default=None))
322 if upload_date is not None:
323 # sometimes the upload date isn't included
in the
file name
324 # instead, another random ID is, which may parse as a valid
325 # date but be wildly out of a reasonable range
326 parsed_date
= date_from_str(upload_date
)
327 if parsed_date
.year
< 2000 or parsed_date
.year
>= 2100:
329 file_duration
= int_or_none(file_element
.get('duration'))
330 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
331 if determine_ext(file_url
) == 'm3u8':
332 formats
= self
._extract
_m
3u8_formats
(
333 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
335 note
='Downloading part %d m3u8 information' % file_num
)
341 if not formats
and not self
.get_param('ignore_no_formats'):
343 self
._sort
_formats
(formats
)
344 file_info
= common_entry
.copy()
347 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
348 'upload_date': upload_date
,
349 'duration': file_duration
,
352 entries
.append(file_info
)
353 entries_info
= info
.copy()
354 entries_info
.update({
355 '_type': 'multi_video',
363 'uploader': uploader
,
364 'uploader_id': uploader_id
,
365 'duration': duration
,
366 'thumbnail': thumbnail
,
369 if determine_ext(video_url
) == 'm3u8':
370 info
['formats'] = self
._extract
_m
3u8_formats
(
371 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
374 app
, playpath
= video_url
.split('mp4:')
378 'play_path': 'mp4:' + playpath
,
379 'rtmp_live': True, # downloading won't end without this