]>
Commit | Line | Data |
---|---|---|
57cf9b7f PR |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
1dbfd787 PR |
4 | import re |
5 | ||
57cf9b7f PR |
6 | from .common import InfoExtractor |
7 | from ..compat import ( | |
8 | compat_urllib_parse_urlparse, | |
9 | compat_urlparse, | |
10 | ) | |
11 | from ..utils import ( | |
12 | ExtractorError, | |
13 | int_or_none, | |
e58609b2 | 14 | update_url_query, |
e7d85c4e | 15 | xpath_element, |
833b644f | 16 | xpath_text, |
57cf9b7f PR |
17 | ) |
18 | ||
19 | ||
20 | class AfreecaTVIE(InfoExtractor): | |
21 | IE_DESC = 'afreecatv.com' | |
e58609b2 S |
22 | _VALID_URL = r'''(?x) |
23 | https?:// | |
24 | (?: | |
25 | (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)? | |
26 | (?: | |
27 | /app/(?:index|read_ucc_bbs)\.cgi| | |
28 | /player/[Pp]layer\.(?:swf|html) | |
29 | )\?.*?\bnTitleNo=| | |
30 | vod\.afreecatv\.com/PLAYER/STATION/ | |
31 | ) | |
32 | (?P<id>\d+) | |
33 | ''' | |
8d93c214 | 34 | _TESTS = [{ |
57cf9b7f PR |
35 | 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=', |
36 | 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e', | |
37 | 'info_dict': { | |
38 | 'id': '36164052', | |
39 | 'ext': 'mp4', | |
40 | 'title': '데일리 에이프릴 요정들의 시상식!', | |
3452c3a2 | 41 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', |
57cf9b7f PR |
42 | 'uploader': 'dailyapril', |
43 | 'uploader_id': 'dailyapril', | |
8d93c214 | 44 | 'upload_date': '20160503', |
57cf9b7f | 45 | } |
8d93c214 PR |
46 | }, { |
47 | 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867', | |
48 | 'info_dict': { | |
49 | 'id': '36153164', | |
50 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
3452c3a2 | 51 | 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$', |
8d93c214 PR |
52 | 'uploader': 'dailyapril', |
53 | 'uploader_id': 'dailyapril', | |
54 | }, | |
55 | 'playlist_count': 2, | |
56 | 'playlist': [{ | |
57 | 'md5': 'd8b7c174568da61d774ef0203159bf97', | |
58 | 'info_dict': { | |
59 | 'id': '36153164_1', | |
60 | 'ext': 'mp4', | |
61 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
62 | 'upload_date': '20160502', | |
63 | }, | |
64 | }, { | |
65 | 'md5': '58f2ce7f6044e34439ab2d50612ab02b', | |
66 | 'info_dict': { | |
67 | 'id': '36153164_2', | |
68 | 'ext': 'mp4', | |
69 | 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'", | |
70 | 'upload_date': '20160502', | |
71 | }, | |
72 | }], | |
3452c3a2 PR |
73 | }, { |
74 | 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652', | |
75 | 'only_matching': True, | |
e58609b2 S |
76 | }, { |
77 | 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030', | |
78 | 'only_matching': True, | |
8d93c214 | 79 | }] |
57cf9b7f | 80 | |
1dbfd787 PR |
81 | @staticmethod |
82 | def parse_video_key(key): | |
0fdbe314 | 83 | video_key = {} |
1dbfd787 PR |
84 | m = re.match(r'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key) |
85 | if m: | |
86 | video_key['upload_date'] = m.group('upload_date') | |
87 | video_key['part'] = m.group('part') | |
88 | return video_key | |
89 | ||
57cf9b7f PR |
90 | def _real_extract(self, url): |
91 | video_id = self._match_id(url) | |
92 | parsed_url = compat_urllib_parse_urlparse(url) | |
93 | info_url = compat_urlparse.urlunparse(parsed_url._replace( | |
94 | netloc='afbbs.afreecatv.com:8080', | |
95 | path='/api/video/get_video_info.php')) | |
e58609b2 S |
96 | |
97 | video_xml = self._download_xml( | |
98 | update_url_query(info_url, {'nTitleNo': video_id}), video_id) | |
57cf9b7f | 99 | |
e7d85c4e | 100 | if xpath_element(video_xml, './track/video/file') is None: |
57cf9b7f PR |
101 | raise ExtractorError('Specified AfreecaTV video does not exist', |
102 | expected=True) | |
e7d85c4e | 103 | |
833b644f PR |
104 | title = xpath_text(video_xml, './track/title', 'title') |
105 | uploader = xpath_text(video_xml, './track/nickname', 'uploader') | |
106 | uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id') | |
107 | duration = int_or_none(xpath_text(video_xml, './track/duration', | |
108 | 'duration')) | |
109 | thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail') | |
57cf9b7f PR |
110 | |
111 | entries = [] | |
93fdb141 PR |
112 | for i, video_file in enumerate(video_xml.findall('./track/video/file')): |
113 | video_key = self.parse_video_key(video_file.get('key', '')) | |
114 | if not video_key: | |
115 | continue | |
833b644f | 116 | entries.append({ |
0fdbe314 | 117 | 'id': '%s_%s' % (video_id, video_key.get('part', i + 1)), |
833b644f | 118 | 'title': title, |
0fdbe314 | 119 | 'upload_date': video_key.get('upload_date'), |
833b644f | 120 | 'duration': int_or_none(video_file.get('duration')), |
22e35ade | 121 | 'url': video_file.text, |
833b644f | 122 | }) |
57cf9b7f PR |
123 | |
124 | info = { | |
125 | 'id': video_id, | |
126 | 'title': title, | |
127 | 'uploader': uploader, | |
128 | 'uploader_id': uploader_id, | |
129 | 'duration': duration, | |
130 | 'thumbnail': thumbnail, | |
131 | } | |
132 | ||
133 | if len(entries) > 1: | |
134 | info['_type'] = 'multi_video' | |
135 | info['entries'] = entries | |
136 | elif len(entries) == 1: | |
22e35ade | 137 | info['url'] = entries[0]['url'] |
370d4eb8 | 138 | info['upload_date'] = entries[0].get('upload_date') |
57cf9b7f PR |
139 | else: |
140 | raise ExtractorError( | |
141 | 'No files found for the specified AfreecaTV video, either' | |
142 | ' the URL is incorrect or the video has been made private.', | |
143 | expected=True) | |
144 | ||
145 | return info |