2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class SVTBaseIE(InfoExtractor):
14 def _extract_video(self, info, video_id):
15 video_info = self._get_video_info(info)
18 for vr in video_info['videoReferences']:
19 player_type = vr.get('playerType')
21 ext = determine_ext(vurl)
23 formats.extend(self._extract_m3u8_formats(
25 ext='mp4', entry_protocol='m3u8_native',
26 m3u8_id=player_type, fatal=False))
28 formats.extend(self._extract_f4m_formats(
29 vurl + '?hdcore=3.3.0', video_id,
30 f4m_id=player_type, fatal=False))
32 if player_type == 'dashhbbtv':
33 formats.extend(self._extract_mpd_formats(
34 vurl, video_id, mpd_id=player_type, fatal=False))
37 'format_id': player_type,
40 self._sort_formats(formats)
43 subtitle_references = dict_get(video_info, ('subtitles', 'subtitleReferences'))
44 if isinstance(subtitle_references, list):
45 for sr in subtitle_references:
46 subtitle_url = sr.get('url')
47 subtitle_lang = sr.get('language', 'sv')
49 if determine_ext(subtitle_url) == 'm3u8':
50 # TODO(yan12125): handle WebVTT in m3u8 manifests
53 subtitles.setdefault(subtitle_lang, []).append({'url': subtitle_url})
55 duration = video_info.get('materialLength')
56 age_limit = 18 if video_info.get('inappropriateForChildren') else 0
61 'subtitles': subtitles,
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': '33e9a5d8f646523ce0868ecfb0eed77d',
75 'title': 'Stjärnorna skojar till det - 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 _get_video_info(self, info):
91 def _real_extract(self, url):
92 mobj = re.match(self._VALID_URL, url)
93 widget_id = mobj.group('widget_id')
94 article_id = mobj.group('id')
96 info = self._download_json(
97 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id),
100 info_dict = self._extract_video(info, article_id)
101 info_dict['title'] = info['context']['title']
105 class SVTPlayIE(SVTBaseIE):
106 IE_DESC = 'SVT Play and Öppet arkiv'
107 _VALID_URL = r'https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)'
109 'url': 'http://www.svtplay.se/video/5996901/flygplan-till-haile-selassie/flygplan-till-haile-selassie-2',
110 'md5': '2b6704fe4a28801e1a098bbf3c5ac611',
114 'title': 'Flygplan till Haile Selassie',
116 'thumbnail': 're:^https?://.*[\.-]jpg$',
126 def _get_video_info(self, info):
127 return info['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video']
129 def _real_extract(self, url):
130 video_id = self._match_id(url)
132 webpage = self._download_webpage(url, video_id)
134 data = self._parse_json(self._search_regex(
135 r'root\["__svtplay"\]\s*=\s*([^;]+);', webpage, 'embedded data'), video_id)
137 thumbnail = self._og_search_thumbnail(webpage)
139 info_dict = self._extract_video(data, video_id)
141 'title': data['context']['dispatcher']['stores']['MetaStore']['title'],
142 'thumbnail': thumbnail,