]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
23f4a93b PH |
2 | |
3 | from __future__ import unicode_literals | |
4 | ||
b6c33fd5 | 5 | import re |
2f0a33d8 | 6 | import itertools |
b6c33fd5 | 7 | |
150f2082 | 8 | from .common import InfoExtractor |
830afe85 | 9 | from ..compat import ( |
11a4efc5 | 10 | compat_parse_qs, |
830afe85 | 11 | compat_urllib_parse_unquote, |
15707c7e | 12 | compat_urllib_parse_urlencode, |
11a4efc5 | 13 | compat_urlparse, |
830afe85 | 14 | ) |
126d7701 | 15 | from ..utils import ( |
16 | int_or_none, | |
17 | str_to_int, | |
18 | xpath_text, | |
2f0a33d8 | 19 | unescapeHTML, |
150f2082 JMF |
20 | ) |
21 | ||
22 | ||
23 | class DaumIE(InfoExtractor): | |
830afe85 | 24 | _VALID_URL = r'https?://(?:(?:m\.)?tvpot\.daum\.net/v/|videofarm\.daum\.net/controller/player/VodPlayer\.swf\?vid=)(?P<id>[^?#&]+)' |
23f4a93b | 25 | IE_NAME = 'daum.net' |
150f2082 | 26 | |
e5a79071 | 27 | _TESTS = [{ |
72033465 | 28 | 'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz', |
178b47e6 | 29 | 'info_dict': { |
72033465 | 30 | 'id': 'vab4dyeDBysyBssyukBUjBz', |
178b47e6 | 31 | 'ext': 'mp4', |
72033465 | 32 | 'title': '마크 헌트 vs 안토니오 실바', |
33 | 'description': 'Mark Hunt vs Antonio Silva', | |
34 | 'upload_date': '20131217', | |
ec85ded8 | 35 | 'thumbnail': r're:^https?://.*\.(?:jpg|png)', |
72033465 | 36 | 'duration': 2117, |
126d7701 | 37 | 'view_count': int, |
38 | 'comment_count': int, | |
178b47e6 | 39 | }, |
e5a79071 | 40 | }, { |
b6c33fd5 | 41 | 'url': 'http://m.tvpot.daum.net/v/65139429', |
42 | 'info_dict': { | |
43 | 'id': '65139429', | |
44 | 'ext': 'mp4', | |
58250eff | 45 | 'title': '1297회, \'아빠 아들로 태어나길 잘 했어\' 민수, 감동의 눈물[아빠 어디가] 20150118', |
b6c33fd5 | 46 | 'description': 'md5:79794514261164ff27e36a21ad229fc5', |
47 | 'upload_date': '20150604', | |
ec85ded8 | 48 | 'thumbnail': r're:^https?://.*\.(?:jpg|png)', |
f5d30d52 | 49 | 'duration': 154, |
50 | 'view_count': int, | |
51 | 'comment_count': int, | |
e047922b | 52 | }, |
53 | }, { | |
e5a79071 PH |
54 | 'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24', |
55 | 'only_matching': True, | |
830afe85 YCH |
56 | }, { |
57 | 'url': 'http://videofarm.daum.net/controller/player/VodPlayer.swf?vid=vwIpVpCQsT8%24&ref=', | |
58 | 'info_dict': { | |
59 | 'id': 'vwIpVpCQsT8$', | |
60 | 'ext': 'flv', | |
61 | 'title': '01-Korean War ( Trouble on the horizon )', | |
62 | 'description': '\nKorean War 01\nTrouble on the horizon\n전쟁의 먹구름', | |
63 | 'upload_date': '20080223', | |
ec85ded8 | 64 | 'thumbnail': r're:^https?://.*\.(?:jpg|png)', |
830afe85 YCH |
65 | 'duration': 249, |
66 | 'view_count': int, | |
67 | 'comment_count': int, | |
68 | }, | |
f7291a0b YCH |
69 | }, { |
70 | # Requires dte_type=WEB (#9972) | |
71 | 'url': 'http://tvpot.daum.net/v/s3794Uf1NZeZ1qMpGpeqeRU', | |
72 | 'md5': 'a8917742069a4dd442516b86e7d66529', | |
73 | 'info_dict': { | |
74 | 'id': 's3794Uf1NZeZ1qMpGpeqeRU', | |
75 | 'ext': 'mp4', | |
76 | 'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny) [쇼! 음악중심] 508회 20160611', | |
77 | 'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\n\n[쇼! 음악중심] 20160611, 507회', | |
78 | 'upload_date': '20160611', | |
79 | }, | |
e5a79071 | 80 | }] |
150f2082 JMF |
81 | |
82 | def _real_extract(self, url): | |
830afe85 | 83 | video_id = compat_urllib_parse_unquote(self._match_id(url)) |
72033465 | 84 | movie_data = self._download_json( |
f7291a0b YCH |
85 | 'http://videofarm.daum.net/controller/api/closed/v1_2/IntegratedMovieData.json', |
86 | video_id, 'Downloading video formats info', query={'vid': video_id, 'dte_type': 'WEB'}) | |
150f2082 | 87 | |
b6c33fd5 | 88 | # For urls like http://m.tvpot.daum.net/v/65139429, where the video_id is really a clipid |
89 | if not movie_data.get('output_list', {}).get('output_list') and re.match(r'^\d+$', video_id): | |
90 | return self.url_result('http://tvpot.daum.net/clip/ClipView.do?clipid=%s' % video_id) | |
91 | ||
06ffa334 | 92 | info = self._download_xml( |
f7291a0b YCH |
93 | 'http://tvpot.daum.net/clip/ClipInfoXml.do', video_id, |
94 | 'Downloading video info', query={'vid': video_id}) | |
06ffa334 | 95 | |
150f2082 | 96 | formats = [] |
72033465 | 97 | for format_el in movie_data['output_list']['output_list']: |
98 | profile = format_el['profile'] | |
15707c7e | 99 | format_query = compat_urllib_parse_urlencode({ |
72033465 | 100 | 'vid': video_id, |
150f2082 JMF |
101 | 'profile': profile, |
102 | }) | |
e26f8712 | 103 | url_doc = self._download_xml( |
150f2082 | 104 | 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query, |
e5a79071 | 105 | video_id, note='Downloading video data for %s format' % profile) |
150f2082 JMF |
106 | format_url = url_doc.find('result/url').text |
107 | formats.append({ | |
108 | 'url': format_url, | |
150f2082 | 109 | 'format_id': profile, |
72033465 | 110 | 'width': int_or_none(format_el.get('width')), |
111 | 'height': int_or_none(format_el.get('height')), | |
112 | 'filesize': int_or_none(format_el.get('filesize')), | |
150f2082 | 113 | }) |
72033465 | 114 | self._sort_formats(formats) |
150f2082 | 115 | |
fb7abb31 | 116 | return { |
150f2082 JMF |
117 | 'id': video_id, |
118 | 'title': info.find('TITLE').text, | |
119 | 'formats': formats, | |
126d7701 | 120 | 'thumbnail': xpath_text(info, 'THUMB_URL'), |
121 | 'description': xpath_text(info, 'CONTENTS'), | |
122 | 'duration': int_or_none(xpath_text(info, 'DURATION')), | |
150f2082 | 123 | 'upload_date': info.find('REGDTTM').text[:8], |
126d7701 | 124 | 'view_count': str_to_int(xpath_text(info, 'PLAY_CNT')), |
125 | 'comment_count': str_to_int(xpath_text(info, 'COMMENT_CNT')), | |
150f2082 | 126 | } |
72033465 | 127 | |
128 | ||
129 | class DaumClipIE(InfoExtractor): | |
b6c33fd5 | 130 | _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)' |
db710571 | 131 | IE_NAME = 'daum.net:clip' |
11a4efc5 | 132 | _URL_TEMPLATE = 'http://tvpot.daum.net/clip/ClipView.do?clipid=%s' |
72033465 | 133 | |
134 | _TESTS = [{ | |
135 | 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690', | |
136 | 'info_dict': { | |
137 | 'id': '52554690', | |
138 | 'ext': 'mp4', | |
139 | 'title': 'DOTA 2GETHER 시즌2 6회 - 2부', | |
140 | 'description': 'DOTA 2GETHER 시즌2 6회 - 2부', | |
141 | 'upload_date': '20130831', | |
ec85ded8 | 142 | 'thumbnail': r're:^https?://.*\.(?:jpg|png)', |
72033465 | 143 | 'duration': 3868, |
144 | 'view_count': int, | |
145 | }, | |
b6c33fd5 | 146 | }, { |
147 | 'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425', | |
148 | 'only_matching': True, | |
72033465 | 149 | }] |
150 | ||
11a4efc5 YCH |
151 | @classmethod |
152 | def suitable(cls, url): | |
153 | return False if DaumPlaylistIE.suitable(url) or DaumUserIE.suitable(url) else super(DaumClipIE, cls).suitable(url) | |
154 | ||
72033465 | 155 | def _real_extract(self, url): |
156 | video_id = self._match_id(url) | |
126d7701 | 157 | clip_info = self._download_json( |
158 | 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?clipid=%s' % video_id, | |
159 | video_id, 'Downloading clip info')['clip_bean'] | |
72033465 | 160 | |
161 | return { | |
162 | '_type': 'url_transparent', | |
163 | 'id': video_id, | |
164 | 'url': 'http://tvpot.daum.net/v/%s' % clip_info['vid'], | |
2f0a33d8 | 165 | 'title': unescapeHTML(clip_info['title']), |
72033465 | 166 | 'thumbnail': clip_info.get('thumb_url'), |
167 | 'description': clip_info.get('contents'), | |
168 | 'duration': int_or_none(clip_info.get('duration')), | |
169 | 'upload_date': clip_info.get('up_date')[:8], | |
170 | 'view_count': int_or_none(clip_info.get('play_count')), | |
171 | 'ie_key': 'Daum', | |
150f2082 | 172 | } |
2f0a33d8 | 173 | |
174 | ||
175 | class DaumListIE(InfoExtractor): | |
176 | def _get_entries(self, list_id, list_id_type): | |
177 | name = None | |
178 | entries = [] | |
179 | for pagenum in itertools.count(1): | |
180 | list_info = self._download_json( | |
181 | 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?size=48&init=true&order=date&page=%d&%s=%s' % ( | |
7537b35f YCH |
182 | pagenum, list_id_type, list_id), list_id, 'Downloading list info - %s' % pagenum) |
183 | ||
2f0a33d8 | 184 | entries.extend([ |
185 | self.url_result( | |
186 | 'http://tvpot.daum.net/v/%s' % clip['vid']) | |
187 | for clip in list_info['clip_list'] | |
188 | ]) | |
189 | ||
190 | if not name: | |
191 | name = list_info.get('playlist_bean', {}).get('name') or \ | |
192 | list_info.get('potInfo', {}).get('name') | |
193 | ||
194 | if not list_info.get('has_more'): | |
195 | break | |
196 | ||
197 | return name, entries | |
198 | ||
11a4efc5 YCH |
199 | def _check_clip(self, url, list_id): |
200 | query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query) | |
201 | if 'clipid' in query_dict: | |
202 | clip_id = query_dict['clipid'][0] | |
203 | if self._downloader.params.get('noplaylist'): | |
204 | self.to_screen('Downloading just video %s because of --no-playlist' % clip_id) | |
205 | return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip') | |
206 | else: | |
207 | self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % list_id) | |
208 | ||
2f0a33d8 | 209 | |
210 | class DaumPlaylistIE(DaumListIE): | |
211 | _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View\.do|Top\.tv)\?.*?playlistid=(?P<id>[0-9]+)' | |
212 | IE_NAME = 'daum.net:playlist' | |
11a4efc5 | 213 | _URL_TEMPLATE = 'http://tvpot.daum.net/mypot/View.do?playlistid=%s' |
2f0a33d8 | 214 | |
215 | _TESTS = [{ | |
216 | 'note': 'Playlist url with clipid', | |
217 | 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844', | |
218 | 'info_dict': { | |
219 | 'id': '6213966', | |
220 | 'title': 'Woorissica Official', | |
221 | }, | |
222 | 'playlist_mincount': 181 | |
223 | }, { | |
224 | 'note': 'Playlist url with clipid - noplaylist', | |
225 | 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844', | |
226 | 'info_dict': { | |
227 | 'id': '73806844', | |
228 | 'ext': 'mp4', | |
229 | 'title': '151017 Airport', | |
230 | 'upload_date': '20160117', | |
231 | }, | |
232 | 'params': { | |
233 | 'noplaylist': True, | |
234 | 'skip_download': True, | |
235 | } | |
236 | }] | |
237 | ||
11a4efc5 YCH |
238 | @classmethod |
239 | def suitable(cls, url): | |
240 | return False if DaumUserIE.suitable(url) else super(DaumPlaylistIE, cls).suitable(url) | |
2f0a33d8 | 241 | |
11a4efc5 | 242 | def _real_extract(self, url): |
2f0a33d8 | 243 | list_id = self._match_id(url) |
11a4efc5 YCH |
244 | |
245 | clip_result = self._check_clip(url, list_id) | |
246 | if clip_result: | |
247 | return clip_result | |
2f0a33d8 | 248 | |
249 | name, entries = self._get_entries(list_id, 'playlistid') | |
250 | ||
251 | return self.playlist_result(entries, list_id, name) | |
252 | ||
253 | ||
254 | class DaumUserIE(DaumListIE): | |
dc724e0c | 255 | _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View|Top)\.(?:do|tv)\?.*?ownerid=(?P<id>[0-9a-zA-Z]+)' |
2f0a33d8 | 256 | IE_NAME = 'daum.net:user' |
257 | ||
258 | _TESTS = [{ | |
259 | 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0', | |
260 | 'info_dict': { | |
261 | 'id': 'o2scDLIVbHc0', | |
262 | 'title': '마이 리틀 텔레비전', | |
263 | }, | |
264 | 'playlist_mincount': 213 | |
265 | }, { | |
266 | 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&clipid=73801156', | |
267 | 'info_dict': { | |
268 | 'id': '73801156', | |
269 | 'ext': 'mp4', | |
270 | 'title': '[미공개] 김구라, 오만석이 부릅니다 \'오케피\' - 마이 리틀 텔레비전 20160116', | |
271 | 'upload_date': '20160117', | |
272 | 'description': 'md5:5e91d2d6747f53575badd24bd62b9f36' | |
273 | }, | |
274 | 'params': { | |
275 | 'noplaylist': True, | |
276 | 'skip_download': True, | |
277 | } | |
278 | }, { | |
279 | 'note': 'Playlist url has ownerid and playlistid, playlistid takes precedence', | |
280 | 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&playlistid=6196631', | |
281 | 'info_dict': { | |
282 | 'id': '6196631', | |
283 | 'title': '마이 리틀 텔레비전 - 20160109', | |
284 | }, | |
285 | 'playlist_count': 11 | |
286 | }, { | |
287 | 'url': 'http://tvpot.daum.net/mypot/Top.do?ownerid=o2scDLIVbHc0', | |
288 | 'only_matching': True, | |
dc724e0c YCH |
289 | }, { |
290 | 'url': 'http://m.tvpot.daum.net/mypot/Top.tv?ownerid=45x1okb1If50&playlistid=3569733', | |
291 | 'only_matching': True, | |
2f0a33d8 | 292 | }] |
293 | ||
294 | def _real_extract(self, url): | |
11a4efc5 | 295 | list_id = self._match_id(url) |
2f0a33d8 | 296 | |
11a4efc5 YCH |
297 | clip_result = self._check_clip(url, list_id) |
298 | if clip_result: | |
299 | return clip_result | |
300 | ||
301 | query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query) | |
302 | if 'playlistid' in query_dict: | |
303 | playlist_id = query_dict['playlistid'][0] | |
304 | return self.url_result(DaumPlaylistIE._URL_TEMPLATE % playlist_id, 'DaumPlaylist') | |
2f0a33d8 | 305 | |
2f0a33d8 | 306 | name, entries = self._get_entries(list_id, 'ownerid') |
307 | ||
308 | return self.playlist_result(entries, list_id, name) |