startrek.py 3.7 KB

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