logo

youtube-dl

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

motorsport.py (1804B)


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