3 from .common
import InfoExtractor
9 from ..compat
import compat_urlparse
12 class UDNEmbedIE(InfoExtractor
):
14 _PROTOCOL_RELATIVE_VALID_URL
= r
'//video\.udn\.com/(?:embed|play)/news/(?P<id>\d+)'
15 _VALID_URL
= r
'https?:' + _PROTOCOL_RELATIVE_VALID_URL
17 'url': 'http://video.udn.com/embed/news/300040',
21 'title': '生物老師男變女 全校挺"做自己"',
22 'thumbnail': r
're:^https?://.*\.jpg$',
26 'skip_download': True,
28 'expected_warnings': ['Failed to parse JSON Expecting value'],
30 'url': 'https://video.udn.com/embed/news/300040',
31 'only_matching': True,
33 # From https://video.udn.com/news/303776
34 'url': 'https://video.udn.com/play/news/303776',
35 'only_matching': True,
38 def _real_extract(self
, url
):
39 video_id
= self
._match
_id
(url
)
41 page
= self
._download
_webpage
(url
, video_id
)
43 options_str
= self
._html
_search
_regex
(
44 r
'var\s+options\s*=\s*([^;]+);', page
, 'options')
45 trans_options_str
= js_to_json(options_str
)
46 options
= self
._parse
_json
(trans_options_str
, 'options', fatal
=False) or {}
48 video_urls
= options
['video']
49 title
= options
['title']
50 poster
= options
.get('poster')
52 video_urls
= self
._parse
_json
(self
._html
_search
_regex
(
53 r
'"video"\s*:\s*({.+?})\s*,', trans_options_str
, 'video urls'), 'video urls')
54 title
= self
._html
_search
_regex
(
55 r
"title\s*:\s*'(.+?)'\s*,", options_str
, 'title')
56 poster
= self
._html
_search
_regex
(
57 r
"poster\s*:\s*'(.+?)'\s*,", options_str
, 'poster', default
=None)
59 if video_urls
.get('youtube'):
60 return self
.url_result(video_urls
.get('youtube'), 'Youtube')
63 for video_type
, api_url
in video_urls
.items():
67 video_url
= self
._download
_webpage
(
68 compat_urlparse
.urljoin(url
, api_url
), video_id
,
69 note
='retrieve url for %s video' % video_type
)
71 ext
= determine_ext(video_url
)
73 formats
.extend(self
._extract
_m
3u8_formats
(
74 video_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
76 formats
.extend(self
._extract
_f
4m
_formats
(
77 video_url
, video_id
, f4m_id
='hds'))
79 mobj
= re
.search(r
'_(?P<height>\d+)p_(?P<tbr>\d+)\.mp4', video_url
)
82 # video_type may be 'mp4', which confuses YoutubeDL
83 'format_id': 'http-' + video_type
,
87 'height': int_or_none(mobj
.group('height')),
88 'tbr': int_or_none(mobj
.group('tbr')),
90 formats
.append(a_format
)
92 self
._sort
_formats
(formats
)