]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/motorsport.py
debian/changelog: Annotate bugs being closed.
[youtubedl] / youtube_dl / extractor / motorsport.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import hashlib
5 import json
6 import re
7 import time
8
9 from .common import InfoExtractor
10 from ..utils import (
11 compat_parse_qs,
12 compat_str,
13 int_or_none,
14 )
15
16
17 class MotorsportIE(InfoExtractor):
18 IE_DESC = 'motorsport.com'
19 _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])'
20 _TEST = {
21 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
22 'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
23 'info_dict': {
24 'id': '7063',
25 'ext': 'mp4',
26 'title': 'Red Bull Racing: 2014 Rules Explained',
27 'duration': 207,
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$'
31 }
32 }
33
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
36 display_id = mobj.group('id')
37
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])
43
44 e = compat_str(int(time.time()) + 24 * 60 * 60)
45 base_video_url = params['location'] + '?e=' + e
46 s = 'h3hg713fh32'
47 h = hashlib.md5((s + base_video_url).encode('utf-8')).hexdigest()
48 video_url = base_video_url + '&h=' + h
49
50 uploader = self._html_search_regex(
51 r'(?s)<span class="label">Video by: </span>(.*?)</a>', webpage,
52 'uploader', fatal=False)
53
54 return {
55 'id': params['video_id'],
56 'display_id': display_id,
57 'title': params['title'],
58 'url': video_url,
59 'description': params.get('description'),
60 'thumbnail': params.get('main_thumb'),
61 'duration': int_or_none(params.get('duration')),
62 'uploader': uploader,
63 }