4 from .common
import InfoExtractor
5 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_download
': 'm3u8
',
168 'skip
': 'Episode
is no longer available
',
170 'url
': 'https
://www
.svtplay
.se
/video
/emBxBQj
',
171 'md5
': '2382036fd6f8c994856c323fe51c426e
',
175 'title
': '1. Farlig kryssning
',
176 'timestamp
': 1491019200,
177 'upload_date
': '20170401',
179 'thumbnail
': r're
:^https?
://(?
:.*[\
.-]jpg|www
.svtstatic
.se
/image
/.*)$
',
181 'episode
': '1. Farlig kryssning
',
182 'series
': 'Rederiet
',
188 'skip_download
': 'm3u8
',
191 'url
': 'https
://www
.svtplay
.se
/video
/jz2rYz7
/anders
-hansen
-moter
/james
-fallon?info
=visa
',
195 'title
': 'James Fallon
',
196 'timestamp
': 1673917200,
197 'upload_date
': '20230117',
199 'thumbnail
': r're
:^https?
://(?
:.*[\
.-]jpg|www
.svtstatic
.se
/image
/.*)$
',
201 'episode
': 'James Fallon
',
202 'series
': 'Anders Hansen möter
...',
205 'skip_download
': 'dash
',
208 'url
': 'https
://www
.svtplay
.se
/video
/30479064/husdrommar
/husdrommar
-sasong
-8-designdrommar
-i
-stenungsund?modalId
=8zVbDPA
',
209 'only_matching
': True,
211 'url
': 'https
://www
.svtplay
.se
/video
/30684086/rapport
/rapport
-24-apr
-18-00-7?
id=e72gVpa
',
212 'only_matching
': True,
214 # geo restricted to Sweden
215 'url
': 'http
://www
.oppetarkiv
.se
/video
/5219710/trollflojten
',
216 'only_matching
': True,
218 'url
': 'http
://www
.svtplay
.se
/klipp
/9023742/stopptid
-om
-bjorn
-borg
',
219 'only_matching
': True,
221 'url
': 'https
://www
.svtplay
.se
/kanaler
/svt1
',
222 'only_matching
': True,
224 'url
': 'svt
:1376446-003A
',
225 'only_matching
': True,
227 'url
': 'svt
:14278044',
228 'only_matching
': True,
230 'url
': 'https
://www
.svt
.se
/barnkanalen
/barnplay
/kar
/eWv5MLX
/',
231 'only_matching
': True,
233 'url
': 'svt
:eWv5MLX
',
234 'only_matching
': True,
237 def _extract_by_video_id(self, video_id, webpage=None):
238 data = self._download_json(
239 'https
://api
.svt
.se
/videoplayer
-api
/video
/%s' % video_id,
240 video_id, headers=self.geo_verification_headers())
241 info_dict = self._extract_video(data, video_id)
242 if not info_dict.get('title
'):
243 title = dict_get(info_dict, ('episode
', 'series
'))
244 if not title and webpage:
246 r'\s
*\|\s
*.+?$
', '', self._og_search_title(webpage))
249 info_dict['title
'] = title
252 def _real_extract(self, url):
253 mobj = self._match_valid_url(url)
254 video_id = mobj.group('id')
255 svt_id = mobj.group('svt_id
') or mobj.group('modal_id
')
258 return self._extract_by_video_id(svt_id)
260 webpage = self._download_webpage(url, video_id)
262 data = self._parse_json(
264 self._SVTPLAY_RE, webpage, 'embedded data
', default='{}',
266 video_id, fatal=False)
268 thumbnail = self._og_search_thumbnail(webpage)
271 video_info = try_get(
272 data, lambda x: x['context
']['dispatcher
']['stores
']['VideoTitlePageStore
']['data
']['video
'],
275 info_dict = self._extract_video(video_info, video_id)
277 'title
': data['context
']['dispatcher
']['stores
']['MetaStore
']['title
'],
278 'thumbnail
': thumbnail,
283 data, lambda x: x['statistics
']['dataLake
']['content
']['id'],
287 nextjs_data = self._search_nextjs_data(webpage, video_id, fatal=False)
288 svt_id = traverse_obj(nextjs_data, (
289 'props
', 'urqlState
', ..., 'data
', {json.loads}, 'detailsPageByPath
',
290 'video
', 'svtId
', {str}), get_all=False)
293 svt_id = self._search_regex(
294 (r'<video
[^
>]+data
-video
-id=["\']([\da-zA-Z-]+)',
295 r'<[^>]+\bdata-rt=["\']top
-area
-play
-button
["\'][^>]+\bhref=["\'][^
"\']*video/[\w-]+/[^"\']*\b(?
:modalId|
id)=([\w
-]+)'),
298 info_dict = self._extract_by_video_id(svt_id, webpage)
299 info_dict['thumbnail
'] = thumbnail
304 class SVTSeriesIE(SVTPlayBaseIE):
305 _VALID_URL = r'https?
://(?
:www\
.)?svtplay\
.se
/(?P
<id>[^
/?
&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
307 'url': 'https://www.svtplay.se/rederiet',
311 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
313 'playlist_mincount': 318,
315 'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
317 'id': 'season-2-14445680',
318 'title': 'Rederiet - Säsong 2',
319 'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
321 'playlist_mincount': 12,
325 def suitable(cls
, url
):
326 return False if SVTIE
.suitable(url
) or SVTPlayIE
.suitable(url
) else super(SVTSeriesIE
, cls
).suitable(url
)
328 def _real_extract(self
, url
):
329 series_slug
, season_id
= self
._match
_valid
_url
(url
).groups()
331 series
= self
._download
_json
(
332 'https://api.svt.se/contento/graphql', series_slug
,
333 'Downloading series page', query
={
335 listablesBySlug(slugs: ["%s"]) {
336 associatedContent(include: [productionPeriod, season]) {
353 })['data']['listablesBySlug'][0]
358 for season
in series
['associatedContent']:
359 if not isinstance(season
, dict):
362 if season
.get('id') != season_id
:
364 season_name
= season
.get('name')
365 items
= season
.get('items')
366 if not isinstance(items
, list):
369 video
= item
.get('item') or {}
370 content_id
= video
.get('videoSvtId')
371 if not content_id
or not isinstance(content_id
, compat_str
):
373 entries
.append(self
.url_result(
374 'svt:' + content_id
, SVTPlayIE
.ie_key(), content_id
))
376 title
= series
.get('name')
377 season_name
= season_name
or season_id
379 if title
and season_name
:
380 title
= '%s - %s' % (title
, season_name
)
384 return self
.playlist_result(
385 entries
, season_id
or series
.get('id'), title
,
386 dict_get(series
, ('longDescription', 'shortDescription')))
389 class SVTPageIE(SVTBaseIE
):
390 _VALID_URL
= r
'https?://(?:www\.)?svt\.se/(?:[^/?#]+/)*(?P<id>[^/?&#]+)'
392 'url': 'https://www.svt.se/nyheter/lokalt/skane/viktor-18-forlorade-armar-och-ben-i-sepsis-vill-ateruppta-karaten-och-bli-svetsare',
394 'title': 'Viktor, 18, förlorade armar och ben i sepsis – vill återuppta karaten och bli svetsare',
395 'id': 'viktor-18-forlorade-armar-och-ben-i-sepsis-vill-ateruppta-karaten-och-bli-svetsare',
399 'url': 'https://www.svt.se/nyheter/lokalt/skane/forsvarsmakten-om-trafikkaoset-pa-e22-kunde-inte-varit-dar-snabbare',
402 'title': 'Försvarsmakten om trafikkaoset på E22: Kunde inte varit där snabbare',
406 'timestamp': 1704370009,
407 'episode': 'Försvarsmakten om trafikkaoset på E22: Kunde inte varit där snabbare',
408 'series': 'Lokala Nyheter Skåne',
409 'upload_date': '20240104'
412 'skip_download': True,
415 'url': 'https://www.svt.se/nyheter/svtforum/2023-tungt-ar-for-svensk-media',
417 'title': '2023 tungt år för svensk media',
423 'timestamp': 1702980479,
424 'upload_date': '20231219',
425 'episode': 'Mediestudier'
428 'skip_download': True,
431 'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
434 'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
437 'skip': 'Video is gone'
439 'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
442 'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
445 'skip': 'Video is gone'
448 'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
452 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
456 'skip': 'Video is gone'
458 'url': 'https://www.svt.se/nyheter/lokalt/vast/svt-testar-tar-nagon-upp-skrapet-1',
459 'only_matching': True,
461 'url': 'https://www.svt.se/vader/manadskronikor/maj2018',
462 'only_matching': True,
466 def suitable(cls
, url
):
467 return False if SVTIE
.suitable(url
) or SVTPlayIE
.suitable(url
) else super(SVTPageIE
, cls
).suitable(url
)
469 def _real_extract(self
, url
):
470 display_id
= self
._match
_id
(url
)
472 webpage
= self
._download
_webpage
(url
, display_id
)
473 title
= self
._og
_search
_title
(webpage
)
475 urql_state
= self
._search
_json
(
476 r
'window\.svt\.nyh\.urqlState\s*=', webpage
, 'json data', display_id
)
478 data
= traverse_obj(urql_state
, (..., 'data', {str}
, {json.loads}
), get_all
=False) or {}
481 for video_id
in set(traverse_obj(data
, (
482 'page', (('topMedia', 'svtId'), ('body', ..., 'video', 'svtId')), {str}
484 info
= self
._extract
_video
(
485 self
._download
_json
(f
'https://api.svt.se/video/{video_id}', video_id
), video_id
)
486 info
['title'] = title
489 return self
.playlist_result(entries(), display_id
, title
)