2 from __future__ import unicode_literals
9 from .common import InfoExtractor
17 class MotorsportIE(InfoExtractor):
18 IE_DESC = 'motorsport.com'
19 _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])'
21 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
22 'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
26 'title': 'Red Bull Racing: 2014 Rules Explained',
28 '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.',
29 'uploader': 'rainiere',
30 'thumbnail': r're:^http://.*motorsport\.com/.+\.jpg$'
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
36 display_id = mobj.group('id')
38 webpage = self._download_webpage(url, display_id)
39 flashvars_code = self._html_search_regex(
40 r'<embed id="player".*?flashvars="([^"]+)"', webpage, 'flashvars')
41 flashvars = compat_parse_qs(flashvars_code)
42 params = json.loads(flashvars['parameters'][0])
44 e = compat_str(int(time.time()) + 24 * 60 * 60)
45 base_video_url = params['location'] + '?e=' + e
47 h = hashlib.md5((s + base_video_url).encode('utf-8')).hexdigest()
48 video_url = base_video_url + '&h=' + h
50 uploader = self._html_search_regex(
51 r'(?s)<span class="label">Video by: </span>(.*?)</a>', webpage,
52 'uploader', fatal=False)
55 'id': params['video_id'],
56 'display_id': display_id,
57 'title': params['title'],
59 'description': params.get('description'),
60 'thumbnail': params.get('main_thumb'),
61 'duration': int_or_none(params.get('duration')),