]>
Commit | Line | Data |
---|---|---|
28f12728 | 1 | # coding: utf-8 |
1309b396 PH |
2 | from __future__ import unicode_literals |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | determine_ext, | |
7 | ) | |
8 | ||
9 | ||
10 | class SVTPlayIE(InfoExtractor): | |
11 | _VALID_URL = r'https?://(?:www\.)?svtplay\.se/video/(?P<id>[0-9]+)' | |
12 | _TEST = { | |
13 | 'url': 'http://www.svtplay.se/video/2609989/sm-veckan/sm-veckan-rally-final-sasong-1-sm-veckan-rally-final', | |
28f12728 | 14 | 'md5': 'f4a184968bc9c802a9b41316657aaa80', |
1309b396 | 15 | 'info_dict': { |
28f12728 | 16 | 'id': '2609989', |
1309b396 | 17 | 'ext': 'mp4', |
28f12728 | 18 | 'title': 'SM veckan vinter, Örebro - Rally, final', |
1309b396 | 19 | 'duration': 4500, |
28f12728 | 20 | 'thumbnail': 're:^https?://.*[\.-]jpg$', |
1309b396 PH |
21 | }, |
22 | } | |
23 | ||
24 | def _real_extract(self, url): | |
25 | video_id = self._match_id(url) | |
26 | info = self._download_json( | |
27 | 'http://www.svtplay.se/video/%s?output=json' % video_id, video_id) | |
28 | ||
29 | title = info['context']['title'] | |
30 | thumbnail = info['context'].get('thumbnailImage') | |
31 | ||
32 | video_info = info['video'] | |
33 | formats = [] | |
34 | for vr in video_info['videoReferences']: | |
35 | vurl = vr['url'] | |
36 | if determine_ext(vurl) == 'm3u8': | |
37 | formats.extend(self._extract_m3u8_formats( | |
38 | vurl, video_id, | |
39 | ext='mp4', entry_protocol='m3u8_native', | |
40 | m3u8_id=vr.get('playerType'))) | |
41 | else: | |
42 | formats.append({ | |
43 | 'format_id': vr.get('playerType'), | |
44 | 'url': vurl, | |
45 | }) | |
46 | self._sort_formats(formats) | |
47 | ||
48 | duration = video_info.get('materialLength') | |
49 | ||
50 | return { | |
51 | 'id': video_id, | |
52 | 'title': title, | |
53 | 'formats': formats, | |
54 | 'thumbnail': thumbnail, | |
55 | 'duration': duration, | |
56 | } |