2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_xpath
17 class AfreecaTVIE(InfoExtractor
):
19 IE_DESC
= 'afreecatv.com'
23 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
25 /app/(?:index|read_ucc_bbs)\.cgi|
26 /player/[Pp]layer\.(?:swf|html)
28 vod\.afreecatv\.com/PLAYER/STATION/
32 _NETRC_MACHINE
= 'afreecatv'
34 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
35 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
39 'title': '데일리 에이프릴 요정들의 시상식!',
40 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
41 'uploader': 'dailyapril',
42 'uploader_id': 'dailyapril',
43 'upload_date': '20160503',
45 'skip': 'Video is gone',
47 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
50 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
51 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
52 'uploader': 'dailyapril',
53 'uploader_id': 'dailyapril',
57 'md5': 'd8b7c174568da61d774ef0203159bf97',
61 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
62 'upload_date': '20160502',
65 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
69 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
70 'upload_date': '20160502',
73 'skip': 'Video is gone',
75 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
79 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
80 'thumbnail': r
're:^https?://.*\.jpg$',
82 'uploader_id': 'badkids',
86 'skip_download': True,
89 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
92 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
93 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
94 'uploader': 'dailyapril',
95 'uploader_id': 'dailyapril',
100 'md5': 'd8b7c174568da61d774ef0203159bf97',
102 'id': '20160502_c4c62b9d_174361386_1',
104 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
105 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
106 'uploader': 'dailyapril',
107 'uploader_id': 'dailyapril',
108 'upload_date': '20160502',
112 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
114 'id': '20160502_39e739bb_174361386_2',
116 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
117 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
118 'uploader': 'dailyapril',
119 'uploader_id': 'dailyapril',
120 'upload_date': '20160502',
125 'skip_download': True,
129 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
131 'id': '20170411_BE689A0E_190960999_1_2_h',
134 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
136 'uploader_id': 'dasl8121',
137 'upload_date': '20170411',
141 'skip_download': True,
145 'url': 'http://vod.afreecatv.com/PLAYER/STATION/32028439',
147 'id': '20180327_27901457_202289533_1',
149 'title': '[생]빨개요♥ (part 1)',
150 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
151 'uploader': '[SA]서아',
152 'uploader_id': 'bjdyrksu',
153 'upload_date': '20180327',
157 'skip_download': True,
159 'expected_warnings': ['adult content'],
161 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
162 'only_matching': True,
164 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
165 'only_matching': True,
169 def parse_video_key(key
):
171 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
173 video_key
['upload_date'] = m
.group('upload_date')
174 video_key
['part'] = int(m
.group('part'))
177 def _real_initialize(self
):
181 username
, password
= self
._get
_login
_info
()
189 'szPassword': password
,
191 'szScriptVar': 'oLoginRet',
195 response
= self
._download
_json
(
196 'https://login.afreecatv.com/app/LoginAction.php', None,
197 'Logging in', data
=urlencode_postdata(login_form
))
200 -4: 'Your account has been suspended due to a violation of our terms and policies.',
201 -5: 'https://member.afreecatv.com/app/user_delete_progress.php',
202 -6: 'https://login.afreecatv.com/membership/changeMember.php',
203 -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.",
204 -9: 'https://member.afreecatv.com/app/pop_login_block.php',
205 -11: 'https://login.afreecatv.com/afreeca/second_login.php',
206 -12: 'https://member.afreecatv.com/app/user_security.php',
207 0: 'The username does not exist or you have entered the wrong password.',
208 -1: 'The username does not exist or you have entered the wrong password.',
209 -3: 'You have entered your username/password incorrectly.',
210 -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
211 -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
212 -32008: 'You have failed to log in. Please contact our Help Center.',
215 result
= int_or_none(response
.get('RESULT'))
217 error
= _ERRORS
.get(result
, 'You have failed to log in.')
218 raise ExtractorError(
219 'Unable to login: %s said: %s' % (self
.IE_NAME
, error
),
222 def _real_extract(self
, url
):
223 video_id
= self
._match
_id
(url
)
225 webpage
= self
._download
_webpage
(url
, video_id
)
227 if re
.search(r
'alert\(["\']This video has been deleted
', webpage):
228 raise ExtractorError(
229 'Video
%s has been deleted
' % video_id, expected=True)
231 station_id = self._search_regex(
232 r'nStationNo\s
*=\s
*(\d
+)', webpage, 'station
')
233 bbs_id = self._search_regex(
234 r'nBbsNo\s
*=\s
*(\d
+)', webpage, 'bbs
')
235 video_id = self._search_regex(
236 r'nTitleNo\s
*=\s
*(\d
+)', webpage, 'title
', default=video_id)
241 'nTitleNo
': video_id,
242 'nStationNo
': station_id,
246 query['partialView
'] = 'SKIP_ADULT
'
247 video_xml = self._download_xml(
248 'http
://afbbs
.afreecatv
.com
:8080/api
/video
/get_video_info
.php
',
249 video_id, 'Downloading video info XML
%s'
250 % (' (skipping adult
)' if partial_view else ''),
255 flag = xpath_text(video_xml, './track
/flag
', 'flag
', default=None)
256 if flag and flag == 'SUCCEED
':
258 if flag == 'PARTIAL_ADULT
':
259 self._downloader.report_warning(
260 'In accordance
with local laws
and regulations
, underage users are restricted
from watching adult content
. '
261 'Only content suitable
for all ages will be downloaded
. '
262 'Provide account credentials
if you wish to download restricted content
.')
265 elif flag == 'ADULT
':
266 error = 'Only users older than
19 are able to watch this video
. Provide account credentials to download this content
.'
269 raise ExtractorError(
270 '%s said
: %s' % (self.IE_NAME, error), expected=True)
272 raise ExtractorError('Unable to download video info
')
274 video_element = video_xml.findall(compat_xpath('./track
/video
'))[-1]
275 if video_element is None or video_element.text is None:
276 raise ExtractorError(
277 'Video
%s video does
not exist
' % video_id, expected=True)
279 video_url = video_element.text.strip()
281 title = xpath_text(video_xml, './track
/title
', 'title
', fatal=True)
283 uploader = xpath_text(video_xml, './track
/nickname
', 'uploader
')
284 uploader_id = xpath_text(video_xml, './track
/bj_id
', 'uploader
id')
285 duration = int_or_none(xpath_text(
286 video_xml, './track
/duration
', 'duration
'))
287 thumbnail = xpath_text(video_xml, './track
/titleImage
', 'thumbnail
')
290 'uploader
': uploader,
291 'uploader_id
': uploader_id,
292 'thumbnail
': thumbnail,
295 info = common_entry.copy()
299 'duration
': duration,
304 file_elements = video_element.findall(compat_xpath('./file'))
305 one = len(file_elements) == 1
306 for file_num, file_element in enumerate(file_elements, start=1):
307 file_url = file_element.text
310 key = file_element.get('key
', '')
311 upload_date = self._search_regex(
312 r'^
(\d{8}
)_
', key, 'upload date
', default=None)
313 file_duration = int_or_none(file_element.get('duration
'))
314 format_id = key if key else '%s_%s' % (video_id, file_num)
315 if determine_ext(file_url) == 'm3u8
':
316 formats = self._extract_m3u8_formats(
317 file_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
319 note='Downloading part
%d m3u8 information
' % file_num)
327 self._sort_formats(formats)
328 file_info = common_entry.copy()
331 'title
': title if one else '%s (part
%d)' % (title, file_num),
332 'upload_date
': upload_date,
333 'duration
': file_duration,
336 entries.append(file_info)
337 entries_info = info.copy()
338 entries_info.update({
339 '_type
': 'multi_video
',
347 'uploader
': uploader,
348 'uploader_id
': uploader_id,
349 'duration
': duration,
350 'thumbnail
': thumbnail,
353 if determine_ext(video_url) == 'm3u8
':
354 info['formats
'] = self._extract_m3u8_formats(
355 video_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
358 app, playpath = video_url.split('mp4
:')
362 'play_path
': 'mp4
:' + playpath,
363 'rtmp_live
': True, # downloading won't end without this