2 from __future__ import unicode_literals
8 from .common import InfoExtractor
18 class MotorsportIE(InfoExtractor):
19 IE_DESC = 'motorsport.com'
20 _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])'
22 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
23 'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
27 'title': 'Red Bull Racing: 2014 Rules Explained',
29 '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.',
30 'uploader': 'rainiere',
31 'thumbnail': r're:^http://.*motorsport\.com/.+\.jpg$'
35 def _real_extract(self, url):
36 display_id = self._match_id(url)
37 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')),