2 from __future__ import unicode_literals
6 from .common import InfoExtractor
8 compat_urllib_parse_urlparse,
18 class AfreecaTVIE(InfoExtractor):
19 IE_DESC = 'afreecatv.com'
20 _VALID_URL = r'''(?x)^
21 https?://(?:(live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
23 /app/(?:index|read_ucc_bbs)\.cgi|
24 /player/[Pp]layer\.(?:swf|html))
25 \?.*?\bnTitleNo=(?P<id>\d+)'''
27 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
28 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
32 'title': '데일리 에이프릴 요정들의 시상식!',
33 'thumbnail': 're:^https?://videoimg.afreecatv.com/.*$',
34 'uploader': 'dailyapril',
35 'uploader_id': 'dailyapril',
36 'upload_date': '20160503',
39 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
42 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
43 'thumbnail': 're:^https?://videoimg.afreecatv.com/.*$',
44 'uploader': 'dailyapril',
45 'uploader_id': 'dailyapril',
49 'md5': 'd8b7c174568da61d774ef0203159bf97',
53 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
54 'upload_date': '20160502',
57 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
61 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
62 'upload_date': '20160502',
68 def parse_video_key(key):
70 m = re.match(r'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key)
72 video_key['upload_date'] = m.group('upload_date')
73 video_key['part'] = m.group('part')
76 def _real_extract(self, url):
77 video_id = self._match_id(url)
78 parsed_url = compat_urllib_parse_urlparse(url)
79 info_url = compat_urlparse.urlunparse(parsed_url._replace(
80 netloc='afbbs.afreecatv.com:8080',
81 path='/api/video/get_video_info.php'))
82 video_xml = self._download_xml(info_url, video_id)
84 if xpath_text(video_xml, './track/flag', default='FAIL') != 'SUCCEED':
85 raise ExtractorError('Specified AfreecaTV video does not exist',
87 title = xpath_text(video_xml, './track/title', 'title')
88 uploader = xpath_text(video_xml, './track/nickname', 'uploader')
89 uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id')
90 duration = int_or_none(xpath_text(video_xml, './track/duration',
92 thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail')
95 for i, video_file in enumerate(video_xml.findall('./track/video/file')):
96 video_key = self.parse_video_key(video_file.get('key'))
98 'id': '%s_%s' % (video_id, video_key.get('part', i + 1)),
100 'upload_date': video_key.get('upload_date'),
101 'duration': int_or_none(video_file.get('duration')),
102 'url': video_file.text,
108 'uploader': uploader,
109 'uploader_id': uploader_id,
110 'duration': duration,
111 'thumbnail': thumbnail,
115 info['_type'] = 'multi_video'
116 info['entries'] = entries
117 elif len(entries) == 1:
118 info['url'] = entries[0]['url']
119 info['upload_date'] = entries[0]['upload_date']
121 raise ExtractorError(
122 'No files found for the specified AfreecaTV video, either'
123 ' the URL is incorrect or the video has been made private.',