]>
Commit | Line | Data |
---|---|---|
28f12728 | 1 | # coding: utf-8 |
1309b396 PH |
2 | from __future__ import unicode_literals |
3 | ||
df5ae3eb S |
4 | import re |
5 | ||
1309b396 PH |
6 | from .common import InfoExtractor |
7 | from ..utils import ( | |
8 | determine_ext, | |
9 | ) | |
10 | ||
11 | ||
79998cd5 S |
12 | class SVTBaseIE(InfoExtractor): |
13 | def _extract_video(self, url, video_id): | |
14 | info = self._download_json(url, video_id) | |
1309b396 PH |
15 | |
16 | title = info['context']['title'] | |
17 | thumbnail = info['context'].get('thumbnailImage') | |
18 | ||
19 | video_info = info['video'] | |
20 | formats = [] | |
21 | for vr in video_info['videoReferences']: | |
22 | vurl = vr['url'] | |
df5ae3eb S |
23 | ext = determine_ext(vurl) |
24 | if ext == 'm3u8': | |
1309b396 PH |
25 | formats.extend(self._extract_m3u8_formats( |
26 | vurl, video_id, | |
27 | ext='mp4', entry_protocol='m3u8_native', | |
28 | m3u8_id=vr.get('playerType'))) | |
df5ae3eb S |
29 | elif ext == 'f4m': |
30 | formats.extend(self._extract_f4m_formats( | |
31 | vurl + '?hdcore=3.3.0', video_id, | |
32 | f4m_id=vr.get('playerType'))) | |
1309b396 PH |
33 | else: |
34 | formats.append({ | |
35 | 'format_id': vr.get('playerType'), | |
36 | 'url': vurl, | |
37 | }) | |
38 | self._sort_formats(formats) | |
39 | ||
1f16b958 | 40 | subtitles = {} |
594c4d79 S |
41 | subtitle_references = video_info.get('subtitleReferences') |
42 | if isinstance(subtitle_references, list): | |
43 | for sr in subtitle_references: | |
44 | subtitle_url = sr.get('url') | |
45 | if subtitle_url: | |
46 | subtitles.setdefault('sv', []).append({'url': subtitle_url}) | |
1f16b958 | 47 | |
1309b396 | 48 | duration = video_info.get('materialLength') |
df5ae3eb | 49 | age_limit = 18 if video_info.get('inappropriateForChildren') else 0 |
1309b396 PH |
50 | |
51 | return { | |
52 | 'id': video_id, | |
53 | 'title': title, | |
54 | 'formats': formats, | |
1f16b958 | 55 | 'subtitles': subtitles, |
1309b396 PH |
56 | 'thumbnail': thumbnail, |
57 | 'duration': duration, | |
df5ae3eb | 58 | 'age_limit': age_limit, |
1309b396 | 59 | } |
79998cd5 S |
60 | |
61 | ||
62 | class SVTIE(SVTBaseIE): | |
63 | _VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)' | |
64 | _TEST = { | |
65 | 'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false', | |
66 | 'md5': '9648197555fc1b49e3dc22db4af51d46', | |
67 | 'info_dict': { | |
68 | 'id': '2900353', | |
69 | 'ext': 'flv', | |
70 | 'title': 'Här trycker Jagr till Giroux (under SVT-intervjun)', | |
71 | 'duration': 27, | |
72 | 'age_limit': 0, | |
73 | }, | |
74 | } | |
75 | ||
bab19a8e S |
76 | @staticmethod |
77 | def _extract_url(webpage): | |
78 | mobj = re.search( | |
79 | r'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE._VALID_URL, webpage) | |
80 | if mobj: | |
81 | return mobj.group('url') | |
82 | ||
79998cd5 S |
83 | def _real_extract(self, url): |
84 | mobj = re.match(self._VALID_URL, url) | |
85 | widget_id = mobj.group('widget_id') | |
86 | article_id = mobj.group('id') | |
87 | return self._extract_video( | |
88 | 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id), | |
89 | article_id) | |
90 | ||
91 | ||
92 | class SVTPlayIE(SVTBaseIE): | |
93 | IE_DESC = 'SVT Play and Öppet arkiv' | |
94 | _VALID_URL = r'https?://(?:www\.)?(?P<host>svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)' | |
594c4d79 S |
95 | _TEST = { |
96 | 'url': 'http://www.svtplay.se/video/5996901/flygplan-till-haile-selassie/flygplan-till-haile-selassie-2', | |
97 | 'md5': '2b6704fe4a28801e1a098bbf3c5ac611', | |
79998cd5 | 98 | 'info_dict': { |
594c4d79 S |
99 | 'id': '5996901', |
100 | 'ext': 'mp4', | |
101 | 'title': 'Flygplan till Haile Selassie', | |
102 | 'duration': 3527, | |
79998cd5 S |
103 | 'thumbnail': 're:^https?://.*[\.-]jpg$', |
104 | 'age_limit': 0, | |
594c4d79 S |
105 | 'subtitles': { |
106 | 'sv': [{ | |
107 | 'ext': 'wsrt', | |
108 | }] | |
109 | }, | |
79998cd5 | 110 | }, |
594c4d79 | 111 | } |
79998cd5 S |
112 | |
113 | def _real_extract(self, url): | |
114 | mobj = re.match(self._VALID_URL, url) | |
115 | video_id = mobj.group('id') | |
116 | host = mobj.group('host') | |
117 | return self._extract_video( | |
118 | 'http://www.%s.se/video/%s?output=json' % (host, video_id), | |
119 | video_id) |