2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
13 from ..compat
import compat_urlparse
16 class UDNEmbedIE(InfoExtractor
):
18 _PROTOCOL_RELATIVE_VALID_URL
= r
'//video\.udn\.com/(?:embed|play)/news/(?P<id>\d+)'
19 _VALID_URL
= r
'https?:' + _PROTOCOL_RELATIVE_VALID_URL
21 'url': 'http://video.udn.com/embed/news/300040',
25 'title': '生物老師男變女 全校挺"做自己"',
26 'thumbnail': 're:^https?://.*\.jpg$',
30 'skip_download': True,
33 'url': 'https://video.udn.com/embed/news/300040',
34 'only_matching': True,
36 # From https://video.udn.com/news/303776
37 'url': 'https://video.udn.com/play/news/303776',
38 'only_matching': True,
41 def _real_extract(self
, url
):
42 video_id
= self
._match
_id
(url
)
44 page
= self
._download
_webpage
(url
, video_id
)
46 options
= json
.loads(js_to_json(self
._html
_search
_regex
(
47 r
'var\s+options\s*=\s*([^;]+);', page
, 'video urls dictionary')))
49 video_urls
= options
['video']
51 if video_urls
.get('youtube'):
52 return self
.url_result(video_urls
.get('youtube'), 'Youtube')
55 for video_type
, api_url
in video_urls
.items():
59 video_url
= self
._download
_webpage
(
60 compat_urlparse
.urljoin(url
, api_url
), video_id
,
61 note
='retrieve url for %s video' % video_type
)
63 ext
= determine_ext(video_url
)
65 formats
.extend(self
._extract
_m
3u8_formats
(
66 video_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
68 formats
.extend(self
._extract
_f
4m
_formats
(
69 video_url
, video_id
, f4m_id
='hds'))
71 mobj
= re
.search(r
'_(?P<height>\d+)p_(?P<tbr>\d+).mp4', video_url
)
74 # video_type may be 'mp4', which confuses YoutubeDL
75 'format_id': 'http-' + video_type
,
79 'height': int_or_none(mobj
.group('height')),
80 'tbr': int_or_none(mobj
.group('tbr')),
82 formats
.append(a_format
)
84 self
._sort
_formats
(formats
)
89 } for img_type
, img_url
in options
.get('gallery', [{}])[0].items() if img_url
]
94 'title': options
['title'],
95 'thumbnails': thumbnails
,