3 from .common
import InfoExtractor
4 from ..compat
import compat_str
16 class SVTBaseIE(InfoExtractor
):
17 _GEO_COUNTRIES
= ['SE']
19 def _extract_video(self
, video_info
, video_id
):
20 is_live
= dict_get(video_info
, ('live', 'simulcast'), default
=False)
21 m3u8_protocol
= 'm3u8' if is_live
else 'm3u8_native'
24 for vr
in video_info
['videoReferences']:
25 player_type
= vr
.get('playerType') or vr
.get('format')
27 ext
= determine_ext(vurl
)
29 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
31 ext
='mp4', entry_protocol
=m3u8_protocol
,
32 m3u8_id
=player_type
, fatal
=False)
34 self
._merge
_subtitles
(subs
, target
=subtitles
)
36 formats
.extend(self
._extract
_f
4m
_formats
(
37 vurl
+ '?hdcore=3.3.0', video_id
,
38 f4m_id
=player_type
, fatal
=False))
40 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
41 vurl
, video_id
, mpd_id
=player_type
, fatal
=False)
43 self
._merge
_subtitles
(subs
, target
=subtitles
)
46 'format_id': player_type
,
49 rights
= try_get(video_info
, lambda x
: x
['rights'], dict) or {}
50 if not formats
and rights
.get('geoBlockedSweden'):
51 self
.raise_geo_restricted(
52 'This video is only available in Sweden',
53 countries
=self
._GEO
_COUNTRIES
, metadata_available
=True)
55 subtitle_references
= dict_get(video_info
, ('subtitles', 'subtitleReferences'))
56 if isinstance(subtitle_references
, list):
57 for sr
in subtitle_references
:
58 subtitle_url
= sr
.get('url')
59 subtitle_lang
= sr
.get('language', 'sv')
64 if determine_ext(subtitle_url
) == 'm3u8':
65 # XXX: no way of testing, is it ever hit?
67 subtitles
.setdefault(subtitle_lang
, []).append(sub
)
69 title
= video_info
.get('title')
71 series
= video_info
.get('programTitle')
72 season_number
= int_or_none(video_info
.get('season'))
73 episode
= video_info
.get('episodeTitle')
74 episode_number
= int_or_none(video_info
.get('episodeNumber'))
76 timestamp
= unified_timestamp(rights
.get('validFrom'))
77 duration
= int_or_none(dict_get(video_info
, ('materialLength', 'contentDuration')))
80 video_info
, ('inappropriateForChildren', 'blockedForChildren'),
81 skip_false_values
=False)
83 age_limit
= 18 if adult
else 0
89 'subtitles': subtitles
,
91 'timestamp': timestamp
,
92 'age_limit': age_limit
,
94 'season_number': season_number
,
96 'episode_number': episode_number
,
101 class SVTIE(SVTBaseIE
):
102 _VALID_URL
= r
'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
103 _EMBED_REGEX
= [r
'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % _VALID_URL
]
105 'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
106 'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
110 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
116 def _real_extract(self
, url
):
117 mobj
= self
._match
_valid
_url
(url
)
118 widget_id
= mobj
.group('widget_id')
119 article_id
= mobj
.group('id')
121 info
= self
._download
_json
(
122 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id
, article_id
),
125 info_dict
= self
._extract
_video
(info
['video'], article_id
)
126 info_dict
['title'] = info
['context']['title']
130 class SVTPlayBaseIE(SVTBaseIE
):
131 _SVTPLAY_RE
= r
'root\s*\[\s*(["\'])_
*svtplay\
1\s
*\
]\s
*=\s
*(?P
<json
>{.+?}
)\s
*;\s
*\n'
134 class SVTPlayIE(SVTPlayBaseIE):
135 IE_DESC = 'SVT Play
and Öppet arkiv
'
136 _VALID_URL = r'''(?x)
140 https?://(?:www\.)?svt\.se/barnkanalen/barnplay/[^/]+/
142 (?P<svt_id>[^/?#&]+)|
143 https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
144 (?:.*?(?:modalId|id)=(?P<modal_id>[\da-zA-Z-]+))?
148 'url
': 'https
://www
.svtplay
.se
/video
/30479064',
149 'md5
': '2382036fd6f8c994856c323fe51c426e
',
153 'title
': 'Designdrömmar i Stenungsund
',
154 'timestamp
': 1615770000,
155 'upload_date
': '20210315',
157 'thumbnail
': r're
:^https?
://(?
:.*[\
.-]jpg|www
.svtstatic
.se
/image
/.*)$
',
166 # skip for now due to download test asserts that segment is > 10000 bytes and svt uses
167 # init segments that are smaller
168 # AssertionError: Expected test_SVTPlay_jNwpV9P.mp4 to be at least 9.77KiB, but it's only
864.00B
169 'skip_download': True,
172 'url': 'https://www.svtplay.se/video/30479064/husdrommar/husdrommar-sasong-8-designdrommar-i-stenungsund?modalId=8zVbDPA',
173 'only_matching': True,
175 'url': 'https://www.svtplay.se/video/30684086/rapport/rapport-24-apr-18-00-7?id=e72gVpa',
176 'only_matching': True,
178 # geo restricted to Sweden
179 'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
180 'only_matching': True,
182 'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
183 'only_matching': True,
185 'url': 'https://www.svtplay.se/kanaler/svt1',
186 'only_matching': True,
188 'url': 'svt:1376446-003A',
189 'only_matching': True,
191 'url': 'svt:14278044',
192 'only_matching': True,
194 'url': 'https://www.svt.se/barnkanalen/barnplay/kar/eWv5MLX/',
195 'only_matching': True,
197 'url': 'svt:eWv5MLX',
198 'only_matching': True,
201 def _extract_by_video_id(self
, video_id
, webpage
=None):
202 data
= self
._download
_json
(
203 'https://api.svt.se/videoplayer-api/video/%s' % video_id
,
204 video_id
, headers
=self
.geo_verification_headers())
205 info_dict
= self
._extract
_video
(data
, video_id
)
206 if not info_dict
.get('title'):
207 title
= dict_get(info_dict
, ('episode', 'series'))
208 if not title
and webpage
:
210 r
'\s*\|\s*.+?$', '', self
._og
_search
_title
(webpage
))
213 info_dict
['title'] = title
216 def _real_extract(self
, url
):
217 mobj
= self
._match
_valid
_url
(url
)
218 video_id
= mobj
.group('id')
219 svt_id
= mobj
.group('svt_id') or mobj
.group('modal_id')
222 return self
._extract
_by
_video
_id
(svt_id
)
224 webpage
= self
._download
_webpage
(url
, video_id
)
226 data
= self
._parse
_json
(
228 self
._SVTPLAY
_RE
, webpage
, 'embedded data', default
='{}',
230 video_id
, fatal
=False)
232 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
235 video_info
= try_get(
236 data
, lambda x
: x
['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video'],
239 info_dict
= self
._extract
_video
(video_info
, video_id
)
241 'title': data
['context']['dispatcher']['stores']['MetaStore']['title'],
242 'thumbnail': thumbnail
,
247 data
, lambda x
: x
['statistics']['dataLake']['content']['id'],
251 svt_id
= self
._search
_regex
(
252 (r
'<video[^>]+data-video-id=["\']([\da
-zA
-Z
-]+)',
253 r'<[^
>]+\bdata
-rt
=["\']top-area-play-button["\'][^
>]+\bhref
=["\'][^"\']*video
/%s/[^
"\']*\b(?:modalId|id)=([\da-zA-Z-]+)' % re.escape(video_id),
254 r'["\']videoSvtId
["\']\s*:\s*["\']([\da
-zA
-Z
-]+)',
255 r'["\']videoSvtId\\?["\']\s
*:\s
*\\?
["\']([\da-zA-Z-]+)',
256 r'"content
"\s*:\s*{.*?"id"\s*:\s*"([\da
-zA
-Z
-]+)"',
257 r'["\']svtId
["\']\s*:\s*["\']([\da
-zA
-Z
-]+)',
258 r'["\']svtId\\?["\']\s
*:\s
*\\?
["\']([\da-zA-Z-]+)'),
261 info_dict = self._extract_by_video_id(svt_id, webpage)
262 info_dict['thumbnail'] = thumbnail
267 class SVTSeriesIE(SVTPlayBaseIE):
268 _VALID_URL = r'https?://(?:www\.)?svtplay\.se/(?P<id>[^/?&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
270 'url': 'https://www.svtplay.se/rederiet',
274 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
276 'playlist_mincount': 318,
278 'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
280 'id': 'season-2-14445680',
281 'title': 'Rederiet - Säsong 2',
282 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
284 'playlist_mincount': 12,
288 def suitable(cls, url):
289 return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTSeriesIE, cls).suitable(url)
291 def _real_extract(self, url):
292 series_slug, season_id = self._match_valid_url(url).groups()
294 series = self._download_json(
295 'https://api.svt.se/contento/graphql', series_slug,
296 'Downloading series page', query={
298 listablesBySlug(slugs: ["%s"]) {
299 associatedContent(include: [productionPeriod, season]) {
316 })['data']['listablesBySlug'][0]
321 for season in series['associatedContent']:
322 if not isinstance(season, dict):
325 if season.get('id') != season_id:
327 season_name = season.get('name')
328 items = season.get('items')
329 if not isinstance(items, list):
332 video = item.get('item') or {}
333 content_id = video.get('videoSvtId')
334 if not content_id or not isinstance(content_id, compat_str):
336 entries.append(self.url_result(
337 'svt:' + content_id, SVTPlayIE.ie_key(), content_id))
339 title = series.get('name')
340 season_name = season_name or season_id
342 if title and season_name:
343 title = '%s - %s' % (title, season_name)
347 return self.playlist_result(
348 entries, season_id or series.get('id'), title,
349 dict_get(series, ('longDescription', 'shortDescription')))
352 class SVTPageIE(InfoExtractor):
353 _VALID_URL = r'https?://(?:www\.)?svt\.se/(?P<path>(?:[^/]+/)*(?P<id>[^/?&#]+))'
355 'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
358 'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
362 'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
365 'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
370 'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
374 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
379 'url': 'https://www.svt.se/nyheter/lokalt/vast/svt-testar-tar-nagon-upp-skrapet-1',
380 'only_matching': True,
382 'url': 'https://www.svt.se/vader/manadskronikor/maj2018',
383 'only_matching': True,
387 def suitable(cls, url):
388 return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTPageIE, cls).suitable(url)
390 def _real_extract(self, url):
391 path, display_id = self._match_valid_url(url).groups()
393 article = self._download_json(
394 'https://api.svt.se/nss-api/page/' + path, display_id,
395 query={'q': 'articles'})['articles']['content'][0]
399 def _process_content(content):
400 if content.get('_type') in ('VIDEOCLIP', 'VIDEOEPISODE'):
401 video_id = compat_str(content['image']['svtId'])
402 entries.append(self.url_result(
403 'svt:' + video_id, SVTPlayIE.ie_key(), video_id))
405 for media in article.get('media', []):
406 _process_content(media)
408 for obj in article.get('structuredBody', []):
409 _process_content(obj.get('content') or {})
411 return self.playlist_result(
412 entries, str_or_none(article.get('id')),
413 strip_or_none(article.get('title')))