4 from .common
import InfoExtractor
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
16 _EMBED_REGEX
= [rf
'<iframe[^>]+src="(?:https?:)?(?P<url>{_PROTOCOL_RELATIVE_VALID_URL})"']
18 'url': 'http://video.udn.com/embed/news/300040',
22 'title': '生物老師男變女 全校挺"做自己"',
23 'thumbnail': r
're:^https?://.*\.jpg$',
27 'skip_download': True,
29 'expected_warnings': ['Failed to parse JSON Expecting value'],
31 'url': 'https://video.udn.com/embed/news/300040',
32 'only_matching': True,
34 # From https://video.udn.com/news/303776
35 'url': 'https://video.udn.com/play/news/303776',
36 'only_matching': True,
39 def _real_extract(self
, url
):
40 video_id
= self
._match
_id
(url
)
42 page
= self
._download
_webpage
(url
, video_id
)
44 options_str
= self
._html
_search
_regex
(
45 r
'var\s+options\s*=\s*([^;]+);', page
, 'options')
46 trans_options_str
= js_to_json(options_str
)
47 options
= self
._parse
_json
(trans_options_str
, 'options', fatal
=False) or {}
49 video_urls
= options
['video']
50 title
= options
['title']
51 poster
= options
.get('poster')
53 video_urls
= self
._parse
_json
(self
._html
_search
_regex
(
54 r
'"video"\s*:\s*({.+?})\s*,', trans_options_str
, 'video urls'), 'video urls')
55 title
= self
._html
_search
_regex
(
56 r
"title\s*:\s*'(.+?)'\s*,", options_str
, 'title')
57 poster
= self
._html
_search
_regex
(
58 r
"poster\s*:\s*'(.+?)'\s*,", options_str
, 'poster', default
=None)
60 if video_urls
.get('youtube'):
61 return self
.url_result(video_urls
.get('youtube'), 'Youtube')
64 for video_type
, api_url
in video_urls
.items():
68 video_url
= self
._download
_webpage
(
69 urllib
.parse
.urljoin(url
, api_url
), video_id
,
70 note
=f
'retrieve url for {video_type} video')
72 ext
= determine_ext(video_url
)
74 formats
.extend(self
._extract
_m
3u8_formats
(
75 video_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
77 formats
.extend(self
._extract
_f
4m
_formats
(
78 video_url
, video_id
, f4m_id
='hds'))
80 mobj
= re
.search(r
'_(?P<height>\d+)p_(?P<tbr>\d+)\.mp4', video_url
)
83 # video_type may be 'mp4', which confuses YoutubeDL
84 'format_id': 'http-' + video_type
,
88 'height': int_or_none(mobj
.group('height')),
89 'tbr': int_or_none(mobj
.group('tbr')),
91 formats
.append(a_format
)