sky.py 5.3 KB

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