]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/daum.py
[brightcove:legacy] Support 'playlistTabs' and skip a dead test
[yt-dlp.git] / youtube_dl / extractor / daum.py
CommitLineData
150f2082 1# encoding: utf-8
23f4a93b
PH
2
3from __future__ import unicode_literals
4
b6c33fd5 5import re
2f0a33d8 6import itertools
b6c33fd5 7
150f2082 8from .common import InfoExtractor
830afe85 9from ..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 15from ..utils import (
16 int_or_none,
17 str_to_int,
18 xpath_text,
2f0a33d8 19 unescapeHTML,
150f2082
JMF
20)
21
22
23class 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',
0179f6a8 35 'thumbnail': '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',
0179f6a8 48 'thumbnail': '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',
0179f6a8 64 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
830afe85
YCH
65 'duration': 249,
66 'view_count': int,
67 'comment_count': int,
68 },
e5a79071 69 }]
150f2082
JMF
70
71 def _real_extract(self, url):
830afe85 72 video_id = compat_urllib_parse_unquote(self._match_id(url))
15707c7e 73 query = compat_urllib_parse_urlencode({'vid': video_id})
72033465 74 movie_data = self._download_json(
75 'http://videofarm.daum.net/controller/api/closed/v1_2/IntegratedMovieData.json?' + query,
23f4a93b 76 video_id, 'Downloading video formats info')
150f2082 77
b6c33fd5 78 # For urls like http://m.tvpot.daum.net/v/65139429, where the video_id is really a clipid
79 if not movie_data.get('output_list', {}).get('output_list') and re.match(r'^\d+$', video_id):
80 return self.url_result('http://tvpot.daum.net/clip/ClipView.do?clipid=%s' % video_id)
81
06ffa334
YCH
82 info = self._download_xml(
83 'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
84 'Downloading video info')
85
150f2082 86 formats = []
72033465 87 for format_el in movie_data['output_list']['output_list']:
88 profile = format_el['profile']
15707c7e 89 format_query = compat_urllib_parse_urlencode({
72033465 90 'vid': video_id,
150f2082
JMF
91 'profile': profile,
92 })
e26f8712 93 url_doc = self._download_xml(
150f2082 94 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
e5a79071 95 video_id, note='Downloading video data for %s format' % profile)
150f2082
JMF
96 format_url = url_doc.find('result/url').text
97 formats.append({
98 'url': format_url,
150f2082 99 'format_id': profile,
72033465 100 'width': int_or_none(format_el.get('width')),
101 'height': int_or_none(format_el.get('height')),
102 'filesize': int_or_none(format_el.get('filesize')),
150f2082 103 })
72033465 104 self._sort_formats(formats)
150f2082 105
fb7abb31 106 return {
150f2082
JMF
107 'id': video_id,
108 'title': info.find('TITLE').text,
109 'formats': formats,
126d7701 110 'thumbnail': xpath_text(info, 'THUMB_URL'),
111 'description': xpath_text(info, 'CONTENTS'),
112 'duration': int_or_none(xpath_text(info, 'DURATION')),
150f2082 113 'upload_date': info.find('REGDTTM').text[:8],
126d7701 114 'view_count': str_to_int(xpath_text(info, 'PLAY_CNT')),
115 'comment_count': str_to_int(xpath_text(info, 'COMMENT_CNT')),
150f2082 116 }
72033465 117
118
119class DaumClipIE(InfoExtractor):
b6c33fd5 120 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)'
db710571 121 IE_NAME = 'daum.net:clip'
11a4efc5 122 _URL_TEMPLATE = 'http://tvpot.daum.net/clip/ClipView.do?clipid=%s'
72033465 123
124 _TESTS = [{
125 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
126 'info_dict': {
127 'id': '52554690',
128 'ext': 'mp4',
129 'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
130 'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
131 'upload_date': '20130831',
0179f6a8 132 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
72033465 133 'duration': 3868,
134 'view_count': int,
135 },
b6c33fd5 136 }, {
137 'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425',
138 'only_matching': True,
72033465 139 }]
140
11a4efc5
YCH
141 @classmethod
142 def suitable(cls, url):
143 return False if DaumPlaylistIE.suitable(url) or DaumUserIE.suitable(url) else super(DaumClipIE, cls).suitable(url)
144
72033465 145 def _real_extract(self, url):
146 video_id = self._match_id(url)
126d7701 147 clip_info = self._download_json(
148 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?clipid=%s' % video_id,
149 video_id, 'Downloading clip info')['clip_bean']
72033465 150
151 return {
152 '_type': 'url_transparent',
153 'id': video_id,
154 'url': 'http://tvpot.daum.net/v/%s' % clip_info['vid'],
2f0a33d8 155 'title': unescapeHTML(clip_info['title']),
72033465 156 'thumbnail': clip_info.get('thumb_url'),
157 'description': clip_info.get('contents'),
158 'duration': int_or_none(clip_info.get('duration')),
159 'upload_date': clip_info.get('up_date')[:8],
160 'view_count': int_or_none(clip_info.get('play_count')),
161 'ie_key': 'Daum',
150f2082 162 }
2f0a33d8 163
164
165class DaumListIE(InfoExtractor):
166 def _get_entries(self, list_id, list_id_type):
167 name = None
168 entries = []
169 for pagenum in itertools.count(1):
170 list_info = self._download_json(
171 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?size=48&init=true&order=date&page=%d&%s=%s' % (
7537b35f
YCH
172 pagenum, list_id_type, list_id), list_id, 'Downloading list info - %s' % pagenum)
173
2f0a33d8 174 entries.extend([
175 self.url_result(
176 'http://tvpot.daum.net/v/%s' % clip['vid'])
177 for clip in list_info['clip_list']
178 ])
179
180 if not name:
181 name = list_info.get('playlist_bean', {}).get('name') or \
182 list_info.get('potInfo', {}).get('name')
183
184 if not list_info.get('has_more'):
185 break
186
187 return name, entries
188
11a4efc5
YCH
189 def _check_clip(self, url, list_id):
190 query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query)
191 if 'clipid' in query_dict:
192 clip_id = query_dict['clipid'][0]
193 if self._downloader.params.get('noplaylist'):
194 self.to_screen('Downloading just video %s because of --no-playlist' % clip_id)
195 return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip')
196 else:
197 self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % list_id)
198
2f0a33d8 199
200class DaumPlaylistIE(DaumListIE):
201 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View\.do|Top\.tv)\?.*?playlistid=(?P<id>[0-9]+)'
202 IE_NAME = 'daum.net:playlist'
11a4efc5 203 _URL_TEMPLATE = 'http://tvpot.daum.net/mypot/View.do?playlistid=%s'
2f0a33d8 204
205 _TESTS = [{
206 'note': 'Playlist url with clipid',
207 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
208 'info_dict': {
209 'id': '6213966',
210 'title': 'Woorissica Official',
211 },
212 'playlist_mincount': 181
213 }, {
214 'note': 'Playlist url with clipid - noplaylist',
215 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
216 'info_dict': {
217 'id': '73806844',
218 'ext': 'mp4',
219 'title': '151017 Airport',
220 'upload_date': '20160117',
221 },
222 'params': {
223 'noplaylist': True,
224 'skip_download': True,
225 }
226 }]
227
11a4efc5
YCH
228 @classmethod
229 def suitable(cls, url):
230 return False if DaumUserIE.suitable(url) else super(DaumPlaylistIE, cls).suitable(url)
2f0a33d8 231
11a4efc5 232 def _real_extract(self, url):
2f0a33d8 233 list_id = self._match_id(url)
11a4efc5
YCH
234
235 clip_result = self._check_clip(url, list_id)
236 if clip_result:
237 return clip_result
2f0a33d8 238
239 name, entries = self._get_entries(list_id, 'playlistid')
240
241 return self.playlist_result(entries, list_id, name)
242
243
244class DaumUserIE(DaumListIE):
dc724e0c 245 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View|Top)\.(?:do|tv)\?.*?ownerid=(?P<id>[0-9a-zA-Z]+)'
2f0a33d8 246 IE_NAME = 'daum.net:user'
247
248 _TESTS = [{
249 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0',
250 'info_dict': {
251 'id': 'o2scDLIVbHc0',
252 'title': '마이 리틀 텔레비전',
253 },
254 'playlist_mincount': 213
255 }, {
256 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&clipid=73801156',
257 'info_dict': {
258 'id': '73801156',
259 'ext': 'mp4',
260 'title': '[미공개] 김구라, 오만석이 부릅니다 \'오케피\' - 마이 리틀 텔레비전 20160116',
261 'upload_date': '20160117',
262 'description': 'md5:5e91d2d6747f53575badd24bd62b9f36'
263 },
264 'params': {
265 'noplaylist': True,
266 'skip_download': True,
267 }
268 }, {
269 'note': 'Playlist url has ownerid and playlistid, playlistid takes precedence',
270 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&playlistid=6196631',
271 'info_dict': {
272 'id': '6196631',
273 'title': '마이 리틀 텔레비전 - 20160109',
274 },
275 'playlist_count': 11
276 }, {
277 'url': 'http://tvpot.daum.net/mypot/Top.do?ownerid=o2scDLIVbHc0',
278 'only_matching': True,
dc724e0c
YCH
279 }, {
280 'url': 'http://m.tvpot.daum.net/mypot/Top.tv?ownerid=45x1okb1If50&playlistid=3569733',
281 'only_matching': True,
2f0a33d8 282 }]
283
284 def _real_extract(self, url):
11a4efc5 285 list_id = self._match_id(url)
2f0a33d8 286
11a4efc5
YCH
287 clip_result = self._check_clip(url, list_id)
288 if clip_result:
289 return clip_result
290
291 query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query)
292 if 'playlistid' in query_dict:
293 playlist_id = query_dict['playlistid'][0]
294 return self.url_result(DaumPlaylistIE._URL_TEMPLATE % playlist_id, 'DaumPlaylist')
2f0a33d8 295
2f0a33d8 296 name, entries = self._get_entries(list_id, 'ownerid')
297
298 return self.playlist_result(entries, list_id, name)