sky.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. extract_attributes,
  6. smuggle_url,
  7. strip_or_none,
  8. urljoin,
  9. )
  10. class SkyBaseIE(InfoExtractor):
  11. def _real_extract(self, url):
  12. video_id = self._match_id(url)
  13. webpage = self._download_webpage(url, video_id)
  14. video_data = extract_attributes(self._search_regex(
  15. r'(<div.+?class="[^"]*sdc-article-video__media-ooyala[^"]*"[^>]+>)',
  16. webpage, 'video data'))
  17. video_url = 'ooyala:%s' % video_data['data-video-id']
  18. if video_data.get('data-token-required') == 'true':
  19. token_fetch_options = self._parse_json(video_data.get(
  20. 'data-token-fetch-options', '{}'), video_id, fatal=False) or {}
  21. token_fetch_url = token_fetch_options.get('url')
  22. if token_fetch_url:
  23. embed_token = self._download_webpage(urljoin(
  24. url, token_fetch_url), video_id, fatal=False)
  25. if embed_token:
  26. video_url = smuggle_url(
  27. video_url, {'embed_token': embed_token.strip('"')})
  28. return {
  29. '_type': 'url_transparent',
  30. 'id': video_id,
  31. 'url': video_url,
  32. 'title': self._og_search_title(webpage),
  33. 'description': strip_or_none(self._og_search_description(webpage)),
  34. 'ie_key': 'Ooyala',
  35. }
  36. class SkySportsIE(SkyBaseIE):
  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': ['Ooyala'],
  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. _VALID_URL = r'https?://news\.sky\.com/video/[0-9a-z-]+-(?P<id>[0-9]+)'
  57. _TEST = {
  58. 'url': 'https://news.sky.com/video/russian-plane-inspected-after-deadly-fire-11712962',
  59. 'md5': 'd6327e581473cea9976a3236ded370cd',
  60. 'info_dict': {
  61. 'id': '1ua21xaDE6lCtZDmbYfl8kwsKLooJbNM',
  62. 'ext': 'mp4',
  63. 'title': 'Russian plane inspected after deadly fire',
  64. 'description': 'The Russian Investigative Committee has released video of the wreckage of a passenger plane which caught fire near Moscow.',
  65. },
  66. 'add_ie': ['Ooyala'],
  67. }