2015-02-09 09:05:01 -06:00
|
|
|
|
# coding: utf-8
|
2015-02-09 08:56:46 -06:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2015-02-28 09:25:04 -06:00
|
|
|
|
import re
|
|
|
|
|
|
2015-02-09 08:56:46 -06:00
|
|
|
|
from .common import InfoExtractor
|
2020-01-26 09:17:51 -06:00
|
|
|
|
from ..compat import compat_str
|
2015-02-09 08:56:46 -06:00
|
|
|
|
from ..utils import (
|
|
|
|
|
determine_ext,
|
2016-06-21 04:55:53 -05:00
|
|
|
|
dict_get,
|
2016-06-22 11:36:07 -05:00
|
|
|
|
int_or_none,
|
2020-11-21 10:24:37 -06:00
|
|
|
|
unified_timestamp,
|
2020-01-26 07:15:49 -06:00
|
|
|
|
str_or_none,
|
2018-06-27 16:29:11 -05:00
|
|
|
|
strip_or_none,
|
2016-06-22 11:36:07 -05:00
|
|
|
|
try_get,
|
2015-02-09 08:56:46 -06:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2015-05-08 13:12:42 -05:00
|
|
|
|
class SVTBaseIE(InfoExtractor):
|
2017-02-18 14:53:23 -06:00
|
|
|
|
_GEO_COUNTRIES = ['SE']
|
2017-02-19 13:25:55 -06:00
|
|
|
|
|
2016-06-22 11:36:07 -05:00
|
|
|
|
def _extract_video(self, video_info, video_id):
|
2018-03-17 10:14:20 -05:00
|
|
|
|
is_live = dict_get(video_info, ('live', 'simulcast'), default=False)
|
|
|
|
|
m3u8_protocol = 'm3u8' if is_live else 'm3u8_native'
|
2015-02-09 08:56:46 -06:00
|
|
|
|
formats = []
|
|
|
|
|
for vr in video_info['videoReferences']:
|
2016-09-17 07:25:31 -05:00
|
|
|
|
player_type = vr.get('playerType') or vr.get('format')
|
2015-02-09 08:56:46 -06:00
|
|
|
|
vurl = vr['url']
|
2015-02-28 09:25:04 -06:00
|
|
|
|
ext = determine_ext(vurl)
|
|
|
|
|
if ext == 'm3u8':
|
2015-02-09 08:56:46 -06:00
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
|
vurl, video_id,
|
2018-03-17 10:14:20 -05:00
|
|
|
|
ext='mp4', entry_protocol=m3u8_protocol,
|
2016-03-15 13:33:09 -05:00
|
|
|
|
m3u8_id=player_type, fatal=False))
|
2015-02-28 09:25:04 -06:00
|
|
|
|
elif ext == 'f4m':
|
|
|
|
|
formats.extend(self._extract_f4m_formats(
|
|
|
|
|
vurl + '?hdcore=3.3.0', video_id,
|
2016-03-15 13:33:09 -05:00
|
|
|
|
f4m_id=player_type, fatal=False))
|
|
|
|
|
elif ext == 'mpd':
|
|
|
|
|
if player_type == 'dashhbbtv':
|
|
|
|
|
formats.extend(self._extract_mpd_formats(
|
|
|
|
|
vurl, video_id, mpd_id=player_type, fatal=False))
|
2015-02-09 08:56:46 -06:00
|
|
|
|
else:
|
|
|
|
|
formats.append({
|
2016-03-15 13:33:09 -05:00
|
|
|
|
'format_id': player_type,
|
2015-02-09 08:56:46 -06:00
|
|
|
|
'url': vurl,
|
|
|
|
|
})
|
2020-11-21 10:24:37 -06:00
|
|
|
|
rights = try_get(video_info, lambda x: x['rights'], dict) or {}
|
|
|
|
|
if not formats and rights.get('geoBlockedSweden'):
|
2017-02-04 05:52:33 -06:00
|
|
|
|
self.raise_geo_restricted(
|
2017-02-18 14:53:23 -06:00
|
|
|
|
'This video is only available in Sweden',
|
|
|
|
|
countries=self._GEO_COUNTRIES)
|
2015-02-09 08:56:46 -06:00
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
2016-01-12 10:08:55 -06:00
|
|
|
|
subtitles = {}
|
2016-06-21 04:55:53 -05:00
|
|
|
|
subtitle_references = dict_get(video_info, ('subtitles', 'subtitleReferences'))
|
2016-01-22 13:47:54 -06:00
|
|
|
|
if isinstance(subtitle_references, list):
|
|
|
|
|
for sr in subtitle_references:
|
|
|
|
|
subtitle_url = sr.get('url')
|
2016-06-21 04:55:53 -05:00
|
|
|
|
subtitle_lang = sr.get('language', 'sv')
|
2016-01-22 13:47:54 -06:00
|
|
|
|
if subtitle_url:
|
2016-06-21 04:55:53 -05:00
|
|
|
|
if determine_ext(subtitle_url) == 'm3u8':
|
|
|
|
|
# TODO(yan12125): handle WebVTT in m3u8 manifests
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
subtitles.setdefault(subtitle_lang, []).append({'url': subtitle_url})
|
2016-01-12 10:08:55 -06:00
|
|
|
|
|
2016-06-22 11:36:07 -05: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 10:24:37 -06:00
|
|
|
|
timestamp = unified_timestamp(rights.get('validFrom'))
|
2016-06-22 11:36:07 -05: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 08:56:46 -06:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
2016-06-22 11:36:07 -05:00
|
|
|
|
'title': title,
|
2015-02-09 08:56:46 -06:00
|
|
|
|
'formats': formats,
|
2016-01-12 10:08:55 -06:00
|
|
|
|
'subtitles': subtitles,
|
2015-02-09 08:56:46 -06:00
|
|
|
|
'duration': duration,
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'timestamp': timestamp,
|
2015-02-28 09:25:04 -06:00
|
|
|
|
'age_limit': age_limit,
|
2016-06-22 11:36:07 -05:00
|
|
|
|
'series': series,
|
|
|
|
|
'season_number': season_number,
|
|
|
|
|
'episode': episode,
|
|
|
|
|
'episode_number': episode_number,
|
2018-03-17 10:14:20 -05:00
|
|
|
|
'is_live': is_live,
|
2015-02-09 08:56:46 -06:00
|
|
|
|
}
|
2015-05-08 13:12:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVTIE(SVTBaseIE):
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
|
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
|
2016-06-21 04:55:53 -05:00
|
|
|
|
'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
|
2015-05-08 13:12:42 -05:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2900353',
|
2016-06-21 04:55:53 -05:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Stjärnorna skojar till det - under SVT-intervjun',
|
2015-05-08 13:12:42 -05:00
|
|
|
|
'duration': 27,
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 13:23:35 -05:00
|
|
|
|
@staticmethod
|
|
|
|
|
def _extract_url(webpage):
|
|
|
|
|
mobj = re.search(
|
|
|
|
|
r'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE._VALID_URL, webpage)
|
|
|
|
|
if mobj:
|
|
|
|
|
return mobj.group('url')
|
|
|
|
|
|
2015-05-08 13:12:42 -05:00
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
widget_id = mobj.group('widget_id')
|
|
|
|
|
article_id = mobj.group('id')
|
2016-06-21 04:55:53 -05:00
|
|
|
|
|
|
|
|
|
info = self._download_json(
|
2015-05-08 13:12:42 -05:00
|
|
|
|
'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id),
|
|
|
|
|
article_id)
|
|
|
|
|
|
2016-06-22 11:36:07 -05:00
|
|
|
|
info_dict = self._extract_video(info['video'], article_id)
|
2016-06-21 04:55:53 -05:00
|
|
|
|
info_dict['title'] = info['context']['title']
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2015-05-08 13:12:42 -05:00
|
|
|
|
|
2018-04-04 12:28:36 -05: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 13:12:42 -05:00
|
|
|
|
IE_DESC = 'SVT Play and Öppet arkiv'
|
2018-06-27 16:29:11 -05:00
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
(?:
|
2020-11-21 10:35:01 -06:00
|
|
|
|
(?:
|
|
|
|
|
svt:|
|
|
|
|
|
https?://(?:www\.)?svt\.se/barnkanalen/barnplay/[^/]+/
|
|
|
|
|
)
|
|
|
|
|
(?P<svt_id>[^/?#&]+)|
|
2018-06-27 16:29:11 -05:00
|
|
|
|
https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
|
|
|
|
|
)
|
|
|
|
|
'''
|
2016-06-22 11:36:07 -05:00
|
|
|
|
_TESTS = [{
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'url': 'https://www.svtplay.se/video/26194546/det-har-ar-himlen',
|
|
|
|
|
'md5': '2382036fd6f8c994856c323fe51c426e',
|
2015-05-08 13:12:42 -05:00
|
|
|
|
'info_dict': {
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'id': 'jNwpV9P',
|
2016-01-22 13:47:54 -06:00
|
|
|
|
'ext': 'mp4',
|
2020-11-21 10:36:25 -06:00
|
|
|
|
'title': 'Det här är himlen',
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'timestamp': 1586044800,
|
|
|
|
|
'upload_date': '20200405',
|
|
|
|
|
'duration': 3515,
|
|
|
|
|
'thumbnail': r're:^https?://(?:.*[\.-]jpg|www.svtstatic.se/image/.*)$',
|
2015-05-08 13:12:42 -05:00
|
|
|
|
'age_limit': 0,
|
2016-01-22 13:47:54 -06:00
|
|
|
|
'subtitles': {
|
|
|
|
|
'sv': [{
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'ext': 'vtt',
|
2016-01-22 13:47:54 -06:00
|
|
|
|
}]
|
|
|
|
|
},
|
2015-05-08 13:12:42 -05:00
|
|
|
|
},
|
2020-11-21 10:24:37 -06:00
|
|
|
|
'params': {
|
|
|
|
|
'format': 'bestvideo',
|
|
|
|
|
# skip for now due to download test asserts that segment is > 10000 bytes and svt uses
|
|
|
|
|
# init segments that are smaller
|
|
|
|
|
# AssertionError: Expected test_SVTPlay_jNwpV9P.mp4 to be at least 9.77KiB, but it's only 864.00B
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2016-06-22 11:36:07 -05:00
|
|
|
|
}, {
|
|
|
|
|
# geo restricted to Sweden
|
|
|
|
|
'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
|
|
|
|
|
'only_matching': True,
|
2016-06-25 12:29:53 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
|
|
|
|
|
'only_matching': True,
|
2018-03-17 10:14:20 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/kanaler/svt1',
|
|
|
|
|
'only_matching': True,
|
2018-06-27 16:29:11 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:1376446-003A',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:14278044',
|
|
|
|
|
'only_matching': True,
|
2020-11-21 10:35:01 -06:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/barnkanalen/barnplay/kar/eWv5MLX/',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:eWv5MLX',
|
|
|
|
|
'only_matching': True,
|
2016-06-22 11:36:07 -05:00
|
|
|
|
}]
|
2016-06-21 04:55:53 -05:00
|
|
|
|
|
2018-06-27 16:29:11 -05:00
|
|
|
|
def _adjust_title(self, info):
|
|
|
|
|
if info['is_live']:
|
|
|
|
|
info['title'] = self._live_title(info['title'])
|
|
|
|
|
|
|
|
|
|
def _extract_by_video_id(self, video_id, webpage=None):
|
|
|
|
|
data = self._download_json(
|
2019-05-12 11:23:29 -05:00
|
|
|
|
'https://api.svt.se/videoplayer-api/video/%s' % video_id,
|
2018-06-27 16:29:11 -05: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
|
|
|
|
|
self._adjust_title(info_dict)
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2015-05-08 13:12:42 -05:00
|
|
|
|
def _real_extract(self, url):
|
2018-06-27 16:29:11 -05:00
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
video_id, svt_id = mobj.group('id', 'svt_id')
|
|
|
|
|
|
|
|
|
|
if svt_id:
|
|
|
|
|
return self._extract_by_video_id(svt_id)
|
2016-06-21 04:55:53 -05:00
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
2016-06-22 11:36:07 -05:00
|
|
|
|
data = self._parse_json(
|
|
|
|
|
self._search_regex(
|
2018-04-04 12:28:36 -05:00
|
|
|
|
self._SVTPLAY_RE, webpage, 'embedded data', default='{}',
|
|
|
|
|
group='json'),
|
2016-06-22 11:36:07 -05:00
|
|
|
|
video_id, fatal=False)
|
2016-06-21 04:55:53 -05:00
|
|
|
|
|
|
|
|
|
thumbnail = self._og_search_thumbnail(webpage)
|
|
|
|
|
|
2016-06-22 11:36:07 -05: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,
|
|
|
|
|
})
|
2018-06-27 16:29:11 -05:00
|
|
|
|
self._adjust_title(info_dict)
|
2016-06-22 11:36:07 -05:00
|
|
|
|
return info_dict
|
|
|
|
|
|
2020-09-05 22:45:57 -05:00
|
|
|
|
svt_id = try_get(
|
|
|
|
|
data, lambda x: x['statistics']['dataLake']['content']['id'],
|
|
|
|
|
compat_str)
|
|
|
|
|
|
|
|
|
|
if not svt_id:
|
|
|
|
|
svt_id = self._search_regex(
|
|
|
|
|
(r'<video[^>]+data-video-id=["\']([\da-zA-Z-]+)',
|
2020-09-13 06:59:37 -05:00
|
|
|
|
r'["\']videoSvtId["\']\s*:\s*["\']([\da-zA-Z-]+)',
|
2021-02-03 15:17:45 -06:00
|
|
|
|
r'["\']videoSvtId\\?["\']\s*:\s*\\?["\']([\da-zA-Z-]+)',
|
2020-09-13 06:59:37 -05:00
|
|
|
|
r'"content"\s*:\s*{.*?"id"\s*:\s*"([\da-zA-Z-]+)"',
|
2021-02-03 15:17:45 -06:00
|
|
|
|
r'["\']svtId["\']\s*:\s*["\']([\da-zA-Z-]+)',
|
|
|
|
|
r'["\']svtId\\?["\']\s*:\s*\\?["\']([\da-zA-Z-]+)'),
|
2020-09-05 22:45:57 -05:00
|
|
|
|
webpage, 'video id')
|
2016-06-22 11:36:07 -05:00
|
|
|
|
|
2020-11-21 10:24:37 -06:00
|
|
|
|
info_dict = self._extract_by_video_id(svt_id, webpage)
|
|
|
|
|
info_dict['thumbnail'] = thumbnail
|
|
|
|
|
|
|
|
|
|
return info_dict
|
2018-03-30 13:02:09 -05:00
|
|
|
|
|
|
|
|
|
|
2018-04-04 12:28:36 -05:00
|
|
|
|
class SVTSeriesIE(SVTPlayBaseIE):
|
2020-01-26 09:17:51 -06:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svtplay\.se/(?P<id>[^/?&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
|
2018-03-30 13:02:09 -05:00
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://www.svtplay.se/rederiet',
|
|
|
|
|
'info_dict': {
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'id': '14445680',
|
2018-03-30 13:02:09 -05:00
|
|
|
|
'title': 'Rederiet',
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-03-30 13:02:09 -05:00
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 318,
|
2018-04-04 12:05:09 -05:00
|
|
|
|
}, {
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
|
2018-04-04 12:05:09 -05:00
|
|
|
|
'info_dict': {
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'id': 'season-2-14445680',
|
2018-04-04 12:05:09 -05:00
|
|
|
|
'title': 'Rederiet - Säsong 2',
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-04-04 12:05:09 -05:00
|
|
|
|
},
|
2020-01-26 09:17:51 -06:00
|
|
|
|
'playlist_mincount': 12,
|
2018-03-30 13:02:09 -05:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def suitable(cls, url):
|
2018-04-04 11:52:00 -05:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTSeriesIE, cls).suitable(url)
|
2018-03-30 13:02:09 -05:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2020-01-26 09:17:51 -06:00
|
|
|
|
series_slug, season_id = re.match(self._VALID_URL, url).groups()
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}''' % series_slug,
|
|
|
|
|
})['data']['listablesBySlug'][0]
|
2018-04-04 12:05:09 -05:00
|
|
|
|
|
|
|
|
|
season_name = None
|
2018-03-30 13:02:09 -05:00
|
|
|
|
|
|
|
|
|
entries = []
|
2020-01-26 09:17:51 -06:00
|
|
|
|
for season in series['associatedContent']:
|
2018-04-04 12:05:09 -05:00
|
|
|
|
if not isinstance(season, dict):
|
|
|
|
|
continue
|
2020-01-26 09:17:51 -06:00
|
|
|
|
if season_id:
|
|
|
|
|
if season.get('id') != season_id:
|
2018-04-04 12:05:09 -05:00
|
|
|
|
continue
|
|
|
|
|
season_name = season.get('name')
|
2020-01-26 09:17:51 -06:00
|
|
|
|
items = season.get('items')
|
|
|
|
|
if not isinstance(items, list):
|
2018-03-30 13:02:09 -05:00
|
|
|
|
continue
|
2020-01-26 09:17:51 -06:00
|
|
|
|
for item in items:
|
|
|
|
|
video = item.get('item') or {}
|
|
|
|
|
content_id = video.get('videoSvtId')
|
|
|
|
|
if not content_id or not isinstance(content_id, compat_str):
|
2018-03-30 13:02:09 -05:00
|
|
|
|
continue
|
2020-01-26 09:17:51 -06:00
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'svt:' + content_id, SVTPlayIE.ie_key(), content_id))
|
2018-04-04 11:52:00 -05:00
|
|
|
|
|
2020-01-26 09:17:51 -06:00
|
|
|
|
title = series.get('name')
|
|
|
|
|
season_name = season_name or season_id
|
2018-04-04 12:05:09 -05:00
|
|
|
|
|
|
|
|
|
if title and season_name:
|
|
|
|
|
title = '%s - %s' % (title, season_name)
|
2020-01-26 09:17:51 -06:00
|
|
|
|
elif season_id:
|
|
|
|
|
title = season_id
|
2018-04-04 12:05:09 -05:00
|
|
|
|
|
2018-03-30 13:02:09 -05:00
|
|
|
|
return self.playlist_result(
|
2020-01-26 09:17:51 -06:00
|
|
|
|
entries, season_id or series.get('id'), title,
|
|
|
|
|
dict_get(series, ('longDescription', 'shortDescription')))
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVTPageIE(InfoExtractor):
|
2020-01-26 07:15:49 -06:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svt\.se/(?P<path>(?:[^/]+/)*(?P<id>[^/?&#]+))'
|
2018-06-27 16:29:11 -05:00
|
|
|
|
_TESTS = [{
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
|
2018-06-27 16:29:11 -05:00
|
|
|
|
'info_dict': {
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'id': '25298267',
|
|
|
|
|
'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
|
2018-06-27 16:29:11 -05:00
|
|
|
|
},
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'playlist_count': 4,
|
2018-06-27 16:29:11 -05:00
|
|
|
|
}, {
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
|
2018-06-27 16:29:11 -05:00
|
|
|
|
'info_dict': {
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'id': '24243746',
|
|
|
|
|
'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
|
2018-06-27 16:29:11 -05:00
|
|
|
|
},
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'playlist_count': 2,
|
2018-06-27 16:29:11 -05:00
|
|
|
|
}, {
|
|
|
|
|
# only programTitle
|
|
|
|
|
'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
|
|
|
|
|
'info_dict': {
|
2020-01-26 07:15:49 -06:00
|
|
|
|
'id': '8439V2K',
|
2018-06-27 16:29:11 -05:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Stjärnorna skojar till det - under SVT-intervjun',
|
|
|
|
|
'duration': 27,
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'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):
|
2020-11-21 10:35:01 -06:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTPageIE, cls).suitable(url)
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2020-01-26 07:15:49 -06:00
|
|
|
|
path, display_id = re.match(self._VALID_URL, url).groups()
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
2020-01-26 07:15:49 -06:00
|
|
|
|
article = self._download_json(
|
|
|
|
|
'https://api.svt.se/nss-api/page/' + path, display_id,
|
|
|
|
|
query={'q': 'articles'})['articles']['content'][0]
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
2020-01-26 07:15:49 -06:00
|
|
|
|
entries = []
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
2020-01-26 07:15:49 -06:00
|
|
|
|
def _process_content(content):
|
|
|
|
|
if content.get('_type') in ('VIDEOCLIP', 'VIDEOEPISODE'):
|
|
|
|
|
video_id = compat_str(content['image']['svtId'])
|
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'svt:' + video_id, SVTPlayIE.ie_key(), video_id))
|
2018-06-27 16:29:11 -05:00
|
|
|
|
|
2020-01-26 07:15:49 -06:00
|
|
|
|
for media in article.get('media', []):
|
|
|
|
|
_process_content(media)
|
|
|
|
|
|
|
|
|
|
for obj in article.get('structuredBody', []):
|
|
|
|
|
_process_content(obj.get('content') or {})
|
|
|
|
|
|
|
|
|
|
return self.playlist_result(
|
|
|
|
|
entries, str_or_none(article.get('id')),
|
|
|
|
|
strip_or_none(article.get('title')))
|