2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
19 class SVTBaseIE(InfoExtractor
):
20 _GEO_COUNTRIES
= ['SE']
22 def _extract_video(self
, video_info
, video_id
):
23 is_live
= dict_get(video_info
, ('live', 'simulcast'), default
=False)
24 m3u8_protocol
= 'm3u8' if is_live
else 'm3u8_native'
26 for vr
in video_info
['videoReferences']:
27 player_type
= vr
.get('playerType') or vr
.get('format')
29 ext
= determine_ext(vurl
)
31 formats
.extend(self
._extract
_m
3u8_formats
(
33 ext
='mp4', entry_protocol
=m3u8_protocol
,
34 m3u8_id
=player_type
, fatal
=False))
36 formats
.extend(self
._extract
_f
4m
_formats
(
37 vurl
+ '?hdcore=3.3.0', video_id
,
38 f4m_id
=player_type
, fatal
=False))
40 if player_type
== 'dashhbbtv':
41 formats
.extend(self
._extract
_mpd
_formats
(
42 vurl
, video_id
, mpd_id
=player_type
, fatal
=False))
45 'format_id': player_type
,
48 rights
= try_get(video_info
, lambda x
: x
['rights'], dict) or {}
49 if not formats
and rights
.get('geoBlockedSweden'):
50 self
.raise_geo_restricted(
51 'This video is only available in Sweden',
52 countries
=self
._GEO
_COUNTRIES
, metadata_available
=True)
53 self
._sort
_formats
(formats
)
56 subtitle_references
= dict_get(video_info
, ('subtitles', 'subtitleReferences'))
57 if isinstance(subtitle_references
, list):
58 for sr
in subtitle_references
:
59 subtitle_url
= sr
.get('url')
60 subtitle_lang
= sr
.get('language', 'sv')
62 if determine_ext(subtitle_url
) == 'm3u8':
63 # TODO(yan12125): handle WebVTT in m3u8 manifests
66 subtitles
.setdefault(subtitle_lang
, []).append({'url': subtitle_url}
)
68 title
= video_info
.get('title')
70 series
= video_info
.get('programTitle')
71 season_number
= int_or_none(video_info
.get('season'))
72 episode
= video_info
.get('episodeTitle')
73 episode_number
= int_or_none(video_info
.get('episodeNumber'))
75 timestamp
= unified_timestamp(rights
.get('validFrom'))
76 duration
= int_or_none(dict_get(video_info
, ('materialLength', 'contentDuration')))
79 video_info
, ('inappropriateForChildren', 'blockedForChildren'),
80 skip_false_values
=False)
82 age_limit
= 18 if adult
else 0
88 'subtitles': subtitles
,
90 'timestamp': timestamp
,
91 'age_limit': age_limit
,
93 'season_number': season_number
,
95 'episode_number': episode_number
,
100 class SVTIE(SVTBaseIE
):
101 _VALID_URL
= r
'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
103 'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
104 'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
108 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
115 def _extract_url(webpage
):
117 r
'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE
._VALID
_URL
, webpage
)
119 return mobj
.group('url')
121 def _real_extract(self
, url
):
122 mobj
= self
._match
_valid
_url
(url
)
123 widget_id
= mobj
.group('widget_id')
124 article_id
= mobj
.group('id')
126 info
= self
._download
_json
(
127 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id
, article_id
),
130 info_dict
= self
._extract
_video
(info
['video'], article_id
)
131 info_dict
['title'] = info
['context']['title']
135 class SVTPlayBaseIE(SVTBaseIE
):
136 _SVTPLAY_RE
= r
'root\s*\[\s*(["\'])_
*svtplay\
1\s
*\
]\s
*=\s
*(?P
<json
>{.+?}
)\s
*;\s
*\n'
139 class SVTPlayIE(SVTPlayBaseIE):
140 IE_DESC = 'SVT Play
and Öppet arkiv
'
141 _VALID_URL = r'''(?x)
145 https?://(?:www\.)?svt\.se/barnkanalen/barnplay/[^/]+/
147 (?P<svt_id>[^/?#&]+)|
148 https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
149 (?:.*?(?:modalId|id)=(?P<modal_id>[\da-zA-Z-]+))?
153 'url
': 'https
://www
.svtplay
.se
/video
/30479064',
154 'md5
': '2382036fd6f8c994856c323fe51c426e
',
158 'title
': 'Designdrömmar i Stenungsund
',
159 'timestamp
': 1615770000,
160 'upload_date
': '20210315',
162 'thumbnail
': r're
:^https?
://(?
:.*[\
.-]jpg|www
.svtstatic
.se
/image
/.*)$
',
171 # skip for now due to download test asserts that segment is > 10000 bytes and svt uses
172 # init segments that are smaller
173 # AssertionError: Expected test_SVTPlay_jNwpV9P.mp4 to be at least 9.77KiB, but it's only
864.00B
174 'skip_download': True,
177 'url': 'https://www.svtplay.se/video/30479064/husdrommar/husdrommar-sasong-8-designdrommar-i-stenungsund?modalId=8zVbDPA',
178 'only_matching': True,
180 'url': 'https://www.svtplay.se/video/30684086/rapport/rapport-24-apr-18-00-7?id=e72gVpa',
181 'only_matching': True,
183 # geo restricted to Sweden
184 'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
185 'only_matching': True,
187 'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
188 'only_matching': True,
190 'url': 'https://www.svtplay.se/kanaler/svt1',
191 'only_matching': True,
193 'url': 'svt:1376446-003A',
194 'only_matching': True,
196 'url': 'svt:14278044',
197 'only_matching': True,
199 'url': 'https://www.svt.se/barnkanalen/barnplay/kar/eWv5MLX/',
200 'only_matching': True,
202 'url': 'svt:eWv5MLX',
203 'only_matching': True,
206 def _extract_by_video_id(self
, video_id
, webpage
=None):
207 data
= self
._download
_json
(
208 'https://api.svt.se/videoplayer-api/video/%s' % video_id
,
209 video_id
, headers
=self
.geo_verification_headers())
210 info_dict
= self
._extract
_video
(data
, video_id
)
211 if not info_dict
.get('title'):
212 title
= dict_get(info_dict
, ('episode', 'series'))
213 if not title
and webpage
:
215 r
'\s*\|\s*.+?$', '', self
._og
_search
_title
(webpage
))
218 info_dict
['title'] = title
221 def _real_extract(self
, url
):
222 mobj
= self
._match
_valid
_url
(url
)
223 video_id
= mobj
.group('id')
224 svt_id
= mobj
.group('svt_id') or mobj
.group('modal_id')
227 return self
._extract
_by
_video
_id
(svt_id
)
229 webpage
= self
._download
_webpage
(url
, video_id
)
231 data
= self
._parse
_json
(
233 self
._SVTPLAY
_RE
, webpage
, 'embedded data', default
='{}',
235 video_id
, fatal
=False)
237 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
240 video_info
= try_get(
241 data
, lambda x
: x
['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video'],
244 info_dict
= self
._extract
_video
(video_info
, video_id
)
246 'title': data
['context']['dispatcher']['stores']['MetaStore']['title'],
247 'thumbnail': thumbnail
,
252 data
, lambda x
: x
['statistics']['dataLake']['content']['id'],
256 svt_id
= self
._search
_regex
(
257 (r
'<video[^>]+data-video-id=["\']([\da
-zA
-Z
-]+)',
258 r'<[^
>]+\bdata
-rt
=["\']top-area-play-button["\'][^
>]+\bhref
=["\'][^"\']*video
/%s/[^
"\']*\b(?:modalId|id)=([\da-zA-Z-]+)' % re.escape(video_id),
259 r'["\']videoSvtId
["\']\s*:\s*["\']([\da
-zA
-Z
-]+)',
260 r'["\']videoSvtId\\?["\']\s
*:\s
*\\?
["\']([\da-zA-Z-]+)',
261 r'"content
"\s*:\s*{.*?"id"\s*:\s*"([\da
-zA
-Z
-]+)"',
262 r'["\']svtId
["\']\s*:\s*["\']([\da
-zA
-Z
-]+)',
263 r'["\']svtId\\?["\']\s
*:\s
*\\?
["\']([\da-zA-Z-]+)'),
266 info_dict = self._extract_by_video_id(svt_id, webpage)
267 info_dict['thumbnail'] = thumbnail
272 class SVTSeriesIE(SVTPlayBaseIE):
273 _VALID_URL = r'https?://(?:www\.)?svtplay\.se/(?P<id>[^/?&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
275 'url': 'https://www.svtplay.se/rederiet',
279 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
281 'playlist_mincount': 318,
283 'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
285 'id': 'season-2-14445680',
286 'title': 'Rederiet - Säsong 2',
287 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
289 'playlist_mincount': 12,
293 def suitable(cls, url):
294 return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTSeriesIE, cls).suitable(url)
296 def _real_extract(self, url):
297 series_slug, season_id = self._match_valid_url(url).groups()
299 series = self._download_json(
300 'https://api.svt.se/contento/graphql', series_slug,
301 'Downloading series page', query={
303 listablesBySlug(slugs: ["%s"]) {
304 associatedContent(include: [productionPeriod, season]) {
321 })['data']['listablesBySlug'][0]
326 for season in series['associatedContent']:
327 if not isinstance(season, dict):
330 if season.get('id') != season_id:
332 season_name = season.get('name')
333 items = season.get('items')
334 if not isinstance(items, list):
337 video = item.get('item') or {}
338 content_id = video.get('videoSvtId')
339 if not content_id or not isinstance(content_id, compat_str):
341 entries.append(self.url_result(
342 'svt:' + content_id, SVTPlayIE.ie_key(), content_id))
344 title = series.get('name')
345 season_name = season_name or season_id
347 if title and season_name:
348 title = '%s - %s' % (title, season_name)
352 return self.playlist_result(
353 entries, season_id or series.get('id'), title,
354 dict_get(series, ('longDescription', 'shortDescription')))
357 class SVTPageIE(InfoExtractor):
358 _VALID_URL = r'https?://(?:www\.)?svt\.se/(?P<path>(?:[^/]+/)*(?P<id>[^/?&#]+))'
360 'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
363 'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
367 'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
370 'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
375 'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
379 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
384 'url': 'https://www.svt.se/nyheter/lokalt/vast/svt-testar-tar-nagon-upp-skrapet-1',
385 'only_matching': True,
387 'url': 'https://www.svt.se/vader/manadskronikor/maj2018',
388 'only_matching': True,
392 def suitable(cls, url):
393 return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTPageIE, cls).suitable(url)
395 def _real_extract(self, url):
396 path, display_id = self._match_valid_url(url).groups()
398 article = self._download_json(
399 'https://api.svt.se/nss-api/page/' + path, display_id,
400 query={'q': 'articles'})['articles']['content'][0]
404 def _process_content(content):
405 if content.get('_type') in ('VIDEOCLIP', 'VIDEOEPISODE'):
406 video_id = compat_str(content['image']['svtId'])
407 entries.append(self.url_result(
408 'svt:' + video_id, SVTPlayIE.ie_key(), video_id))
410 for media in article.get('media', []):
411 _process_content(media)
413 for obj in article.get('structuredBody', []):
414 _process_content(obj.get('content') or {})
416 return self.playlist_result(
417 entries, str_or_none(article.get('id')),
418 strip_or_none(article.get('title')))