2 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..utils import js_to_json
7 from ..compat import compat_urlparse
10 class UDNEmbedIE(InfoExtractor):
11 _VALID_URL = r'(?:https?:)?//video\.udn\.com/embed/news/(?P<id>\d+)'
13 'url': 'http://video.udn.com/embed/news/300040',
14 'md5': 'de06b4c90b042c128395a88f0384817e',
18 'title': '生物老師男變女 全校挺"做自己"',
19 'thumbnail': 're:^https?://.*\.jpg$',
22 'url': '//video.udn.com/embed/news/300040',
23 'only_matching': True,
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
29 page = self._download_webpage(url, video_id)
31 options = json.loads(js_to_json(self._html_search_regex(
32 r'var options\s*=\s*([^;]+);', page, 'video urls dictionary')))
34 video_urls = options['video']
36 if video_urls.get('youtube'):
37 return self.url_result(video_urls.get('youtube'), 'Youtube')
40 del video_urls['youtube']
45 'url': self._download_webpage(
46 compat_urlparse.urljoin(url, api_url), video_id,
47 'retrieve url for %s video' % video_type),
48 'format_id': video_type,
49 'preference': 0 if video_type == 'mp4' else -1,
50 } for video_type, api_url in video_urls.items()]
52 self._sort_formats(formats)
56 if options.get('gallery') and len(options['gallery']):
57 thumbnail = options['gallery'][0].get('original')
62 'title': options['title'],
63 'thumbnail': thumbnail