sky.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. extract_attributes,
  5. smuggle_url,
  6. strip_or_none,
  7. urljoin,
  8. )
  9. class SkyBaseIE(InfoExtractor):
  10. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
  11. _SDC_EL_REGEX = r'(?s)(<div[^>]+data-(?:component-name|fn)="sdc-(?:articl|sit)e-video"[^>]*>)'
  12. def _process_ooyala_element(self, webpage, sdc_el, url):
  13. sdc = extract_attributes(sdc_el)
  14. provider = sdc.get('data-provider')
  15. if provider == 'ooyala':
  16. video_id = sdc['data-sdc-video-id']
  17. video_url = 'ooyala:%s' % video_id
  18. ie_key = 'Ooyala'
  19. ooyala_el = self._search_regex(
  20. r'(<div[^>]+class="[^"]*\bsdc-article-video__media-ooyala\b[^"]*"[^>]+data-video-id="%s"[^>]*>)' % video_id,
  21. webpage, 'video data', fatal=False)
  22. if ooyala_el:
  23. ooyala_attrs = extract_attributes(ooyala_el) or {}
  24. if ooyala_attrs.get('data-token-required') == 'true':
  25. token_fetch_url = (self._parse_json(ooyala_attrs.get(
  26. 'data-token-fetch-options', '{}'),
  27. video_id, fatal=False) or {}).get('url')
  28. if token_fetch_url:
  29. embed_token = self._download_json(urljoin(
  30. url, token_fetch_url), video_id, fatal=False)
  31. if embed_token:
  32. video_url = smuggle_url(
  33. video_url, {'embed_token': embed_token})
  34. elif provider == 'brightcove':
  35. video_id = sdc['data-video-id']
  36. account_id = sdc.get('data-account-id') or '6058004172001'
  37. player_id = sdc.get('data-player-id') or 'RC9PQUaJ6'
  38. video_url = self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id)
  39. ie_key = 'BrightcoveNew'
  40. return {
  41. '_type': 'url_transparent',
  42. 'id': video_id,
  43. 'url': video_url,
  44. 'ie_key': ie_key,
  45. }
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. webpage = self._download_webpage(url, video_id)
  49. info = self._process_ooyala_element(webpage, self._search_regex(
  50. self._SDC_EL_REGEX, webpage, 'sdc element'), url)
  51. info.update({
  52. 'title': self._og_search_title(webpage),
  53. 'description': strip_or_none(self._og_search_description(webpage)),
  54. })
  55. return info
  56. class SkySportsIE(SkyBaseIE):
  57. IE_NAME = 'sky:sports'
  58. _VALID_URL = r'https?://(?:www\.)?skysports\.com/watch/video/([^/]+/)*(?P<id>[0-9]+)'
  59. _TESTS = [{
  60. 'url': 'http://www.skysports.com/watch/video/10328419/bale-its-our-time-to-shine',
  61. 'md5': '77d59166cddc8d3cb7b13e35eaf0f5ec',
  62. 'info_dict': {
  63. 'id': 'o3eWJnNDE6l7kfNO8BOoBlRxXRQ4ANNQ',
  64. 'ext': 'mp4',
  65. 'title': 'Bale: It\'s our time to shine',
  66. 'description': 'md5:e88bda94ae15f7720c5cb467e777bb6d',
  67. },
  68. 'add_ie': ['Ooyala'],
  69. }, {
  70. 'url': 'https://www.skysports.com/watch/video/sports/f1/12160544/abu-dhabi-gp-the-notebook',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'https://www.skysports.com/watch/video/tv-shows/12118508/rainford-brent-how-ace-programme-helps',
  74. 'only_matching': True,
  75. }]
  76. class SkyNewsIE(SkyBaseIE):
  77. IE_NAME = 'sky:news'
  78. _VALID_URL = r'https?://news\.sky\.com/video/[0-9a-z-]+-(?P<id>[0-9]+)'
  79. _TEST = {
  80. 'url': 'https://news.sky.com/video/russian-plane-inspected-after-deadly-fire-11712962',
  81. 'md5': '411e8893fd216c75eaf7e4c65d364115',
  82. 'info_dict': {
  83. 'id': 'ref:1ua21xaDE6lCtZDmbYfl8kwsKLooJbNM',
  84. 'ext': 'mp4',
  85. 'title': 'Russian plane inspected after deadly fire',
  86. 'description': 'The Russian Investigative Committee has released video of the wreckage of a passenger plane which caught fire near Moscow.',
  87. 'uploader_id': '6058004172001',
  88. 'timestamp': 1567112345,
  89. 'upload_date': '20190829',
  90. },
  91. 'add_ie': ['BrightcoveNew'],
  92. }
  93. class SkyNewsStoryIE(SkyBaseIE):
  94. IE_NAME = 'sky:news:story'
  95. _VALID_URL = r'https?://news\.sky\.com/story/[0-9a-z-]+-(?P<id>[0-9]+)'
  96. _TEST = {
  97. 'url': 'https://news.sky.com/story/budget-2021-chancellor-rishi-sunak-vows-address-will-deliver-strong-economy-fit-for-a-new-age-of-optimism-12445425',
  98. 'info_dict': {
  99. 'id': 'ref:0714acb9-123d-42c8-91b8-5c1bc6c73f20',
  100. 'title': 'md5:e408dd7aad63f31a1817bbe40c7d276f',
  101. 'description': 'md5:a881e12f49212f92be2befe4a09d288a',
  102. 'ext': 'mp4',
  103. 'upload_date': '20211027',
  104. 'timestamp': 1635317494,
  105. 'uploader_id': '6058004172001',
  106. }
  107. }
  108. def _real_extract(self, url):
  109. article_id = self._match_id(url)
  110. webpage = self._download_webpage(url, article_id)
  111. entries = [self._process_ooyala_element(webpage, sdc_el, url)
  112. for sdc_el in re.findall(self._SDC_EL_REGEX, webpage)]
  113. return self.playlist_result(
  114. entries, article_id, self._og_search_title(webpage),
  115. self._html_search_meta(['og:description', 'description'], webpage))
  116. class SkySportsNewsIE(SkyBaseIE):
  117. IE_NAME = 'sky:sports:news'
  118. _VALID_URL = r'https?://(?:www\.)?skysports\.com/([^/]+/)*news/\d+/(?P<id>\d+)'
  119. _TEST = {
  120. 'url': 'http://www.skysports.com/golf/news/12176/10871916/dustin-johnson-ready-to-conquer-players-championship-at-tpc-sawgrass',
  121. 'info_dict': {
  122. 'id': '10871916',
  123. 'title': 'Dustin Johnson ready to conquer Players Championship at TPC Sawgrass',
  124. 'description': 'Dustin Johnson is confident he can continue his dominant form in 2017 by adding the Players Championship to his list of victories.',
  125. },
  126. 'playlist_count': 2,
  127. }
  128. def _real_extract(self, url):
  129. article_id = self._match_id(url)
  130. webpage = self._download_webpage(url, article_id)
  131. entries = []
  132. for sdc_el in re.findall(self._SDC_EL_REGEX, webpage):
  133. entries.append(self._process_ooyala_element(webpage, sdc_el, url))
  134. return self.playlist_result(
  135. entries, article_id, self._og_search_title(webpage),
  136. self._html_search_meta(['og:description', 'description'], webpage))