]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/daum.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / daum.py
1 import itertools
2 import urllib.parse
3
4 from .common import InfoExtractor
5 from ..utils import parse_qs
6
7
8 class DaumBaseIE(InfoExtractor):
9 _KAKAO_EMBED_BASE = 'http://tv.kakao.com/embed/player/cliplink/'
10
11
12 class DaumIE(DaumBaseIE):
13 _VALID_URL = r'https?://(?:(?:m\.)?tvpot\.daum\.net/v/|videofarm\.daum\.net/controller/player/VodPlayer\.swf\?vid=)(?P<id>[^?#&]+)'
14 IE_NAME = 'daum.net'
15
16 _TESTS = [{
17 'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
18 'info_dict': {
19 'id': 'vab4dyeDBysyBssyukBUjBz',
20 'ext': 'mp4',
21 'title': '마크 헌트 vs 안토니오 실바',
22 'description': 'Mark Hunt vs Antonio Silva',
23 'upload_date': '20131217',
24 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
25 'duration': 2117,
26 'view_count': int,
27 'comment_count': int,
28 'uploader_id': '186139',
29 'uploader': '콘간지',
30 'timestamp': 1387310323,
31 },
32 }, {
33 'url': 'http://m.tvpot.daum.net/v/65139429',
34 'info_dict': {
35 'id': '65139429',
36 'ext': 'mp4',
37 'title': '1297회, \'아빠 아들로 태어나길 잘 했어\' 민수, 감동의 눈물[아빠 어디가] 20150118',
38 'description': 'md5:79794514261164ff27e36a21ad229fc5',
39 'upload_date': '20150118',
40 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
41 'duration': 154,
42 'view_count': int,
43 'comment_count': int,
44 'uploader': 'MBC 예능',
45 'uploader_id': '132251',
46 'timestamp': 1421604228,
47 },
48 }, {
49 'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
50 'only_matching': True,
51 }, {
52 'url': 'http://videofarm.daum.net/controller/player/VodPlayer.swf?vid=vwIpVpCQsT8%24&ref=',
53 'info_dict': {
54 'id': 'vwIpVpCQsT8$',
55 'ext': 'flv',
56 'title': '01-Korean War ( Trouble on the horizon )',
57 'description': 'Korean War 01\r\nTrouble on the horizon\r\n전쟁의 먹구름',
58 'upload_date': '20080223',
59 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
60 'duration': 249,
61 'view_count': int,
62 'comment_count': int,
63 'uploader': '까칠한 墮落始祖 황비홍님의',
64 'uploader_id': '560824',
65 'timestamp': 1203770745,
66 },
67 }, {
68 # Requires dte_type=WEB (#9972)
69 'url': 'http://tvpot.daum.net/v/s3794Uf1NZeZ1qMpGpeqeRU',
70 'md5': 'a8917742069a4dd442516b86e7d66529',
71 'info_dict': {
72 'id': 's3794Uf1NZeZ1qMpGpeqeRU',
73 'ext': 'mp4',
74 'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)',
75 'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\r\n\r\n[쇼! 음악중심] 20160611, 507회',
76 'upload_date': '20170129',
77 'uploader': '쇼! 음악중심',
78 'uploader_id': '2653210',
79 'timestamp': 1485684628,
80 },
81 }]
82
83 def _real_extract(self, url):
84 video_id = urllib.parse.unquote(self._match_id(url))
85 if not video_id.isdigit():
86 video_id += '@my'
87 return self.url_result(
88 self._KAKAO_EMBED_BASE + video_id, 'Kakao', video_id)
89
90
91 class DaumClipIE(DaumBaseIE):
92 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)'
93 IE_NAME = 'daum.net:clip'
94 _URL_TEMPLATE = 'http://tvpot.daum.net/clip/ClipView.do?clipid=%s'
95
96 _TESTS = [{
97 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
98 'info_dict': {
99 'id': '52554690',
100 'ext': 'mp4',
101 'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
102 'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
103 'upload_date': '20130831',
104 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
105 'duration': 3868,
106 'view_count': int,
107 'uploader': 'GOMeXP',
108 'uploader_id': '6667',
109 'timestamp': 1377911092,
110 },
111 }, {
112 'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425',
113 'only_matching': True,
114 }]
115
116 @classmethod
117 def suitable(cls, url):
118 return False if DaumPlaylistIE.suitable(url) or DaumUserIE.suitable(url) else super().suitable(url)
119
120 def _real_extract(self, url):
121 video_id = self._match_id(url)
122 return self.url_result(
123 self._KAKAO_EMBED_BASE + video_id, 'Kakao', video_id)
124
125
126 class DaumListIE(InfoExtractor): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
127 def _get_entries(self, list_id, list_id_type):
128 name = None
129 entries = []
130 for pagenum in itertools.count(1):
131 list_info = self._download_json(
132 f'http://tvpot.daum.net/mypot/json/GetClipInfo.do?size=48&init=true&order=date&page={pagenum}&{list_id_type}={list_id}',
133 list_id, f'Downloading list info - {pagenum}')
134
135 entries.extend([
136 self.url_result(
137 'http://tvpot.daum.net/v/{}'.format(clip['vid']))
138 for clip in list_info['clip_list']
139 ])
140
141 if not name:
142 name = list_info.get('playlist_bean', {}).get('name') or \
143 list_info.get('potInfo', {}).get('name')
144
145 if not list_info.get('has_more'):
146 break
147
148 return name, entries
149
150 def _check_clip(self, url, list_id):
151 query_dict = parse_qs(url)
152 if 'clipid' in query_dict:
153 clip_id = query_dict['clipid'][0]
154 if not self._yes_playlist(list_id, clip_id):
155 return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip')
156
157
158 class DaumPlaylistIE(DaumListIE):
159 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View\.do|Top\.tv)\?.*?playlistid=(?P<id>[0-9]+)'
160 IE_NAME = 'daum.net:playlist'
161 _URL_TEMPLATE = 'http://tvpot.daum.net/mypot/View.do?playlistid=%s'
162
163 _TESTS = [{
164 'note': 'Playlist url with clipid',
165 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
166 'info_dict': {
167 'id': '6213966',
168 'title': 'Woorissica Official',
169 },
170 'playlist_mincount': 181,
171 }, {
172 'note': 'Playlist url with clipid - noplaylist',
173 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
174 'info_dict': {
175 'id': '73806844',
176 'ext': 'mp4',
177 'title': '151017 Airport',
178 'upload_date': '20160117',
179 },
180 'params': {
181 'noplaylist': True,
182 'skip_download': True,
183 },
184 }]
185
186 @classmethod
187 def suitable(cls, url):
188 return False if DaumUserIE.suitable(url) else super().suitable(url)
189
190 def _real_extract(self, url):
191 list_id = self._match_id(url)
192
193 clip_result = self._check_clip(url, list_id)
194 if clip_result:
195 return clip_result
196
197 name, entries = self._get_entries(list_id, 'playlistid')
198
199 return self.playlist_result(entries, list_id, name)
200
201
202 class DaumUserIE(DaumListIE):
203 _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View|Top)\.(?:do|tv)\?.*?ownerid=(?P<id>[0-9a-zA-Z]+)'
204 IE_NAME = 'daum.net:user'
205
206 _TESTS = [{
207 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0',
208 'info_dict': {
209 'id': 'o2scDLIVbHc0',
210 'title': '마이 리틀 텔레비전',
211 },
212 'playlist_mincount': 213,
213 }, {
214 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&clipid=73801156',
215 'info_dict': {
216 'id': '73801156',
217 'ext': 'mp4',
218 'title': '[미공개] 김구라, 오만석이 부릅니다 \'오케피\' - 마이 리틀 텔레비전 20160116',
219 'upload_date': '20160117',
220 'description': 'md5:5e91d2d6747f53575badd24bd62b9f36',
221 },
222 'params': {
223 'noplaylist': True,
224 'skip_download': True,
225 },
226 }, {
227 'note': 'Playlist url has ownerid and playlistid, playlistid takes precedence',
228 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&playlistid=6196631',
229 'info_dict': {
230 'id': '6196631',
231 'title': '마이 리틀 텔레비전 - 20160109',
232 },
233 'playlist_count': 11,
234 }, {
235 'url': 'http://tvpot.daum.net/mypot/Top.do?ownerid=o2scDLIVbHc0',
236 'only_matching': True,
237 }, {
238 'url': 'http://m.tvpot.daum.net/mypot/Top.tv?ownerid=45x1okb1If50&playlistid=3569733',
239 'only_matching': True,
240 }]
241
242 def _real_extract(self, url):
243 list_id = self._match_id(url)
244
245 clip_result = self._check_clip(url, list_id)
246 if clip_result:
247 return clip_result
248
249 query_dict = parse_qs(url)
250 if 'playlistid' in query_dict:
251 playlist_id = query_dict['playlistid'][0]
252 return self.url_result(DaumPlaylistIE._URL_TEMPLATE % playlist_id, 'DaumPlaylist')
253
254 name, entries = self._get_entries(list_id, 'ownerid')
255
256 return self.playlist_result(entries, list_id, name)