motorsport.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. class MotorsportIE(InfoExtractor):
  4. _WORKING = False
  5. IE_DESC = 'motorsport.com'
  6. _VALID_URL = r'https?://(?:www\.)?motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/?(?:$|[?#])'
  7. _TEST = {
  8. 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
  9. 'info_dict': {
  10. 'id': '2-T3WuR-KMM',
  11. 'ext': 'mp4',
  12. 'title': 'Red Bull Racing: 2014 Rules Explained',
  13. 'duration': 208,
  14. 'description': 'A new clip from Red Bull sees Daniel Ricciardo and Sebastian Vettel explain the 2014 Formula One regulations – which are arguably the most complex the sport has ever seen.',
  15. 'uploader': 'mcomstaff',
  16. 'uploader_id': 'UC334JIYKkVnyFoNCclfZtHQ',
  17. 'upload_date': '20140903',
  18. 'thumbnail': r're:^https?://.+\.jpg$',
  19. },
  20. 'add_ie': ['Youtube'],
  21. 'params': {
  22. 'skip_download': True,
  23. },
  24. }
  25. def _real_extract(self, url):
  26. display_id = self._match_id(url)
  27. webpage = self._download_webpage(url, display_id)
  28. iframe_path = self._html_search_regex(
  29. r'<iframe id="player_iframe"[^>]+src="([^"]+)"', webpage, 'iframe path', default=None)
  30. if iframe_path is None:
  31. iframe_path = self._html_search_regex(
  32. r'<iframe [^>]*\bsrc="(https://motorsport\.tv/embed/[^"]+)', webpage, 'embed iframe path')
  33. return self.url_result(iframe_path)
  34. iframe = self._download_webpage(
  35. urllib.parse.urljoin(url, iframe_path), display_id,
  36. 'Downloading iframe')
  37. youtube_id = self._search_regex(
  38. r'www.youtube.com/embed/(.{11})', iframe, 'youtube id')
  39. return {
  40. '_type': 'url_transparent',
  41. 'display_id': display_id,
  42. 'url': f'https://youtube.com/watch?v={youtube_id}',
  43. }