motorsport.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from .common import InfoExtractor
  2. from ..compat import (
  3. compat_urlparse,
  4. )
  5. class MotorsportIE(InfoExtractor):
  6. IE_DESC = 'motorsport.com'
  7. _VALID_URL = r'https?://(?:www\.)?motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/?(?:$|[?#])'
  8. _TEST = {
  9. 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
  10. 'info_dict': {
  11. 'id': '2-T3WuR-KMM',
  12. 'ext': 'mp4',
  13. 'title': 'Red Bull Racing: 2014 Rules Explained',
  14. 'duration': 208,
  15. '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.',
  16. 'uploader': 'mcomstaff',
  17. 'uploader_id': 'UC334JIYKkVnyFoNCclfZtHQ',
  18. 'upload_date': '20140903',
  19. 'thumbnail': r're:^https?://.+\.jpg$'
  20. },
  21. 'add_ie': ['Youtube'],
  22. 'params': {
  23. 'skip_download': True,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. display_id = self._match_id(url)
  28. webpage = self._download_webpage(url, display_id)
  29. iframe_path = self._html_search_regex(
  30. r'<iframe id="player_iframe"[^>]+src="([^"]+)"', webpage, 'iframe path', default=None)
  31. if iframe_path is None:
  32. iframe_path = self._html_search_regex(
  33. r'<iframe [^>]*\bsrc="(https://motorsport\.tv/embed/[^"]+)', webpage, 'embed iframe path')
  34. return self.url_result(iframe_path)
  35. iframe = self._download_webpage(
  36. compat_urlparse.urljoin(url, iframe_path), display_id,
  37. 'Downloading iframe')
  38. youtube_id = self._search_regex(
  39. r'www.youtube.com/embed/(.{11})', iframe, 'youtube id')
  40. return {
  41. '_type': 'url_transparent',
  42. 'display_id': display_id,
  43. 'url': 'https://youtube.com/watch?v=%s' % youtube_id,
  44. }