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