2 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  10 from ..compat 
import compat_urlparse
 
  13 class UDNEmbedIE(InfoExtractor
): 
  15     _PROTOCOL_RELATIVE_VALID_URL 
= r
'//video\.udn\.com/(?:embed|play)/news/(?P<id>\d+)' 
  16     _VALID_URL 
= r
'https?:' + _PROTOCOL_RELATIVE_VALID_URL
 
  18         'url': 'http://video.udn.com/embed/news/300040', 
  19         'md5': 'de06b4c90b042c128395a88f0384817e', 
  23             'title': '生物老師男變女 全校挺"做自己"', 
  24             'thumbnail': 're:^https?://.*\.jpg$', 
  27         'url': 'https://video.udn.com/embed/news/300040', 
  28         'only_matching': True, 
  30         # From https://video.udn.com/news/303776 
  31         'url': 'https://video.udn.com/play/news/303776', 
  32         'only_matching': True, 
  35     def _real_extract(self
, url
): 
  36         video_id 
= self
._match
_id
(url
) 
  38         page 
= self
._download
_webpage
(url
, video_id
) 
  40         options 
= json
.loads(js_to_json(self
._html
_search
_regex
( 
  41             r
'var options\s*=\s*([^;]+);', page
, 'video urls dictionary'))) 
  43         video_urls 
= options
['video'] 
  45         if video_urls
.get('youtube'): 
  46             return self
.url_result(video_urls
.get('youtube'), 'Youtube') 
  49             del video_urls
['youtube'] 
  54             'url': self
._download
_webpage
( 
  55                 compat_urlparse
.urljoin(url
, api_url
), video_id
, 
  56                 'retrieve url for %s video' % video_type
), 
  57             'format_id': video_type
, 
  58             'preference': 0 if video_type 
== 'mp4' else -1, 
  59         } for video_type
, api_url 
in video_urls
.items() if api_url
] 
  62             raise ExtractorError('No videos found', expected
=True) 
  64         self
._sort
_formats
(formats
) 
  68         if options
.get('gallery') and len(options
['gallery']): 
  69             thumbnail 
= options
['gallery'][0].get('original') 
  74             'title': options
['title'], 
  75             'thumbnail': thumbnail