You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import hashlib
  4. import json
  5. import re
  6. import time
  7. from .common import InfoExtractor
  8. from ..utils import (
  9. compat_parse_qs,
  10. compat_str,
  11. int_or_none,
  12. )
  13. class MotorsportIE(InfoExtractor):
  14. IE_DESC = 'motorsport.com'
  15. _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])'
  16. _TEST = {
  17. 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
  18. 'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
  19. 'info_dict': {
  20. 'id': '7063',
  21. 'ext': 'mp4',
  22. 'title': 'Red Bull Racing: 2014 Rules Explained',
  23. 'duration': 207,
  24. '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.',
  25. 'uploader': 'rainiere',
  26. 'thumbnail': r're:^http://.*motorsport\.com/.+\.jpg$'
  27. }
  28. }
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. display_id = mobj.group('id')
  32. webpage = self._download_webpage(url, display_id)
  33. flashvars_code = self._html_search_regex(
  34. r'<embed id="player".*?flashvars="([^"]+)"', webpage, 'flashvars')
  35. flashvars = compat_parse_qs(flashvars_code)
  36. params = json.loads(flashvars['parameters'][0])
  37. e = compat_str(int(time.time()) + 24 * 60 * 60)
  38. base_video_url = params['location'] + '?e=' + e
  39. s = 'h3hg713fh32'
  40. h = hashlib.md5((s + base_video_url).encode('utf-8')).hexdigest()
  41. video_url = base_video_url + '&h=' + h
  42. uploader = self._html_search_regex(
  43. r'(?s)<span class="label">Video by: </span>(.*?)</a>', webpage,
  44. 'uploader', fatal=False)
  45. return {
  46. 'id': params['video_id'],
  47. 'display_id': display_id,
  48. 'title': params['title'],
  49. 'url': video_url,
  50. 'description': params.get('description'),
  51. 'thumbnail': params.get('main_thumb'),
  52. 'duration': int_or_none(params.get('duration')),
  53. 'uploader': uploader,
  54. }