2023-09-02 10:40:11 -04:00
|
|
|
|
import json
|
2015-02-28 10:25:04 -05:00
|
|
|
|
import re
|
|
|
|
|
|
2015-02-09 09:56:46 -05:00
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..utils import (
|
|
|
|
|
determine_ext,
|
2016-06-21 05:55:53 -04:00
|
|
|
|
dict_get,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
int_or_none,
|
2023-09-02 10:40:11 -04:00
|
|
|
|
traverse_obj,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
try_get,
|
2023-09-02 10:40:11 -04:00
|
|
|
|
unified_timestamp,
|
2015-02-09 09:56:46 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2015-05-08 14:12:42 -04:00
|
|
|
|
class SVTBaseIE(InfoExtractor):
|
2017-02-18 15:53:23 -05:00
|
|
|
|
_GEO_COUNTRIES = ['SE']
|
2017-02-19 14:25:55 -05:00
|
|
|
|
|
2016-06-22 12:36:07 -04:00
|
|
|
|
def _extract_video(self, video_info, video_id):
|
2018-03-17 11:14:20 -04:00
|
|
|
|
is_live = dict_get(video_info, ('live', 'simulcast'), default=False)
|
|
|
|
|
m3u8_protocol = 'm3u8' if is_live else 'm3u8_native'
|
2015-02-09 09:56:46 -05:00
|
|
|
|
formats = []
|
2022-02-11 14:03:33 -05:00
|
|
|
|
subtitles = {}
|
2015-02-09 09:56:46 -05:00
|
|
|
|
for vr in video_info['videoReferences']:
|
2016-09-17 08:25:31 -04:00
|
|
|
|
player_type = vr.get('playerType') or vr.get('format')
|
2015-02-09 09:56:46 -05:00
|
|
|
|
vurl = vr['url']
|
2015-02-28 10:25:04 -05:00
|
|
|
|
ext = determine_ext(vurl)
|
|
|
|
|
if ext == 'm3u8':
|
2022-02-11 14:03:33 -05:00
|
|
|
|
fmts, subs = self._extract_m3u8_formats_and_subtitles(
|
2015-02-09 09:56:46 -05:00
|
|
|
|
vurl, video_id,
|
2018-03-17 11:14:20 -04:00
|
|
|
|
ext='mp4', entry_protocol=m3u8_protocol,
|
2022-02-11 14:03:33 -05:00
|
|
|
|
m3u8_id=player_type, fatal=False)
|
|
|
|
|
formats.extend(fmts)
|
|
|
|
|
self._merge_subtitles(subs, target=subtitles)
|
2015-02-28 10:25:04 -05:00
|
|
|
|
elif ext == 'f4m':
|
|
|
|
|
formats.extend(self._extract_f4m_formats(
|
|
|
|
|
vurl + '?hdcore=3.3.0', video_id,
|
2016-03-15 14:33:09 -04:00
|
|
|
|
f4m_id=player_type, fatal=False))
|
|
|
|
|
elif ext == 'mpd':
|
2022-02-11 14:03:33 -05:00
|
|
|
|
fmts, subs = self._extract_mpd_formats_and_subtitles(
|
|
|
|
|
vurl, video_id, mpd_id=player_type, fatal=False)
|
|
|
|
|
formats.extend(fmts)
|
|
|
|
|
self._merge_subtitles(subs, target=subtitles)
|
2015-02-09 09:56:46 -05:00
|
|
|
|
else:
|
|
|
|
|
formats.append({
|
2016-03-15 14:33:09 -04:00
|
|
|
|
'format_id': player_type,
|
2015-02-09 09:56:46 -05:00
|
|
|
|
'url': vurl,
|
|
|
|
|
})
|
2020-11-21 09:50:42 -05:00
|
|
|
|
rights = try_get(video_info, lambda x: x['rights'], dict) or {}
|
|
|
|
|
if not formats and rights.get('geoBlockedSweden'):
|
2017-02-04 06:52:33 -05:00
|
|
|
|
self.raise_geo_restricted(
|
2017-02-18 15:53:23 -05:00
|
|
|
|
'This video is only available in Sweden',
|
2021-04-16 20:09:58 -04:00
|
|
|
|
countries=self._GEO_COUNTRIES, metadata_available=True)
|
2015-02-09 09:56:46 -05:00
|
|
|
|
|
2016-06-21 05:55:53 -04:00
|
|
|
|
subtitle_references = dict_get(video_info, ('subtitles', 'subtitleReferences'))
|
2016-01-22 14:47:54 -05:00
|
|
|
|
if isinstance(subtitle_references, list):
|
|
|
|
|
for sr in subtitle_references:
|
|
|
|
|
subtitle_url = sr.get('url')
|
2016-06-21 05:55:53 -04:00
|
|
|
|
subtitle_lang = sr.get('language', 'sv')
|
2016-01-22 14:47:54 -05:00
|
|
|
|
if subtitle_url:
|
2022-02-11 14:03:33 -05:00
|
|
|
|
sub = {
|
|
|
|
|
'url': subtitle_url,
|
|
|
|
|
}
|
2016-06-21 05:55:53 -04:00
|
|
|
|
if determine_ext(subtitle_url) == 'm3u8':
|
2022-02-11 14:03:33 -05:00
|
|
|
|
# XXX: no way of testing, is it ever hit?
|
|
|
|
|
sub['ext'] = 'vtt'
|
|
|
|
|
subtitles.setdefault(subtitle_lang, []).append(sub)
|
2016-01-12 11:08:55 -05:00
|
|
|
|
|
2016-06-22 12:36:07 -04:00
|
|
|
|
title = video_info.get('title')
|
|
|
|
|
|
|
|
|
|
series = video_info.get('programTitle')
|
|
|
|
|
season_number = int_or_none(video_info.get('season'))
|
|
|
|
|
episode = video_info.get('episodeTitle')
|
|
|
|
|
episode_number = int_or_none(video_info.get('episodeNumber'))
|
|
|
|
|
|
2020-11-21 09:50:42 -05:00
|
|
|
|
timestamp = unified_timestamp(rights.get('validFrom'))
|
2016-06-22 12:36:07 -04:00
|
|
|
|
duration = int_or_none(dict_get(video_info, ('materialLength', 'contentDuration')))
|
|
|
|
|
age_limit = None
|
|
|
|
|
adult = dict_get(
|
|
|
|
|
video_info, ('inappropriateForChildren', 'blockedForChildren'),
|
|
|
|
|
skip_false_values=False)
|
|
|
|
|
if adult is not None:
|
|
|
|
|
age_limit = 18 if adult else 0
|
2015-02-09 09:56:46 -05:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
'title': title,
|
2015-02-09 09:56:46 -05:00
|
|
|
|
'formats': formats,
|
2016-01-12 11:08:55 -05:00
|
|
|
|
'subtitles': subtitles,
|
2015-02-09 09:56:46 -05:00
|
|
|
|
'duration': duration,
|
2020-11-21 09:50:42 -05:00
|
|
|
|
'timestamp': timestamp,
|
2015-02-28 10:25:04 -05:00
|
|
|
|
'age_limit': age_limit,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
'series': series,
|
|
|
|
|
'season_number': season_number,
|
|
|
|
|
'episode': episode,
|
|
|
|
|
'episode_number': episode_number,
|
2018-03-17 11:14:20 -04:00
|
|
|
|
'is_live': is_live,
|
2015-02-09 09:56:46 -05:00
|
|
|
|
}
|
2015-05-08 14:12:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVTIE(SVTBaseIE):
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
|
2024-06-11 19:09:58 -04:00
|
|
|
|
_EMBED_REGEX = [rf'(?:<iframe src|href)="(?P<url>{_VALID_URL}[^"]*)"']
|
2015-05-08 14:12:42 -04:00
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
|
2016-06-21 05:55:53 -04:00
|
|
|
|
'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
|
2015-05-08 14:12:42 -04:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2900353',
|
2016-06-21 05:55:53 -04:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Stjärnorna skojar till det - under SVT-intervjun',
|
2015-05-08 14:12:42 -04:00
|
|
|
|
'duration': 27,
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
mobj = self._match_valid_url(url)
|
2015-05-08 14:12:42 -04:00
|
|
|
|
widget_id = mobj.group('widget_id')
|
|
|
|
|
article_id = mobj.group('id')
|
2016-06-21 05:55:53 -04:00
|
|
|
|
|
|
|
|
|
info = self._download_json(
|
2024-06-11 19:09:58 -04:00
|
|
|
|
f'http://www.svt.se/wd?widgetId={widget_id}&articleId={article_id}&format=json&type=embed&output=json',
|
2015-05-08 14:12:42 -04:00
|
|
|
|
article_id)
|
|
|
|
|
|
2016-06-22 12:36:07 -04:00
|
|
|
|
info_dict = self._extract_video(info['video'], article_id)
|
2016-06-21 05:55:53 -04:00
|
|
|
|
info_dict['title'] = info['context']['title']
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2015-05-08 14:12:42 -04:00
|
|
|
|
|
2018-04-04 13:28:36 -04:00
|
|
|
|
class SVTPlayBaseIE(SVTBaseIE):
|
|
|
|
|
_SVTPLAY_RE = r'root\s*\[\s*(["\'])_*svtplay\1\s*\]\s*=\s*(?P<json>{.+?})\s*;\s*\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVTPlayIE(SVTPlayBaseIE):
|
2015-05-08 14:12:42 -04:00
|
|
|
|
IE_DESC = 'SVT Play and Öppet arkiv'
|
2018-06-27 17:29:11 -04:00
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
(?:
|
2020-11-21 09:50:42 -05:00
|
|
|
|
(?:
|
|
|
|
|
svt:|
|
|
|
|
|
https?://(?:www\.)?svt\.se/barnkanalen/barnplay/[^/]+/
|
|
|
|
|
)
|
|
|
|
|
(?P<svt_id>[^/?#&]+)|
|
2018-06-27 17:29:11 -04:00
|
|
|
|
https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
|
2021-05-06 12:01:20 -04:00
|
|
|
|
(?:.*?(?:modalId|id)=(?P<modal_id>[\da-zA-Z-]+))?
|
2018-06-27 17:29:11 -04:00
|
|
|
|
)
|
|
|
|
|
'''
|
2016-06-22 12:36:07 -04:00
|
|
|
|
_TESTS = [{
|
2021-03-21 14:57:54 -04:00
|
|
|
|
'url': 'https://www.svtplay.se/video/30479064',
|
2020-11-21 09:50:42 -05:00
|
|
|
|
'md5': '2382036fd6f8c994856c323fe51c426e',
|
2015-05-08 14:12:42 -04:00
|
|
|
|
'info_dict': {
|
2021-03-21 14:57:54 -04:00
|
|
|
|
'id': '8zVbDPA',
|
2016-01-22 14:47:54 -05:00
|
|
|
|
'ext': 'mp4',
|
2021-03-21 14:57:54 -04:00
|
|
|
|
'title': 'Designdrömmar i Stenungsund',
|
|
|
|
|
'timestamp': 1615770000,
|
|
|
|
|
'upload_date': '20210315',
|
|
|
|
|
'duration': 3519,
|
2020-11-21 09:50:42 -05:00
|
|
|
|
'thumbnail': r're:^https?://(?:.*[\.-]jpg|www.svtstatic.se/image/.*)$',
|
2015-05-08 14:12:42 -04:00
|
|
|
|
'age_limit': 0,
|
2016-01-22 14:47:54 -05:00
|
|
|
|
'subtitles': {
|
|
|
|
|
'sv': [{
|
2020-11-21 09:50:42 -05:00
|
|
|
|
'ext': 'vtt',
|
2024-06-11 19:09:58 -04:00
|
|
|
|
}],
|
2016-01-22 14:47:54 -05:00
|
|
|
|
},
|
2015-05-08 14:12:42 -04:00
|
|
|
|
},
|
2020-11-21 09:50:42 -05:00
|
|
|
|
'params': {
|
2023-09-02 10:40:11 -04:00
|
|
|
|
'skip_download': 'm3u8',
|
|
|
|
|
},
|
|
|
|
|
'skip': 'Episode is no longer available',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/video/emBxBQj',
|
|
|
|
|
'md5': '2382036fd6f8c994856c323fe51c426e',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'eyBd9aj',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '1. Farlig kryssning',
|
|
|
|
|
'timestamp': 1491019200,
|
|
|
|
|
'upload_date': '20170401',
|
|
|
|
|
'duration': 2566,
|
|
|
|
|
'thumbnail': r're:^https?://(?:.*[\.-]jpg|www.svtstatic.se/image/.*)$',
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
'episode': '1. Farlig kryssning',
|
|
|
|
|
'series': 'Rederiet',
|
|
|
|
|
'subtitles': {
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'sv': 'count:3',
|
2023-09-02 10:40:11 -04:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': 'm3u8',
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/video/jz2rYz7/anders-hansen-moter/james-fallon?info=visa',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'jvXAGVb',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'James Fallon',
|
|
|
|
|
'timestamp': 1673917200,
|
|
|
|
|
'upload_date': '20230117',
|
|
|
|
|
'duration': 1081,
|
|
|
|
|
'thumbnail': r're:^https?://(?:.*[\.-]jpg|www.svtstatic.se/image/.*)$',
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
'episode': 'James Fallon',
|
|
|
|
|
'series': 'Anders Hansen möter...',
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': 'dash',
|
2020-11-21 09:50:42 -05:00
|
|
|
|
},
|
2021-03-21 14:57:54 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/video/30479064/husdrommar/husdrommar-sasong-8-designdrommar-i-stenungsund?modalId=8zVbDPA',
|
|
|
|
|
'only_matching': True,
|
2021-05-06 12:01:20 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/video/30684086/rapport/rapport-24-apr-18-00-7?id=e72gVpa',
|
|
|
|
|
'only_matching': True,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
}, {
|
|
|
|
|
# geo restricted to Sweden
|
|
|
|
|
'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
|
|
|
|
|
'only_matching': True,
|
2016-06-25 13:29:53 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
|
|
|
|
|
'only_matching': True,
|
2018-03-17 11:14:20 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/kanaler/svt1',
|
|
|
|
|
'only_matching': True,
|
2018-06-27 17:29:11 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:1376446-003A',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:14278044',
|
|
|
|
|
'only_matching': True,
|
2020-11-21 09:50:42 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/barnkanalen/barnplay/kar/eWv5MLX/',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:eWv5MLX',
|
|
|
|
|
'only_matching': True,
|
2016-06-22 12:36:07 -04:00
|
|
|
|
}]
|
2016-06-21 05:55:53 -04:00
|
|
|
|
|
2018-06-27 17:29:11 -04:00
|
|
|
|
def _extract_by_video_id(self, video_id, webpage=None):
|
|
|
|
|
data = self._download_json(
|
2024-06-11 19:09:58 -04:00
|
|
|
|
f'https://api.svt.se/videoplayer-api/video/{video_id}',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
video_id, headers=self.geo_verification_headers())
|
|
|
|
|
info_dict = self._extract_video(data, video_id)
|
|
|
|
|
if not info_dict.get('title'):
|
|
|
|
|
title = dict_get(info_dict, ('episode', 'series'))
|
|
|
|
|
if not title and webpage:
|
|
|
|
|
title = re.sub(
|
|
|
|
|
r'\s*\|\s*.+?$', '', self._og_search_title(webpage))
|
|
|
|
|
if not title:
|
|
|
|
|
title = video_id
|
|
|
|
|
info_dict['title'] = title
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2015-05-08 14:12:42 -04:00
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
mobj = self._match_valid_url(url)
|
2021-03-21 14:57:54 -04:00
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
svt_id = mobj.group('svt_id') or mobj.group('modal_id')
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
|
|
|
|
if svt_id:
|
|
|
|
|
return self._extract_by_video_id(svt_id)
|
2016-06-21 05:55:53 -04:00
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
2016-06-22 12:36:07 -04:00
|
|
|
|
data = self._parse_json(
|
|
|
|
|
self._search_regex(
|
2018-04-04 13:28:36 -04:00
|
|
|
|
self._SVTPLAY_RE, webpage, 'embedded data', default='{}',
|
|
|
|
|
group='json'),
|
2016-06-22 12:36:07 -04:00
|
|
|
|
video_id, fatal=False)
|
2016-06-21 05:55:53 -04:00
|
|
|
|
|
|
|
|
|
thumbnail = self._og_search_thumbnail(webpage)
|
|
|
|
|
|
2016-06-22 12:36:07 -04:00
|
|
|
|
if data:
|
|
|
|
|
video_info = try_get(
|
|
|
|
|
data, lambda x: x['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video'],
|
|
|
|
|
dict)
|
|
|
|
|
if video_info:
|
|
|
|
|
info_dict = self._extract_video(video_info, video_id)
|
|
|
|
|
info_dict.update({
|
|
|
|
|
'title': data['context']['dispatcher']['stores']['MetaStore']['title'],
|
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
|
})
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2020-09-05 23:45:57 -04:00
|
|
|
|
svt_id = try_get(
|
|
|
|
|
data, lambda x: x['statistics']['dataLake']['content']['id'],
|
2024-06-11 19:09:58 -04:00
|
|
|
|
str)
|
2020-09-05 23:45:57 -04:00
|
|
|
|
|
2023-09-02 10:40:11 -04:00
|
|
|
|
if not svt_id:
|
|
|
|
|
nextjs_data = self._search_nextjs_data(webpage, video_id, fatal=False)
|
|
|
|
|
svt_id = traverse_obj(nextjs_data, (
|
|
|
|
|
'props', 'urqlState', ..., 'data', {json.loads}, 'detailsPageByPath',
|
|
|
|
|
'video', 'svtId', {str}), get_all=False)
|
|
|
|
|
|
2020-09-05 23:45:57 -04:00
|
|
|
|
if not svt_id:
|
|
|
|
|
svt_id = self._search_regex(
|
|
|
|
|
(r'<video[^>]+data-video-id=["\']([\da-zA-Z-]+)',
|
2023-09-02 10:40:11 -04:00
|
|
|
|
r'<[^>]+\bdata-rt=["\']top-area-play-button["\'][^>]+\bhref=["\'][^"\']*video/[\w-]+/[^"\']*\b(?:modalId|id)=([\w-]+)'),
|
2020-09-05 23:45:57 -04:00
|
|
|
|
webpage, 'video id')
|
2016-06-22 12:36:07 -04:00
|
|
|
|
|
2020-11-21 09:50:42 -05:00
|
|
|
|
info_dict = self._extract_by_video_id(svt_id, webpage)
|
|
|
|
|
info_dict['thumbnail'] = thumbnail
|
|
|
|
|
|
|
|
|
|
return info_dict
|
2018-03-30 14:02:09 -04:00
|
|
|
|
|
|
|
|
|
|
2018-04-04 13:28:36 -04:00
|
|
|
|
class SVTSeriesIE(SVTPlayBaseIE):
|
2020-01-26 10:17:51 -05:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svtplay\.se/(?P<id>[^/?&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
|
2018-03-30 14:02:09 -04:00
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://www.svtplay.se/rederiet',
|
|
|
|
|
'info_dict': {
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'id': '14445680',
|
2018-03-30 14:02:09 -04:00
|
|
|
|
'title': 'Rederiet',
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-03-30 14:02:09 -04:00
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 318,
|
2018-04-04 13:05:09 -04:00
|
|
|
|
}, {
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
|
2018-04-04 13:05:09 -04:00
|
|
|
|
'info_dict': {
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'id': 'season-2-14445680',
|
2018-04-04 13:05:09 -04:00
|
|
|
|
'title': 'Rederiet - Säsong 2',
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-04-04 13:05:09 -04:00
|
|
|
|
},
|
2020-01-26 10:17:51 -05:00
|
|
|
|
'playlist_mincount': 12,
|
2018-03-30 14:02:09 -04:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def suitable(cls, url):
|
2024-06-11 19:09:58 -04:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super().suitable(url)
|
2018-03-30 14:02:09 -04:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
series_slug, season_id = self._match_valid_url(url).groups()
|
2020-01-26 10:17:51 -05:00
|
|
|
|
|
|
|
|
|
series = self._download_json(
|
|
|
|
|
'https://api.svt.se/contento/graphql', series_slug,
|
|
|
|
|
'Downloading series page', query={
|
|
|
|
|
'query': '''{
|
|
|
|
|
listablesBySlug(slugs: ["%s"]) {
|
|
|
|
|
associatedContent(include: [productionPeriod, season]) {
|
|
|
|
|
items {
|
|
|
|
|
item {
|
|
|
|
|
... on Episode {
|
|
|
|
|
videoSvtId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
id
|
|
|
|
|
name
|
|
|
|
|
}
|
|
|
|
|
id
|
|
|
|
|
longDescription
|
|
|
|
|
name
|
|
|
|
|
shortDescription
|
|
|
|
|
}
|
2024-06-11 19:09:58 -04:00
|
|
|
|
}''' % series_slug, # noqa: UP031
|
2020-01-26 10:17:51 -05:00
|
|
|
|
})['data']['listablesBySlug'][0]
|
2018-04-04 13:05:09 -04:00
|
|
|
|
|
|
|
|
|
season_name = None
|
2018-03-30 14:02:09 -04:00
|
|
|
|
|
|
|
|
|
entries = []
|
2020-01-26 10:17:51 -05:00
|
|
|
|
for season in series['associatedContent']:
|
2018-04-04 13:05:09 -04:00
|
|
|
|
if not isinstance(season, dict):
|
|
|
|
|
continue
|
2020-01-26 10:17:51 -05:00
|
|
|
|
if season_id:
|
|
|
|
|
if season.get('id') != season_id:
|
2018-04-04 13:05:09 -04:00
|
|
|
|
continue
|
|
|
|
|
season_name = season.get('name')
|
2020-01-26 10:17:51 -05:00
|
|
|
|
items = season.get('items')
|
|
|
|
|
if not isinstance(items, list):
|
2018-03-30 14:02:09 -04:00
|
|
|
|
continue
|
2020-01-26 10:17:51 -05:00
|
|
|
|
for item in items:
|
|
|
|
|
video = item.get('item') or {}
|
|
|
|
|
content_id = video.get('videoSvtId')
|
2024-06-11 19:09:58 -04:00
|
|
|
|
if not content_id or not isinstance(content_id, str):
|
2018-03-30 14:02:09 -04:00
|
|
|
|
continue
|
2020-01-26 10:17:51 -05:00
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'svt:' + content_id, SVTPlayIE.ie_key(), content_id))
|
2018-04-04 12:52:00 -04:00
|
|
|
|
|
2020-01-26 10:17:51 -05:00
|
|
|
|
title = series.get('name')
|
|
|
|
|
season_name = season_name or season_id
|
2018-04-04 13:05:09 -04:00
|
|
|
|
|
|
|
|
|
if title and season_name:
|
2024-06-11 19:09:58 -04:00
|
|
|
|
title = f'{title} - {season_name}'
|
2020-01-26 10:17:51 -05:00
|
|
|
|
elif season_id:
|
|
|
|
|
title = season_id
|
2018-04-04 13:05:09 -04:00
|
|
|
|
|
2018-03-30 14:02:09 -04:00
|
|
|
|
return self.playlist_result(
|
2020-01-26 10:17:51 -05:00
|
|
|
|
entries, season_id or series.get('id'), title,
|
|
|
|
|
dict_get(series, ('longDescription', 'shortDescription')))
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
class SVTPageIE(SVTBaseIE):
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svt\.se/(?:[^/?#]+/)*(?P<id>[^/?&#]+)'
|
2018-06-27 17:29:11 -04:00
|
|
|
|
_TESTS = [{
|
2024-02-16 11:59:25 -05:00
|
|
|
|
'url': 'https://www.svt.se/nyheter/lokalt/skane/viktor-18-forlorade-armar-och-ben-i-sepsis-vill-ateruppta-karaten-och-bli-svetsare',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'title': 'Viktor, 18, förlorade armar och ben i sepsis – vill återuppta karaten och bli svetsare',
|
|
|
|
|
'id': 'viktor-18-forlorade-armar-och-ben-i-sepsis-vill-ateruppta-karaten-och-bli-svetsare',
|
|
|
|
|
},
|
|
|
|
|
'playlist_count': 2,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/nyheter/lokalt/skane/forsvarsmakten-om-trafikkaoset-pa-e22-kunde-inte-varit-dar-snabbare',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'jXvk42E',
|
|
|
|
|
'title': 'Försvarsmakten om trafikkaoset på E22: Kunde inte varit där snabbare',
|
|
|
|
|
'ext': 'mp4',
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'duration': 80,
|
2024-02-16 11:59:25 -05:00
|
|
|
|
'age_limit': 0,
|
|
|
|
|
'timestamp': 1704370009,
|
|
|
|
|
'episode': 'Försvarsmakten om trafikkaoset på E22: Kunde inte varit där snabbare',
|
|
|
|
|
'series': 'Lokala Nyheter Skåne',
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'upload_date': '20240104',
|
2024-02-16 11:59:25 -05:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
2024-06-11 19:09:58 -04:00
|
|
|
|
},
|
2024-02-16 11:59:25 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/nyheter/svtforum/2023-tungt-ar-for-svensk-media',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'title': '2023 tungt år för svensk media',
|
|
|
|
|
'id': 'ewqAZv4',
|
|
|
|
|
'ext': 'mp4',
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'duration': 3074,
|
2024-02-16 11:59:25 -05:00
|
|
|
|
'age_limit': 0,
|
|
|
|
|
'series': '',
|
|
|
|
|
'timestamp': 1702980479,
|
|
|
|
|
'upload_date': '20231219',
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'episode': 'Mediestudier',
|
2024-02-16 11:59:25 -05:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
2024-06-11 19:09:58 -04:00
|
|
|
|
},
|
2024-02-16 11:59:25 -05:00
|
|
|
|
}, {
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
'info_dict': {
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'id': '25298267',
|
|
|
|
|
'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
},
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'playlist_count': 4,
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'skip': 'Video is gone',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
}, {
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
'info_dict': {
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'id': '24243746',
|
|
|
|
|
'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
},
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'playlist_count': 2,
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'skip': 'Video is gone',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
}, {
|
|
|
|
|
# only programTitle
|
|
|
|
|
'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
|
|
|
|
|
'info_dict': {
|
2020-01-26 08:15:49 -05:00
|
|
|
|
'id': '8439V2K',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Stjärnorna skojar till det - under SVT-intervjun',
|
|
|
|
|
'duration': 27,
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
},
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'skip': 'Video is gone',
|
2018-06-27 17:29:11 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/nyheter/lokalt/vast/svt-testar-tar-nagon-upp-skrapet-1',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/vader/manadskronikor/maj2018',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def suitable(cls, url):
|
2024-06-11 19:09:58 -04:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super().suitable(url)
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-02-16 11:59:25 -05:00
|
|
|
|
display_id = self._match_id(url)
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
webpage = self._download_webpage(url, display_id)
|
|
|
|
|
title = self._og_search_title(webpage)
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
urql_state = self._search_json(
|
2024-09-26 12:57:00 -04:00
|
|
|
|
r'window\.svt\.(?:nyh\.)?urqlState\s*=', webpage, 'json data', display_id)
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
data = traverse_obj(urql_state, (..., 'data', {str}, {json.loads}), get_all=False) or {}
|
2018-06-27 17:29:11 -04:00
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
def entries():
|
|
|
|
|
for video_id in set(traverse_obj(data, (
|
2024-06-11 19:09:58 -04:00
|
|
|
|
'page', (('topMedia', 'svtId'), ('body', ..., 'video', 'svtId')), {str},
|
2024-02-16 11:59:25 -05:00
|
|
|
|
))):
|
|
|
|
|
info = self._extract_video(
|
|
|
|
|
self._download_json(f'https://api.svt.se/video/{video_id}', video_id), video_id)
|
|
|
|
|
info['title'] = title
|
|
|
|
|
yield info
|
2020-01-26 08:15:49 -05:00
|
|
|
|
|
2024-02-16 11:59:25 -05:00
|
|
|
|
return self.playlist_result(entries(), display_id, title)
|