]>
Commit | Line | Data |
---|---|---|
57cf9b7f PR |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
1dbfd787 PR |
4 | import re |
5 | ||
57cf9b7f | 6 | from .common import InfoExtractor |
51ef4919 | 7 | from ..compat import compat_xpath |
57cf9b7f | 8 | from ..utils import ( |
6b9466de | 9 | determine_ext, |
57cf9b7f PR |
10 | ExtractorError, |
11 | int_or_none, | |
833b644f | 12 | xpath_text, |
57cf9b7f PR |
13 | ) |
14 | ||
15 | ||
16 | class AfreecaTVIE(InfoExtractor): | |
c60089c0 | 17 | IE_NAME = 'afreecatv' |
57cf9b7f | 18 | IE_DESC = 'afreecatv.com' |
e58609b2 S |
19 | _VALID_URL = r'''(?x) |
20 | https?:// | |
21 | (?: | |
22 | (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)? | |
23 | (?: | |
24 | /app/(?:index|read_ucc_bbs)\.cgi| | |
25 | /player/[Pp]layer\.(?:swf|html) | |
26 | )\?.*?\bnTitleNo=| | |
27 | vod\.afreecatv\.com/PLAYER/STATION/ | |
28 | ) | |
29 | (?P<id>\d+) | |
30 | ''' | |
8d93c214 | 31 | _TESTS = [{ |
57cf9b7f PR |
32 | 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=', |
33 | 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e', | |
34 | 'info_dict': { | |
35 | 'id': '36164052', | |
36 | 'ext': 'mp4', | |
37 | 'title': '데일리 에이프릴 요정들의 시상식!', | |
3452c3a2 | 38 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', |
57cf9b7f PR |
39 | 'uploader': 'dailyapril', |
40 | 'uploader_id': 'dailyapril', | |
8d93c214 | 41 | 'upload_date': '20160503', |
51ef4919 YCH |
42 | }, |
43 | 'skip': 'Video is gone', | |
8d93c214 PR |
44 | }, { |
45 | 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867', | |
46 | 'info_dict': { | |
47 | 'id': '36153164', | |
48 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
3452c3a2 | 49 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', |
8d93c214 PR |
50 | 'uploader': 'dailyapril', |
51 | 'uploader_id': 'dailyapril', | |
52 | }, | |
53 | 'playlist_count': 2, | |
54 | 'playlist': [{ | |
55 | 'md5': 'd8b7c174568da61d774ef0203159bf97', | |
56 | 'info_dict': { | |
57 | 'id': '36153164_1', | |
58 | 'ext': 'mp4', | |
59 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
60 | 'upload_date': '20160502', | |
61 | }, | |
62 | }, { | |
63 | 'md5': '58f2ce7f6044e34439ab2d50612ab02b', | |
64 | 'info_dict': { | |
65 | 'id': '36153164_2', | |
66 | 'ext': 'mp4', | |
67 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
68 | 'upload_date': '20160502', | |
69 | }, | |
70 | }], | |
51ef4919 YCH |
71 | 'skip': 'Video is gone', |
72 | }, { | |
73 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793', | |
74 | 'info_dict': { | |
75 | 'id': '18650793', | |
6b9466de S |
76 | 'ext': 'mp4', |
77 | 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!', | |
78 | 'thumbnail': r're:^https?://.*\.jpg$', | |
51ef4919 YCH |
79 | 'uploader': '윈아디', |
80 | 'uploader_id': 'badkids', | |
6b9466de S |
81 | 'duration': 107, |
82 | }, | |
83 | 'params': { | |
84 | 'skip_download': True, | |
85 | }, | |
86 | }, { | |
87 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652', | |
88 | 'info_dict': { | |
89 | 'id': '10481652', | |
90 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
91 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', | |
92 | 'uploader': 'dailyapril', | |
93 | 'uploader_id': 'dailyapril', | |
94 | 'duration': 6492, | |
51ef4919 | 95 | }, |
6b9466de S |
96 | 'playlist_count': 2, |
97 | 'playlist': [{ | |
98 | 'md5': 'd8b7c174568da61d774ef0203159bf97', | |
99 | 'info_dict': { | |
e109f1ff | 100 | 'id': '20160502_c4c62b9d_174361386_1', |
6b9466de S |
101 | 'ext': 'mp4', |
102 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)", | |
103 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', | |
104 | 'uploader': 'dailyapril', | |
105 | 'uploader_id': 'dailyapril', | |
106 | 'upload_date': '20160502', | |
107 | 'duration': 3601, | |
108 | }, | |
109 | }, { | |
110 | 'md5': '58f2ce7f6044e34439ab2d50612ab02b', | |
111 | 'info_dict': { | |
e109f1ff | 112 | 'id': '20160502_39e739bb_174361386_2', |
6b9466de S |
113 | 'ext': 'mp4', |
114 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)", | |
115 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', | |
116 | 'uploader': 'dailyapril', | |
117 | 'uploader_id': 'dailyapril', | |
118 | 'upload_date': '20160502', | |
119 | 'duration': 2891, | |
120 | }, | |
121 | }], | |
51ef4919 | 122 | 'params': { |
6b9466de | 123 | 'skip_download': True, |
51ef4919 | 124 | }, |
e109f1ff S |
125 | }, { |
126 | # non standard key | |
127 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605', | |
128 | 'info_dict': { | |
129 | 'id': '20170411_BE689A0E_190960999_1_2_h', | |
130 | 'ext': 'mp4', | |
131 | 'title': '혼자사는여자집', | |
132 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', | |
133 | 'uploader': '♥이슬이', | |
134 | 'uploader_id': 'dasl8121', | |
135 | 'upload_date': '20170411', | |
136 | 'duration': 213, | |
137 | }, | |
138 | 'params': { | |
139 | 'skip_download': True, | |
140 | }, | |
839728f5 S |
141 | }, { |
142 | # adult video | |
143 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/26542731', | |
144 | 'info_dict': { | |
145 | 'id': '20171001_F1AE1711_196617479_1', | |
146 | 'ext': 'mp4', | |
147 | 'title': '[생]서아 초심 찾기 방송 (part 1)', | |
148 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', | |
149 | 'uploader': 'BJ서아', | |
150 | 'uploader_id': 'bjdyrksu', | |
151 | 'upload_date': '20171001', | |
152 | 'duration': 3600, | |
153 | 'age_limit': 18, | |
154 | }, | |
155 | 'params': { | |
156 | 'skip_download': True, | |
157 | }, | |
3452c3a2 PR |
158 | }, { |
159 | 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652', | |
160 | 'only_matching': True, | |
e58609b2 S |
161 | }, { |
162 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030', | |
163 | 'only_matching': True, | |
8d93c214 | 164 | }] |
57cf9b7f | 165 | |
1dbfd787 PR |
166 | @staticmethod |
167 | def parse_video_key(key): | |
0fdbe314 | 168 | video_key = {} |
1dbfd787 PR |
169 | m = re.match(r'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key) |
170 | if m: | |
171 | video_key['upload_date'] = m.group('upload_date') | |
6b9466de | 172 | video_key['part'] = int(m.group('part')) |
1dbfd787 PR |
173 | return video_key |
174 | ||
57cf9b7f PR |
175 | def _real_extract(self, url): |
176 | video_id = self._match_id(url) | |
e58609b2 | 177 | |
9e36fedd S |
178 | webpage = self._download_webpage(url, video_id) |
179 | ||
f9f10268 S |
180 | if re.search(r'alert\(["\']This video has been deleted', webpage): |
181 | raise ExtractorError( | |
182 | 'Video %s has been deleted' % video_id, expected=True) | |
183 | ||
9e36fedd S |
184 | station_id = self._search_regex( |
185 | r'nStationNo\s*=\s*(\d+)', webpage, 'station') | |
186 | bbs_id = self._search_regex( | |
187 | r'nBbsNo\s*=\s*(\d+)', webpage, 'bbs') | |
188 | video_id = self._search_regex( | |
189 | r'nTitleNo\s*=\s*(\d+)', webpage, 'title', default=video_id) | |
190 | ||
e58609b2 | 191 | video_xml = self._download_xml( |
51ef4919 | 192 | 'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php', |
fde677fe S |
193 | video_id, headers={ |
194 | 'Referer': 'http://vod.afreecatv.com/embed.php', | |
195 | }, query={ | |
839728f5 | 196 | 'nTitleNo': video_id, |
9e36fedd S |
197 | 'nStationNo': station_id, |
198 | 'nBbsNo': bbs_id, | |
839728f5 S |
199 | 'partialView': 'SKIP_ADULT', |
200 | }) | |
201 | ||
202 | flag = xpath_text(video_xml, './track/flag', 'flag', default=None) | |
203 | if flag and flag != 'SUCCEED': | |
204 | raise ExtractorError( | |
205 | '%s said: %s' % (self.IE_NAME, flag), expected=True) | |
57cf9b7f | 206 | |
f241a973 | 207 | video_element = video_xml.findall(compat_xpath('./track/video'))[-1] |
51ef4919 | 208 | if video_element is None or video_element.text is None: |
f9f10268 S |
209 | raise ExtractorError( |
210 | 'Video %s video does not exist' % video_id, expected=True) | |
e7d85c4e | 211 | |
6b9466de | 212 | video_url = video_element.text.strip() |
51ef4919 YCH |
213 | |
214 | title = xpath_text(video_xml, './track/title', 'title', fatal=True) | |
6b9466de | 215 | |
833b644f PR |
216 | uploader = xpath_text(video_xml, './track/nickname', 'uploader') |
217 | uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id') | |
6b9466de S |
218 | duration = int_or_none(xpath_text( |
219 | video_xml, './track/duration', 'duration')) | |
833b644f | 220 | thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail') |
57cf9b7f | 221 | |
6b9466de S |
222 | common_entry = { |
223 | 'uploader': uploader, | |
224 | 'uploader_id': uploader_id, | |
225 | 'thumbnail': thumbnail, | |
226 | } | |
227 | ||
228 | info = common_entry.copy() | |
229 | info.update({ | |
230 | 'id': video_id, | |
231 | 'title': title, | |
232 | 'duration': duration, | |
233 | }) | |
234 | ||
235 | if not video_url: | |
236 | entries = [] | |
e109f1ff S |
237 | file_elements = video_element.findall(compat_xpath('./file')) |
238 | one = len(file_elements) == 1 | |
239 | for file_num, file_element in enumerate(file_elements, start=1): | |
6b9466de S |
240 | file_url = file_element.text |
241 | if not file_url: | |
242 | continue | |
e109f1ff S |
243 | key = file_element.get('key', '') |
244 | upload_date = self._search_regex( | |
245 | r'^(\d{8})_', key, 'upload date', default=None) | |
6b9466de | 246 | file_duration = int_or_none(file_element.get('duration')) |
e109f1ff | 247 | format_id = key if key else '%s_%s' % (video_id, file_num) |
4a109f81 S |
248 | if determine_ext(file_url) == 'm3u8': |
249 | formats = self._extract_m3u8_formats( | |
250 | file_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
251 | m3u8_id='hls', | |
252 | note='Downloading part %d m3u8 information' % file_num) | |
253 | else: | |
254 | formats = [{ | |
255 | 'url': file_url, | |
256 | 'format_id': 'http', | |
257 | }] | |
258 | if not formats: | |
259 | continue | |
260 | self._sort_formats(formats) | |
6b9466de S |
261 | file_info = common_entry.copy() |
262 | file_info.update({ | |
263 | 'id': format_id, | |
6b4ddd33 | 264 | 'title': title if one else '%s (part %d)' % (title, file_num), |
e109f1ff | 265 | 'upload_date': upload_date, |
6b9466de S |
266 | 'duration': file_duration, |
267 | 'formats': formats, | |
268 | }) | |
269 | entries.append(file_info) | |
270 | entries_info = info.copy() | |
271 | entries_info.update({ | |
272 | '_type': 'multi_video', | |
273 | 'entries': entries, | |
274 | }) | |
275 | return entries_info | |
276 | ||
277 | info = { | |
57cf9b7f PR |
278 | 'id': video_id, |
279 | 'title': title, | |
280 | 'uploader': uploader, | |
281 | 'uploader_id': uploader_id, | |
282 | 'duration': duration, | |
283 | 'thumbnail': thumbnail, | |
284 | } | |
285 | ||
6b9466de S |
286 | if determine_ext(video_url) == 'm3u8': |
287 | info['formats'] = self._extract_m3u8_formats( | |
288 | video_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
289 | m3u8_id='hls') | |
290 | else: | |
291 | app, playpath = video_url.split('mp4:') | |
292 | info.update({ | |
293 | 'url': app, | |
294 | 'ext': 'flv', | |
295 | 'play_path': 'mp4:' + playpath, | |
296 | 'rtmp_live': True, # downloading won't end without this | |
297 | }) | |
298 | ||
299 | return info |