ceskatelevize: Closed captions support
[youtube-dl] / youtube_dl / extractor / motorsport.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import hashlib
5 import json
6 import time
7
8 from .common import InfoExtractor
9 from ..compat import (
10     compat_parse_qs,
11     compat_str,
12 )
13 from ..utils import (
14     int_or_none,
15 )
16
17
18 class MotorsportIE(InfoExtractor):
19     IE_DESC = 'motorsport.com'
20     _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])'
21     _TEST = {
22         'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
23         'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
24         'info_dict': {
25             'id': '7063',
26             'ext': 'mp4',
27             'title': 'Red Bull Racing: 2014 Rules Explained',
28             'duration': 207,
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$'
32         }
33     }
34
35     def _real_extract(self, url):
36         display_id = self._match_id(url)
37         webpage = self._download_webpage(url, display_id)
38
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         }