2015-02-10 00:05:01 +09:00
|
|
|
|
# coding: utf-8
|
2015-02-09 23:56:46 +09:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2015-03-01 00:25:04 +09:00
|
|
|
|
import re
|
|
|
|
|
|
2015-02-09 23:56:46 +09:00
|
|
|
|
from .common import InfoExtractor
|
2020-01-27 00:17:51 +09:00
|
|
|
|
from ..compat import compat_str
|
2015-02-09 23:56:46 +09:00
|
|
|
|
from ..utils import (
|
|
|
|
|
determine_ext,
|
2016-06-21 18:55:53 +09:00
|
|
|
|
dict_get,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
int_or_none,
|
2020-11-22 01:24:37 +09:00
|
|
|
|
unified_timestamp,
|
2020-01-26 22:15:49 +09:00
|
|
|
|
str_or_none,
|
2018-06-28 06:29:11 +09:00
|
|
|
|
strip_or_none,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
try_get,
|
2015-02-09 23:56:46 +09:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2015-05-09 03:12:42 +09:00
|
|
|
|
class SVTBaseIE(InfoExtractor):
|
2017-02-19 05:53:23 +09:00
|
|
|
|
_GEO_COUNTRIES = ['SE']
|
2017-02-20 04:25:55 +09:00
|
|
|
|
|
2016-06-23 01:36:07 +09:00
|
|
|
|
def _extract_video(self, video_info, video_id):
|
2018-03-18 00:14:20 +09:00
|
|
|
|
is_live = dict_get(video_info, ('live', 'simulcast'), default=False)
|
|
|
|
|
m3u8_protocol = 'm3u8' if is_live else 'm3u8_native'
|
2015-02-09 23:56:46 +09:00
|
|
|
|
formats = []
|
|
|
|
|
for vr in video_info['videoReferences']:
|
2016-09-17 21:25:31 +09:00
|
|
|
|
player_type = vr.get('playerType') or vr.get('format')
|
2015-02-09 23:56:46 +09:00
|
|
|
|
vurl = vr['url']
|
2015-03-01 00:25:04 +09:00
|
|
|
|
ext = determine_ext(vurl)
|
|
|
|
|
if ext == 'm3u8':
|
2015-02-09 23:56:46 +09:00
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
|
vurl, video_id,
|
2018-03-18 00:14:20 +09:00
|
|
|
|
ext='mp4', entry_protocol=m3u8_protocol,
|
2016-03-16 03:33:09 +09:00
|
|
|
|
m3u8_id=player_type, fatal=False))
|
2015-03-01 00:25:04 +09:00
|
|
|
|
elif ext == 'f4m':
|
|
|
|
|
formats.extend(self._extract_f4m_formats(
|
|
|
|
|
vurl + '?hdcore=3.3.0', video_id,
|
2016-03-16 03:33:09 +09: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 23:56:46 +09:00
|
|
|
|
else:
|
|
|
|
|
formats.append({
|
2016-03-16 03:33:09 +09:00
|
|
|
|
'format_id': player_type,
|
2015-02-09 23:56:46 +09:00
|
|
|
|
'url': vurl,
|
|
|
|
|
})
|
2020-11-22 01:24:37 +09:00
|
|
|
|
rights = try_get(video_info, lambda x: x['rights'], dict) or {}
|
|
|
|
|
if not formats and rights.get('geoBlockedSweden'):
|
2017-02-04 20:52:33 +09:00
|
|
|
|
self.raise_geo_restricted(
|
2017-02-19 05:53:23 +09:00
|
|
|
|
'This video is only available in Sweden',
|
|
|
|
|
countries=self._GEO_COUNTRIES)
|
2015-02-09 23:56:46 +09:00
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
2016-01-13 01:08:55 +09:00
|
|
|
|
subtitles = {}
|
2016-06-21 18:55:53 +09:00
|
|
|
|
subtitle_references = dict_get(video_info, ('subtitles', 'subtitleReferences'))
|
2016-01-23 04:47:54 +09:00
|
|
|
|
if isinstance(subtitle_references, list):
|
|
|
|
|
for sr in subtitle_references:
|
|
|
|
|
subtitle_url = sr.get('url')
|
2016-06-21 18:55:53 +09:00
|
|
|
|
subtitle_lang = sr.get('language', 'sv')
|
2016-01-23 04:47:54 +09:00
|
|
|
|
if subtitle_url:
|
2016-06-21 18:55:53 +09: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-13 01:08:55 +09:00
|
|
|
|
|
2016-06-23 01:36:07 +09: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-22 01:24:37 +09:00
|
|
|
|
timestamp = unified_timestamp(rights.get('validFrom'))
|
2016-06-23 01:36:07 +09: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 23:56:46 +09:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
'title': title,
|
2015-02-09 23:56:46 +09:00
|
|
|
|
'formats': formats,
|
2016-01-13 01:08:55 +09:00
|
|
|
|
'subtitles': subtitles,
|
2015-02-09 23:56:46 +09:00
|
|
|
|
'duration': duration,
|
2020-11-22 01:24:37 +09:00
|
|
|
|
'timestamp': timestamp,
|
2015-03-01 00:25:04 +09:00
|
|
|
|
'age_limit': age_limit,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
'series': series,
|
|
|
|
|
'season_number': season_number,
|
|
|
|
|
'episode': episode,
|
|
|
|
|
'episode_number': episode_number,
|
2018-03-18 00:14:20 +09:00
|
|
|
|
'is_live': is_live,
|
2015-02-09 23:56:46 +09:00
|
|
|
|
}
|
2015-05-09 03:12:42 +09: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 18:55:53 +09:00
|
|
|
|
'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
|
2015-05-09 03:12:42 +09:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2900353',
|
2016-06-21 18:55:53 +09:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Stjärnorna skojar till det - under SVT-intervjun',
|
2015-05-09 03:12:42 +09:00
|
|
|
|
'duration': 27,
|
|
|
|
|
'age_limit': 0,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 03:23:35 +09: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-09 03:12:42 +09: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 18:55:53 +09:00
|
|
|
|
|
|
|
|
|
info = self._download_json(
|
2015-05-09 03:12:42 +09:00
|
|
|
|
'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id),
|
|
|
|
|
article_id)
|
|
|
|
|
|
2016-06-23 01:36:07 +09:00
|
|
|
|
info_dict = self._extract_video(info['video'], article_id)
|
2016-06-21 18:55:53 +09:00
|
|
|
|
info_dict['title'] = info['context']['title']
|
|
|
|
|
return info_dict
|
|
|
|
|
|
2015-05-09 03:12:42 +09:00
|
|
|
|
|
2018-04-05 02:28:36 +09: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-09 03:12:42 +09:00
|
|
|
|
IE_DESC = 'SVT Play and Öppet arkiv'
|
2018-06-28 06:29:11 +09:00
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
(?:
|
2020-11-22 01:35:01 +09:00
|
|
|
|
(?:
|
|
|
|
|
svt:|
|
|
|
|
|
https?://(?:www\.)?svt\.se/barnkanalen/barnplay/[^/]+/
|
|
|
|
|
)
|
|
|
|
|
(?P<svt_id>[^/?#&]+)|
|
2018-06-28 06:29:11 +09:00
|
|
|
|
https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
|
2021-03-15 22:42:20 +09:00
|
|
|
|
(?:.*?modalId=(?P<modal_id>[\da-zA-Z-]+))?
|
2018-06-28 06:29:11 +09:00
|
|
|
|
)
|
|
|
|
|
'''
|
2016-06-23 01:36:07 +09:00
|
|
|
|
_TESTS = [{
|
2021-03-15 22:42:20 +09:00
|
|
|
|
'url': 'https://www.svtplay.se/video/30479064',
|
2020-11-22 01:24:37 +09:00
|
|
|
|
'md5': '2382036fd6f8c994856c323fe51c426e',
|
2015-05-09 03:12:42 +09:00
|
|
|
|
'info_dict': {
|
2021-03-15 22:42:20 +09:00
|
|
|
|
'id': '8zVbDPA',
|
2016-01-23 04:47:54 +09:00
|
|
|
|
'ext': 'mp4',
|
2021-03-15 22:42:20 +09:00
|
|
|
|
'title': 'Designdrömmar i Stenungsund',
|
|
|
|
|
'timestamp': 1615770000,
|
|
|
|
|
'upload_date': '20210315',
|
|
|
|
|
'duration': 3519,
|
2020-11-22 01:24:37 +09:00
|
|
|
|
'thumbnail': r're:^https?://(?:.*[\.-]jpg|www.svtstatic.se/image/.*)$',
|
2015-05-09 03:12:42 +09:00
|
|
|
|
'age_limit': 0,
|
2016-01-23 04:47:54 +09:00
|
|
|
|
'subtitles': {
|
|
|
|
|
'sv': [{
|
2020-11-22 01:24:37 +09:00
|
|
|
|
'ext': 'vtt',
|
2016-01-23 04:47:54 +09:00
|
|
|
|
}]
|
|
|
|
|
},
|
2015-05-09 03:12:42 +09:00
|
|
|
|
},
|
2020-11-22 01:24:37 +09: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,
|
|
|
|
|
},
|
2021-03-15 22:42:20 +09:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/video/30479064/husdrommar/husdrommar-sasong-8-designdrommar-i-stenungsund?modalId=8zVbDPA',
|
|
|
|
|
'only_matching': True,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
}, {
|
|
|
|
|
# geo restricted to Sweden
|
|
|
|
|
'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
|
|
|
|
|
'only_matching': True,
|
2016-06-26 02:29:53 +09:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
|
|
|
|
|
'only_matching': True,
|
2018-03-18 00:14:20 +09:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svtplay.se/kanaler/svt1',
|
|
|
|
|
'only_matching': True,
|
2018-06-28 06:29:11 +09:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:1376446-003A',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:14278044',
|
|
|
|
|
'only_matching': True,
|
2020-11-22 01:35:01 +09:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.svt.se/barnkanalen/barnplay/kar/eWv5MLX/',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'svt:eWv5MLX',
|
|
|
|
|
'only_matching': True,
|
2016-06-23 01:36:07 +09:00
|
|
|
|
}]
|
2016-06-21 18:55:53 +09:00
|
|
|
|
|
2018-06-28 06:29:11 +09: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-13 01:23:29 +09:00
|
|
|
|
'https://api.svt.se/videoplayer-api/video/%s' % video_id,
|
2018-06-28 06:29:11 +09: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-09 03:12:42 +09:00
|
|
|
|
def _real_extract(self, url):
|
2018-06-28 06:29:11 +09:00
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
2021-03-15 22:42:20 +09:00
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
svt_id = mobj.group('svt_id') or mobj.group('modal_id')
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
|
|
|
|
if svt_id:
|
|
|
|
|
return self._extract_by_video_id(svt_id)
|
2016-06-21 18:55:53 +09:00
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
2016-06-23 01:36:07 +09:00
|
|
|
|
data = self._parse_json(
|
|
|
|
|
self._search_regex(
|
2018-04-05 02:28:36 +09:00
|
|
|
|
self._SVTPLAY_RE, webpage, 'embedded data', default='{}',
|
|
|
|
|
group='json'),
|
2016-06-23 01:36:07 +09:00
|
|
|
|
video_id, fatal=False)
|
2016-06-21 18:55:53 +09:00
|
|
|
|
|
|
|
|
|
thumbnail = self._og_search_thumbnail(webpage)
|
|
|
|
|
|
2016-06-23 01:36:07 +09: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-28 06:29:11 +09:00
|
|
|
|
self._adjust_title(info_dict)
|
2016-06-23 01:36:07 +09:00
|
|
|
|
return info_dict
|
|
|
|
|
|
2020-09-06 12:45:57 +09: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-]+)',
|
2021-03-15 22:42:20 +09:00
|
|
|
|
r'<[^>]+\bdata-rt=["\']top-area-play-button["\'][^>]+\bhref=["\'][^"\']*video/%s/[^"\']*\bmodalId=([\da-zA-Z-]+)' % re.escape(video_id),
|
2020-09-13 20:59:37 +09:00
|
|
|
|
r'["\']videoSvtId["\']\s*:\s*["\']([\da-zA-Z-]+)',
|
2021-02-04 06:17:45 +09:00
|
|
|
|
r'["\']videoSvtId\\?["\']\s*:\s*\\?["\']([\da-zA-Z-]+)',
|
2020-09-13 20:59:37 +09:00
|
|
|
|
r'"content"\s*:\s*{.*?"id"\s*:\s*"([\da-zA-Z-]+)"',
|
2021-02-04 06:17:45 +09:00
|
|
|
|
r'["\']svtId["\']\s*:\s*["\']([\da-zA-Z-]+)',
|
|
|
|
|
r'["\']svtId\\?["\']\s*:\s*\\?["\']([\da-zA-Z-]+)'),
|
2020-09-06 12:45:57 +09:00
|
|
|
|
webpage, 'video id')
|
2016-06-23 01:36:07 +09:00
|
|
|
|
|
2020-11-22 01:24:37 +09:00
|
|
|
|
info_dict = self._extract_by_video_id(svt_id, webpage)
|
|
|
|
|
info_dict['thumbnail'] = thumbnail
|
|
|
|
|
|
|
|
|
|
return info_dict
|
2018-03-31 03:02:09 +09:00
|
|
|
|
|
|
|
|
|
|
2018-04-05 02:28:36 +09:00
|
|
|
|
class SVTSeriesIE(SVTPlayBaseIE):
|
2020-01-27 00:17:51 +09:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svtplay\.se/(?P<id>[^/?&#]+)(?:.+?\btab=(?P<season_slug>[^&#]+))?'
|
2018-03-31 03:02:09 +09:00
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://www.svtplay.se/rederiet',
|
|
|
|
|
'info_dict': {
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'id': '14445680',
|
2018-03-31 03:02:09 +09:00
|
|
|
|
'title': 'Rederiet',
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-03-31 03:02:09 +09:00
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 318,
|
2018-04-05 02:05:09 +09:00
|
|
|
|
}, {
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'url': 'https://www.svtplay.se/rederiet?tab=season-2-14445680',
|
2018-04-05 02:05:09 +09:00
|
|
|
|
'info_dict': {
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'id': 'season-2-14445680',
|
2018-04-05 02:05:09 +09:00
|
|
|
|
'title': 'Rederiet - Säsong 2',
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'description': 'md5:d9fdfff17f5d8f73468176ecd2836039',
|
2018-04-05 02:05:09 +09:00
|
|
|
|
},
|
2020-01-27 00:17:51 +09:00
|
|
|
|
'playlist_mincount': 12,
|
2018-03-31 03:02:09 +09:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def suitable(cls, url):
|
2018-04-05 01:52:00 +09:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTSeriesIE, cls).suitable(url)
|
2018-03-31 03:02:09 +09:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2020-01-27 00:17:51 +09: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-05 02:05:09 +09:00
|
|
|
|
|
|
|
|
|
season_name = None
|
2018-03-31 03:02:09 +09:00
|
|
|
|
|
|
|
|
|
entries = []
|
2020-01-27 00:17:51 +09:00
|
|
|
|
for season in series['associatedContent']:
|
2018-04-05 02:05:09 +09:00
|
|
|
|
if not isinstance(season, dict):
|
|
|
|
|
continue
|
2020-01-27 00:17:51 +09:00
|
|
|
|
if season_id:
|
|
|
|
|
if season.get('id') != season_id:
|
2018-04-05 02:05:09 +09:00
|
|
|
|
continue
|
|
|
|
|
season_name = season.get('name')
|
2020-01-27 00:17:51 +09:00
|
|
|
|
items = season.get('items')
|
|
|
|
|
if not isinstance(items, list):
|
2018-03-31 03:02:09 +09:00
|
|
|
|
continue
|
2020-01-27 00:17:51 +09: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-31 03:02:09 +09:00
|
|
|
|
continue
|
2020-01-27 00:17:51 +09:00
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'svt:' + content_id, SVTPlayIE.ie_key(), content_id))
|
2018-04-05 01:52:00 +09:00
|
|
|
|
|
2020-01-27 00:17:51 +09:00
|
|
|
|
title = series.get('name')
|
|
|
|
|
season_name = season_name or season_id
|
2018-04-05 02:05:09 +09:00
|
|
|
|
|
|
|
|
|
if title and season_name:
|
|
|
|
|
title = '%s - %s' % (title, season_name)
|
2020-01-27 00:17:51 +09:00
|
|
|
|
elif season_id:
|
|
|
|
|
title = season_id
|
2018-04-05 02:05:09 +09:00
|
|
|
|
|
2018-03-31 03:02:09 +09:00
|
|
|
|
return self.playlist_result(
|
2020-01-27 00:17:51 +09:00
|
|
|
|
entries, season_id or series.get('id'), title,
|
|
|
|
|
dict_get(series, ('longDescription', 'shortDescription')))
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVTPageIE(InfoExtractor):
|
2020-01-26 22:15:49 +09:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?svt\.se/(?P<path>(?:[^/]+/)*(?P<id>[^/?&#]+))'
|
2018-06-28 06:29:11 +09:00
|
|
|
|
_TESTS = [{
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'url': 'https://www.svt.se/sport/ishockey/bakom-masken-lehners-kamp-mot-mental-ohalsa',
|
2018-06-28 06:29:11 +09:00
|
|
|
|
'info_dict': {
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'id': '25298267',
|
|
|
|
|
'title': 'Bakom masken – Lehners kamp mot mental ohälsa',
|
2018-06-28 06:29:11 +09:00
|
|
|
|
},
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'playlist_count': 4,
|
2018-06-28 06:29:11 +09:00
|
|
|
|
}, {
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'url': 'https://www.svt.se/nyheter/utrikes/svenska-andrea-ar-en-mil-fran-branderna-i-kalifornien',
|
2018-06-28 06:29:11 +09:00
|
|
|
|
'info_dict': {
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'id': '24243746',
|
|
|
|
|
'title': 'Svenska Andrea redo att fly sitt hem i Kalifornien',
|
2018-06-28 06:29:11 +09:00
|
|
|
|
},
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'playlist_count': 2,
|
2018-06-28 06:29:11 +09:00
|
|
|
|
}, {
|
|
|
|
|
# only programTitle
|
|
|
|
|
'url': 'http://www.svt.se/sport/ishockey/jagr-tacklar-giroux-under-intervjun',
|
|
|
|
|
'info_dict': {
|
2020-01-26 22:15:49 +09:00
|
|
|
|
'id': '8439V2K',
|
2018-06-28 06:29:11 +09: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-22 01:35:01 +09:00
|
|
|
|
return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTPageIE, cls).suitable(url)
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2020-01-26 22:15:49 +09:00
|
|
|
|
path, display_id = re.match(self._VALID_URL, url).groups()
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
2020-01-26 22:15:49 +09:00
|
|
|
|
article = self._download_json(
|
|
|
|
|
'https://api.svt.se/nss-api/page/' + path, display_id,
|
|
|
|
|
query={'q': 'articles'})['articles']['content'][0]
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
2020-01-26 22:15:49 +09:00
|
|
|
|
entries = []
|
2018-06-28 06:29:11 +09:00
|
|
|
|
|
2020-01-26 22:15:49 +09: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-28 06:29:11 +09:00
|
|
|
|
|
2020-01-26 22:15:49 +09: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')))
|