2 from __future__ import unicode_literals
5 from .common import InfoExtractor
10 from ..compat import compat_urlparse
13 class UDNEmbedIE(InfoExtractor):
15 _VALID_URL = r'https?://video\.udn\.com/(?:embed|play)/news/(?P<id>\d+)'
17 'url': 'http://video.udn.com/embed/news/300040',
18 'md5': 'de06b4c90b042c128395a88f0384817e',
22 'title': '生物老師男變女 全校挺"做自己"',
23 'thumbnail': 're:^https?://.*\.jpg$',
26 'url': 'https://video.udn.com/embed/news/300040',
27 'only_matching': True,
29 # From https://video.udn.com/news/303776
30 'url': 'https://video.udn.com/play/news/303776',
31 'only_matching': True,
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
37 page = self._download_webpage(url, video_id)
39 options = json.loads(js_to_json(self._html_search_regex(
40 r'var options\s*=\s*([^;]+);', page, 'video urls dictionary')))
42 video_urls = options['video']
44 if video_urls.get('youtube'):
45 return self.url_result(video_urls.get('youtube'), 'Youtube')
48 del video_urls['youtube']
53 'url': self._download_webpage(
54 compat_urlparse.urljoin(url, api_url), video_id,
55 'retrieve url for %s video' % video_type),
56 'format_id': video_type,
57 'preference': 0 if video_type == 'mp4' else -1,
58 } for video_type, api_url in video_urls.items() if api_url]
61 raise ExtractorError('No videos found', expected=True)
63 self._sort_formats(formats)
67 if options.get('gallery') and len(options['gallery']):
68 thumbnail = options['gallery'][0].get('original')
73 'title': options['title'],
74 'thumbnail': thumbnail