]>
Commit | Line | Data |
---|---|---|
eb2333bc TW |
1 | from .common import InfoExtractor |
2 | from ..utils import int_or_none, urljoin | |
3 | ||
4 | ||
5 | class StarTrekIE(InfoExtractor): | |
6 | _VALID_URL = r'(?P<base>https?://(?:intl|www)\.startrek\.com)/videos/(?P<id>[^/]+)' | |
7 | _TESTS = [{ | |
8 | 'url': 'https://intl.startrek.com/videos/watch-welcoming-jess-bush-to-the-ready-room', | |
9 | 'md5': '491df5035c9d4dc7f63c79caaf9c839e', | |
10 | 'info_dict': { | |
11 | 'id': 'watch-welcoming-jess-bush-to-the-ready-room', | |
12 | 'ext': 'mp4', | |
13 | 'title': 'WATCH: Welcoming Jess Bush to The Ready Room', | |
14 | 'duration': 1888, | |
15 | 'timestamp': 1655388000, | |
16 | 'upload_date': '20220616', | |
17 | 'description': 'md5:1ffee884e3920afbdd6dd04e926a1221', | |
18 | 'thumbnail': r're:https://(?:intl|www)\.startrek\.com/sites/default/files/styles/video_1920x1080/public/images/2022-06/pp_14794_rr_thumb_107_yt_16x9\.jpg(?:\?.+)?', | |
19 | 'subtitles': {'en-US': [{ | |
20 | 'url': r're:https://(?:intl|www)\.startrek\.com/sites/default/files/video/captions/2022-06/TRR_SNW_107_v4\.vtt', | |
21 | }, { | |
22 | 'url': 'https://media.startrek.com/2022/06/16/2043801155561/1069981_hls/trr_snw_107_v4-c4bfc25d/stream_vtt.m3u8', | |
23 | }]}, | |
24 | } | |
25 | }, { | |
26 | 'url': 'https://www.startrek.com/videos/watch-ethan-peck-and-gia-sandhu-beam-down-to-the-ready-room', | |
27 | 'md5': 'f5ad74fbb86e91e0882fc0a333178d1d', | |
28 | 'info_dict': { | |
29 | 'id': 'watch-ethan-peck-and-gia-sandhu-beam-down-to-the-ready-room', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'WATCH: Ethan Peck and Gia Sandhu Beam Down to The Ready Room', | |
32 | 'duration': 1986, | |
33 | 'timestamp': 1654221600, | |
34 | 'upload_date': '20220603', | |
35 | 'description': 'md5:b3aa0edacfe119386567362dec8ed51b', | |
36 | 'thumbnail': r're:https://www\.startrek\.com/sites/default/files/styles/video_1920x1080/public/images/2022-06/pp_14792_rr_thumb_105_yt_16x9_1.jpg(?:\?.+)?', | |
37 | 'subtitles': {'en-US': [{ | |
38 | 'url': r're:https://(?:intl|www)\.startrek\.com/sites/default/files/video/captions/2022-06/TRR_SNW_105_v5\.vtt', | |
39 | }]}, | |
40 | } | |
41 | }] | |
42 | ||
43 | def _real_extract(self, url): | |
44 | urlbase, video_id = self._match_valid_url(url).group('base', 'id') | |
45 | webpage = self._download_webpage(url, video_id) | |
46 | ||
47 | player = self._search_regex( | |
48 | r'(<\s*div\s+id\s*=\s*"cvp-player-[^<]+<\s*/div\s*>)', webpage, 'player') | |
49 | ||
50 | hls = self._html_search_regex(r'\bdata-hls\s*=\s*"([^"]+)"', player, 'HLS URL') | |
51 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(hls, video_id, 'mp4') | |
52 | self._sort_formats(formats) | |
53 | ||
54 | captions = self._html_search_regex( | |
55 | r'\bdata-captions-url\s*=\s*"([^"]+)"', player, 'captions URL', fatal=False) | |
56 | if captions: | |
57 | subtitles.setdefault('en-US', [])[:0] = [{'url': urljoin(urlbase, captions)}] | |
58 | ||
59 | # NB: Most of the data in the json_ld is undesirable | |
60 | json_ld = self._search_json_ld(webpage, video_id, fatal=False) | |
61 | ||
62 | return { | |
63 | 'id': video_id, | |
64 | 'title': self._html_search_regex( | |
65 | r'\bdata-title\s*=\s*"([^"]+)"', player, 'title', json_ld.get('title')), | |
66 | 'description': self._html_search_regex( | |
67 | r'(?s)<\s*div\s+class\s*=\s*"header-body"\s*>(.+?)<\s*/div\s*>', | |
68 | webpage, 'description', fatal=False), | |
69 | 'duration': int_or_none(self._html_search_regex( | |
70 | r'\bdata-duration\s*=\s*"(\d+)"', player, 'duration', fatal=False)), | |
71 | 'formats': formats, | |
72 | 'subtitles': subtitles, | |
73 | 'thumbnail': urljoin(urlbase, self._html_search_regex( | |
74 | r'\bdata-poster-url\s*=\s*"([^"]+)"', player, 'thumbnail', fatal=False)), | |
75 | 'timestamp': json_ld.get('timestamp'), | |
76 | } |