logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

sky.py (5418B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. extract_attributes,
  7. smuggle_url,
  8. strip_or_none,
  9. urljoin,
  10. )
  11. class SkyBaseIE(InfoExtractor):
  12. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
  13. _SDC_EL_REGEX = r'(?s)(<div[^>]+data-(?:component-name|fn)="sdc-(?:articl|sit)e-video"[^>]*>)'
  14. def _process_ooyala_element(self, webpage, sdc_el, url):
  15. sdc = extract_attributes(sdc_el)
  16. provider = sdc.get('data-provider')
  17. if provider == 'ooyala':
  18. video_id = sdc['data-sdc-video-id']
  19. video_url = 'ooyala:%s' % video_id
  20. ie_key = 'Ooyala'
  21. ooyala_el = self._search_regex(
  22. r'(<div[^>]+class="[^"]*\bsdc-article-video__media-ooyala\b[^"]*"[^>]+data-video-id="%s"[^>]*>)' % video_id,
  23. webpage, 'video data', fatal=False)
  24. if ooyala_el:
  25. ooyala_attrs = extract_attributes(ooyala_el) or {}
  26. if ooyala_attrs.get('data-token-required') == 'true':
  27. token_fetch_url = (self._parse_json(ooyala_attrs.get(
  28. 'data-token-fetch-options', '{}'),
  29. video_id, fatal=False) or {}).get('url')
  30. if token_fetch_url:
  31. embed_token = self._download_json(urljoin(
  32. url, token_fetch_url), video_id, fatal=False)
  33. if embed_token:
  34. video_url = smuggle_url(
  35. video_url, {'embed_token': embed_token})
  36. elif provider == 'brightcove':
  37. video_id = sdc['data-video-id']
  38. account_id = sdc.get('data-account-id') or '6058004172001'
  39. player_id = sdc.get('data-player-id') or 'RC9PQUaJ6'
  40. video_url = self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id)
  41. ie_key = 'BrightcoveNew'
  42. return {
  43. '_type': 'url_transparent',
  44. 'id': video_id,
  45. 'url': video_url,
  46. 'ie_key': ie_key,
  47. }
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. webpage = self._download_webpage(url, video_id)
  51. info = self._process_ooyala_element(webpage, self._search_regex(
  52. self._SDC_EL_REGEX, webpage, 'sdc element'), url)
  53. info.update({
  54. 'title': self._og_search_title(webpage),
  55. 'description': strip_or_none(self._og_search_description(webpage)),
  56. })
  57. return info
  58. class SkySportsIE(SkyBaseIE):
  59. IE_NAME = 'sky:sports'
  60. _VALID_URL = r'https?://(?:www\.)?skysports\.com/watch/video/([^/]+/)*(?P<id>[0-9]+)'
  61. _TESTS = [{
  62. 'url': 'http://www.skysports.com/watch/video/10328419/bale-its-our-time-to-shine',
  63. 'md5': '77d59166cddc8d3cb7b13e35eaf0f5ec',
  64. 'info_dict': {
  65. 'id': 'o3eWJnNDE6l7kfNO8BOoBlRxXRQ4ANNQ',
  66. 'ext': 'mp4',
  67. 'title': 'Bale: It\'s our time to shine',
  68. 'description': 'md5:e88bda94ae15f7720c5cb467e777bb6d',
  69. },
  70. 'add_ie': ['Ooyala'],
  71. }, {
  72. 'url': 'https://www.skysports.com/watch/video/sports/f1/12160544/abu-dhabi-gp-the-notebook',
  73. 'only_matching': True,
  74. }, {
  75. 'url': 'https://www.skysports.com/watch/video/tv-shows/12118508/rainford-brent-how-ace-programme-helps',
  76. 'only_matching': True,
  77. }]
  78. class SkyNewsIE(SkyBaseIE):
  79. IE_NAME = 'sky:news'
  80. _VALID_URL = r'https?://news\.sky\.com/video/[0-9a-z-]+-(?P<id>[0-9]+)'
  81. _TEST = {
  82. 'url': 'https://news.sky.com/video/russian-plane-inspected-after-deadly-fire-11712962',
  83. 'md5': '411e8893fd216c75eaf7e4c65d364115',
  84. 'info_dict': {
  85. 'id': 'ref:1ua21xaDE6lCtZDmbYfl8kwsKLooJbNM',
  86. 'ext': 'mp4',
  87. 'title': 'Russian plane inspected after deadly fire',
  88. 'description': 'The Russian Investigative Committee has released video of the wreckage of a passenger plane which caught fire near Moscow.',
  89. 'uploader_id': '6058004172001',
  90. 'timestamp': 1567112345,
  91. 'upload_date': '20190829',
  92. },
  93. 'add_ie': ['BrightcoveNew'],
  94. }
  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_ooyala_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))