2 from __future__ import unicode_literals
6 from .common import InfoExtractor
12 class SVTBaseIE(InfoExtractor):
13 def _extract_video(self, url, video_id):
14 info = self._download_json(url, video_id)
16 title = info['context']['title']
17 thumbnail = info['context'].get('thumbnailImage')
19 video_info = info['video']
21 for vr in video_info['videoReferences']:
22 player_type = vr.get('playerType')
24 ext = determine_ext(vurl)
26 formats.extend(self._extract_m3u8_formats(
28 ext='mp4', entry_protocol='m3u8_native',
29 m3u8_id=player_type, fatal=False))
31 formats.extend(self._extract_f4m_formats(
32 vurl + '?hdcore=3.3.0', video_id,
33 f4m_id=player_type, fatal=False))
35 if player_type == 'dashhbbtv':
36 formats.extend(self._extract_mpd_formats(
37 vurl, video_id, mpd_id=player_type, fatal=False))
40 'format_id': player_type,
43 self._sort_formats(formats)
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')
51 subtitles.setdefault('sv', []).append({'url': subtitle_url})
53 duration = video_info.get('materialLength')
54 age_limit = 18 if video_info.get('inappropriateForChildren') else 0
60 'subtitles': subtitles,
61 'thumbnail': thumbnail,
63 'age_limit': age_limit,
67 class SVTIE(SVTBaseIE):
68 _VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
70 'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
71 'md5': '9648197555fc1b49e3dc22db4af51d46',
75 'title': 'Här trycker Jagr till Giroux (under SVT-intervjun)',
82 def _extract_url(webpage):
84 r'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE._VALID_URL, webpage)
86 return mobj.group('url')
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),
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]+)'
101 'url': 'http://www.svtplay.se/video/5996901/flygplan-till-haile-selassie/flygplan-till-haile-selassie-2',
102 'md5': '2b6704fe4a28801e1a098bbf3c5ac611',
106 'title': 'Flygplan till Haile Selassie',
108 'thumbnail': 're:^https?://.*[\.-]jpg$',
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),