]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/afreecatv.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_xpath
16 class AfreecaTVIE(InfoExtractor
):
18 IE_DESC
= 'afreecatv.com'
22 (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
24 /app/(?:index|read_ucc_bbs)\.cgi|
25 /player/[Pp]layer\.(?:swf|html)
27 vod\.afreecatv\.com/PLAYER/STATION/
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',
37 'title': '데일리 에이프릴 요정들의 시상식!',
38 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
39 'uploader': 'dailyapril',
40 'uploader_id': 'dailyapril',
41 'upload_date': '20160503',
43 'skip': 'Video is gone',
45 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
48 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
49 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
50 'uploader': 'dailyapril',
51 'uploader_id': 'dailyapril',
55 'md5': 'd8b7c174568da61d774ef0203159bf97',
59 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
60 'upload_date': '20160502',
63 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
67 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
68 'upload_date': '20160502',
71 'skip': 'Video is gone',
73 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
77 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
78 'thumbnail': r
're:^https?://.*\.jpg$',
80 'uploader_id': 'badkids',
84 'skip_download': True,
87 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
90 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
91 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
92 'uploader': 'dailyapril',
93 'uploader_id': 'dailyapril',
98 'md5': 'd8b7c174568da61d774ef0203159bf97',
100 'id': '20160502_c4c62b9d_174361386_1',
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',
110 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
112 'id': '20160502_39e739bb_174361386_2',
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',
123 'skip_download': True,
127 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
129 'id': '20170411_BE689A0E_190960999_1_2_h',
132 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
134 'uploader_id': 'dasl8121',
135 'upload_date': '20170411',
139 'skip_download': True,
142 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
143 'only_matching': True,
145 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
146 'only_matching': True,
150 def parse_video_key(key
):
152 m
= re
.match(r
'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key
)
154 video_key
['upload_date'] = m
.group('upload_date')
155 video_key
['part'] = int(m
.group('part'))
158 def _real_extract(self
, url
):
159 video_id
= self
._match
_id
(url
)
161 video_xml
= self
._download
_xml
(
162 'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php',
163 video_id
, query
={'nTitleNo': video_id
})
165 video_element
= video_xml
.findall(compat_xpath('./track/video'))[1]
166 if video_element
is None or video_element
.text
is None:
167 raise ExtractorError('Specified AfreecaTV video does not exist',
170 video_url
= video_element
.text
.strip()
172 title
= xpath_text(video_xml
, './track/title', 'title', fatal
=True)
174 uploader
= xpath_text(video_xml
, './track/nickname', 'uploader')
175 uploader_id
= xpath_text(video_xml
, './track/bj_id', 'uploader id')
176 duration
= int_or_none(xpath_text(
177 video_xml
, './track/duration', 'duration'))
178 thumbnail
= xpath_text(video_xml
, './track/titleImage', 'thumbnail')
181 'uploader': uploader
,
182 'uploader_id': uploader_id
,
183 'thumbnail': thumbnail
,
186 info
= common_entry
.copy()
190 'duration': duration
,
195 file_elements
= video_element
.findall(compat_xpath('./file'))
196 one
= len(file_elements
) == 1
197 for file_num
, file_element
in enumerate(file_elements
, start
=1):
198 file_url
= file_element
.text
201 key
= file_element
.get('key', '')
202 upload_date
= self
._search
_regex
(
203 r
'^(\d{8})_', key
, 'upload date', default
=None)
204 file_duration
= int_or_none(file_element
.get('duration'))
205 format_id
= key
if key
else '%s_%s' % (video_id
, file_num
)
206 formats
= self
._extract
_m
3u8_formats
(
207 file_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
209 note
='Downloading part %d m3u8 information' % file_num
)
210 file_info
= common_entry
.copy()
213 'title': title
if one
else '%s (part %d)' % (title
, file_num
),
214 'upload_date': upload_date
,
215 'duration': file_duration
,
218 entries
.append(file_info
)
219 entries_info
= info
.copy()
220 entries_info
.update({
221 '_type': 'multi_video',
229 'uploader': uploader
,
230 'uploader_id': uploader_id
,
231 'duration': duration
,
232 'thumbnail': thumbnail
,
235 if determine_ext(video_url
) == 'm3u8':
236 info
['formats'] = self
._extract
_m
3u8_formats
(
237 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
240 app
, playpath
= video_url
.split('mp4:')
244 'play_path': 'mp4:' + playpath
,
245 'rtmp_live': True, # downloading won't end without this
251 class AfreecaTVGlobalIE(AfreecaTVIE
):
252 IE_NAME
= 'afreecatv:global'
253 _VALID_URL
= r
'https?://(?:www\.)?afreeca\.tv/(?P<channel_id>\d+)(?:/v/(?P<video_id>\d+))?'
255 'url': 'http://afreeca.tv/36853014/v/58301',
258 'title': 'tryhard top100',
259 'uploader_id': '36853014',
260 'uploader': 'makgi Hearthstone Live!',
265 def _real_extract(self
, url
):
266 channel_id
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
267 video_type
= 'video' if video_id
else 'live'
273 query
['vno'] = video_id
274 video_data
= self
._download
_json
(
275 'http://api.afreeca.tv/%s/view_%s.php' % (video_type
, video_type
),
276 video_id
or channel_id
, query
=query
)['channel']
278 if video_data
.get('result') != 1:
279 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, video_data
['remsg']))
281 title
= video_data
['title']
284 'thumbnail': video_data
.get('thumb'),
285 'view_count': int_or_none(video_data
.get('vcnt')),
286 'age_limit': int_or_none(video_data
.get('grade')),
287 'uploader_id': channel_id
,
288 'uploader': video_data
.get('cname'),
293 for i
, f
in enumerate(video_data
.get('flist', [])):
294 video_key
= self
.parse_video_key(f
.get('key', ''))
295 f_url
= f
.get('file')
296 if not video_key
or not f_url
:
299 'id': '%s_%s' % (video_id
, video_key
.get('part', i
+ 1)),
301 'upload_date': video_key
.get('upload_date'),
302 'duration': int_or_none(f
.get('length')),
304 'protocol': 'm3u8_native',
311 'duration': int_or_none(video_data
.get('length')),
314 info
['_type'] = 'multi_video'
315 info
['entries'] = entries
316 elif len(entries
) == 1:
317 i
= entries
[0].copy()
322 for s
in video_data
.get('strm', []):
323 s_url
= s
.get('purl')
326 stype
= s
.get('stype')
328 formats
.extend(self
._extract
_m
3u8_formats
(
329 s_url
, channel_id
, 'mp4', m3u8_id
=stype
, fatal
=False))
330 elif stype
== 'RTMP':
332 label
= s
.get('label')
334 format_id
.append(label
)
336 'format_id': '-'.join(format_id
),
338 'tbr': int_or_none(s
.get('bps')),
339 'height': int_or_none(s
.get('brt')),
343 self
._sort
_formats
(formats
)
347 'title': self
._live
_title
(title
),