2015-10-09 21:08:37 +02:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2021-03-02 09:05:59 +01:00
|
|
|
float_or_none,
|
|
|
|
int_or_none,
|
2021-11-06 02:05:24 +01:00
|
|
|
join_nonempty,
|
2015-10-09 21:08:37 +02:00
|
|
|
parse_iso8601,
|
|
|
|
qualities,
|
2021-03-02 09:05:59 +01:00
|
|
|
try_get,
|
2015-10-09 21:08:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SRGSSRIE(InfoExtractor):
|
2021-03-02 09:05:59 +01:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
(?:
|
|
|
|
https?://tp\.srgssr\.ch/p(?:/[^/]+)+\?urn=urn|
|
|
|
|
srgssr
|
|
|
|
):
|
|
|
|
(?P<bu>
|
|
|
|
srf|rts|rsi|rtr|swi
|
|
|
|
):(?:[^:]+:)?
|
|
|
|
(?P<type>
|
|
|
|
video|audio
|
|
|
|
):
|
|
|
|
(?P<id>
|
|
|
|
[0-9a-f\-]{36}|\d+
|
|
|
|
)
|
|
|
|
'''
|
2017-02-18 21:53:23 +01:00
|
|
|
_GEO_BYPASS = False
|
|
|
|
_GEO_COUNTRIES = ['CH']
|
2015-10-09 21:08:37 +02:00
|
|
|
|
|
|
|
_ERRORS = {
|
|
|
|
'AGERATING12': 'To protect children under the age of 12, this video is only available between 8 p.m. and 6 a.m.',
|
|
|
|
'AGERATING18': 'To protect children under the age of 18, this video is only available between 11 p.m. and 5 a.m.',
|
2015-12-05 15:57:10 +01:00
|
|
|
# 'ENDDATE': 'For legal reasons, this video was only available for a specified period of time.',
|
2015-10-09 21:08:37 +02:00
|
|
|
'GEOBLOCK': 'For legal reasons, this video is only available in Switzerland.',
|
|
|
|
'LEGAL': 'The video cannot be transmitted for legal reasons.',
|
|
|
|
'STARTDATE': 'This video is not yet available. Please try again later.',
|
|
|
|
}
|
2021-03-02 09:05:59 +01:00
|
|
|
_DEFAULT_LANGUAGE_CODES = {
|
|
|
|
'srf': 'de',
|
|
|
|
'rts': 'fr',
|
|
|
|
'rsi': 'it',
|
|
|
|
'rtr': 'rm',
|
|
|
|
'swi': 'en',
|
|
|
|
}
|
2015-10-09 21:08:37 +02:00
|
|
|
|
2016-12-10 10:47:19 +01:00
|
|
|
def _get_tokenized_src(self, url, video_id, format_id):
|
|
|
|
token = self._download_json(
|
2021-03-02 09:05:59 +01:00
|
|
|
'http://tp.srgssr.ch/akahd/token?acl=*',
|
2024-06-12 01:09:58 +02:00
|
|
|
video_id, f'Downloading {format_id} token', fatal=False) or {}
|
2021-03-02 09:05:59 +01:00
|
|
|
auth_params = try_get(token, lambda x: x['token']['authparams'])
|
2016-12-10 10:47:19 +01:00
|
|
|
if auth_params:
|
2021-03-02 09:05:59 +01:00
|
|
|
url += ('?' if '?' not in url else '&') + auth_params
|
2016-12-10 10:47:19 +01:00
|
|
|
return url
|
|
|
|
|
2021-03-02 09:05:59 +01:00
|
|
|
def _get_media_data(self, bu, media_type, media_id):
|
|
|
|
query = {'onlyChapters': True} if media_type == 'video' else {}
|
|
|
|
full_media_data = self._download_json(
|
2024-06-12 01:09:58 +02:00
|
|
|
f'https://il.srgssr.ch/integrationlayer/2.0/{bu}/mediaComposition/{media_type}/{media_id}.json',
|
2021-03-02 09:05:59 +01:00
|
|
|
media_id, query=query)['chapterList']
|
|
|
|
try:
|
|
|
|
media_data = next(
|
|
|
|
x for x in full_media_data if x.get('id') == media_id)
|
|
|
|
except StopIteration:
|
|
|
|
raise ExtractorError('No media information found')
|
|
|
|
|
|
|
|
block_reason = media_data.get('blockReason')
|
|
|
|
if block_reason and block_reason in self._ERRORS:
|
|
|
|
message = self._ERRORS[block_reason]
|
|
|
|
if block_reason == 'GEOBLOCK':
|
2017-02-18 21:53:23 +01:00
|
|
|
self.raise_geo_restricted(
|
|
|
|
msg=message, countries=self._GEO_COUNTRIES)
|
2017-02-04 12:55:23 +01:00
|
|
|
raise ExtractorError(
|
2024-06-12 01:09:58 +02:00
|
|
|
f'{self.IE_NAME} said: {message}', expected=True)
|
2015-12-05 15:57:10 +01:00
|
|
|
|
|
|
|
return media_data
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 03:41:24 +02:00
|
|
|
bu, media_type, media_id = self._match_valid_url(url).groups()
|
2021-03-02 09:05:59 +01:00
|
|
|
media_data = self._get_media_data(bu, media_type, media_id)
|
|
|
|
title = media_data['title']
|
2015-12-05 15:57:10 +01:00
|
|
|
|
2015-10-09 21:08:37 +02:00
|
|
|
formats = []
|
2021-04-15 10:16:15 +02:00
|
|
|
subtitles = {}
|
2021-03-02 09:05:59 +01:00
|
|
|
q = qualities(['SD', 'HD'])
|
|
|
|
for source in (media_data.get('resourceList') or []):
|
|
|
|
format_url = source.get('url')
|
|
|
|
if not format_url:
|
|
|
|
continue
|
|
|
|
protocol = source.get('protocol')
|
|
|
|
quality = source.get('quality')
|
2021-11-06 02:05:24 +01:00
|
|
|
format_id = join_nonempty(protocol, source.get('encoding'), quality)
|
2021-03-02 09:05:59 +01:00
|
|
|
|
|
|
|
if protocol in ('HDS', 'HLS'):
|
|
|
|
if source.get('tokenType') == 'AKAMAI':
|
|
|
|
format_url = self._get_tokenized_src(
|
|
|
|
format_url, media_id, format_id)
|
2021-04-15 10:16:15 +02:00
|
|
|
fmts, subs = self._extract_akamai_formats_and_subtitles(
|
|
|
|
format_url, media_id)
|
|
|
|
formats.extend(fmts)
|
|
|
|
subtitles = self._merge_subtitles(subtitles, subs)
|
2021-03-02 09:05:59 +01:00
|
|
|
elif protocol == 'HLS':
|
2021-04-15 10:16:15 +02:00
|
|
|
m3u8_fmts, m3u8_subs = self._extract_m3u8_formats_and_subtitles(
|
2021-03-02 09:05:59 +01:00
|
|
|
format_url, media_id, 'mp4', 'm3u8_native',
|
2021-04-15 10:16:15 +02:00
|
|
|
m3u8_id=format_id, fatal=False)
|
|
|
|
formats.extend(m3u8_fmts)
|
|
|
|
subtitles = self._merge_subtitles(subtitles, m3u8_subs)
|
2021-03-02 09:05:59 +01:00
|
|
|
elif protocol in ('HTTP', 'HTTPS'):
|
|
|
|
formats.append({
|
|
|
|
'format_id': format_id,
|
|
|
|
'url': format_url,
|
|
|
|
'quality': q(quality),
|
|
|
|
})
|
|
|
|
|
|
|
|
# This is needed because for audio medias the podcast url is usually
|
|
|
|
# always included, even if is only an audio segment and not the
|
|
|
|
# whole episode.
|
|
|
|
if int_or_none(media_data.get('position')) == 0:
|
|
|
|
for p in ('S', 'H'):
|
2024-06-12 01:09:58 +02:00
|
|
|
podcast_url = media_data.get(f'podcast{p}dUrl')
|
2021-03-02 09:05:59 +01:00
|
|
|
if not podcast_url:
|
|
|
|
continue
|
|
|
|
quality = p + 'D'
|
|
|
|
formats.append({
|
|
|
|
'format_id': 'PODCAST-' + quality,
|
|
|
|
'url': podcast_url,
|
|
|
|
'quality': q(quality),
|
|
|
|
})
|
2015-10-09 21:08:37 +02:00
|
|
|
|
2021-03-02 09:05:59 +01:00
|
|
|
if media_type == 'video':
|
|
|
|
for sub in (media_data.get('subtitleList') or []):
|
|
|
|
sub_url = sub.get('url')
|
|
|
|
if not sub_url:
|
|
|
|
continue
|
|
|
|
lang = sub.get('locale') or self._DEFAULT_LANGUAGE_CODES[bu]
|
|
|
|
subtitles.setdefault(lang, []).append({
|
|
|
|
'url': sub_url,
|
|
|
|
})
|
|
|
|
|
2015-10-09 21:08:37 +02:00
|
|
|
return {
|
|
|
|
'id': media_id,
|
|
|
|
'title': title,
|
2021-03-02 09:05:59 +01:00
|
|
|
'description': media_data.get('description'),
|
|
|
|
'timestamp': parse_iso8601(media_data.get('date')),
|
|
|
|
'thumbnail': media_data.get('imageUrl'),
|
|
|
|
'duration': float_or_none(media_data.get('duration'), 1000),
|
|
|
|
'subtitles': subtitles,
|
2015-10-09 21:08:37 +02:00
|
|
|
'formats': formats,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SRGSSRPlayIE(InfoExtractor):
|
2015-12-29 12:01:22 +01:00
|
|
|
IE_DESC = 'srf.ch, rts.ch, rsi.ch, rtr.ch and swissinfo.ch play sites'
|
2019-05-23 19:43:22 +02:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
https?://
|
|
|
|
(?:(?:www|play)\.)?
|
|
|
|
(?P<bu>srf|rts|rsi|rtr|swissinfo)\.ch/play/(?:tv|radio)/
|
|
|
|
(?:
|
|
|
|
[^/]+/(?P<type>video|audio)/[^?]+|
|
|
|
|
popup(?P<type_2>video|audio)player
|
|
|
|
)
|
2020-09-13 16:07:25 +02:00
|
|
|
\?.*?\b(?:id=|urn=urn:[^:]+:video:)(?P<id>[0-9a-f\-]{36}|\d+)
|
2019-05-23 19:43:22 +02:00
|
|
|
'''
|
2015-10-09 21:08:37 +02:00
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://www.srf.ch/play/tv/10vor10/video/snowden-beantragt-asyl-in-russland?id=28e1a57d-5b76-4399-8ab3-9097f071e6c5',
|
2021-03-02 09:05:59 +01:00
|
|
|
'md5': '6db2226ba97f62ad42ce09783680046c',
|
2015-10-09 21:08:37 +02:00
|
|
|
'info_dict': {
|
|
|
|
'id': '28e1a57d-5b76-4399-8ab3-9097f071e6c5',
|
2016-12-10 10:47:19 +01:00
|
|
|
'ext': 'mp4',
|
2015-10-09 21:08:37 +02:00
|
|
|
'upload_date': '20130701',
|
|
|
|
'title': 'Snowden beantragt Asyl in Russland',
|
2021-03-02 09:05:59 +01:00
|
|
|
'timestamp': 1372708215,
|
|
|
|
'duration': 113.827,
|
|
|
|
'thumbnail': r're:^https?://.*1383719781\.png$',
|
2015-10-09 21:08:37 +02:00
|
|
|
},
|
2021-03-02 09:05:59 +01:00
|
|
|
'expected_warnings': ['Unable to download f4m manifest'],
|
2015-12-05 15:57:10 +01:00
|
|
|
}, {
|
2015-10-14 11:40:54 +02:00
|
|
|
'url': 'http://www.rtr.ch/play/radio/actualitad/audio/saira-tujetsch-tuttina-cuntinuar-cun-sedrun-muster-turissem?id=63cb0778-27f8-49af-9284-8c7a8c6d15fc',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '63cb0778-27f8-49af-9284-8c7a8c6d15fc',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'upload_date': '20151013',
|
|
|
|
'title': 'Saira: Tujetsch - tuttina cuntinuar cun Sedrun Mustér Turissem',
|
2021-03-02 09:05:59 +01:00
|
|
|
'timestamp': 1444709160,
|
|
|
|
'duration': 336.816,
|
2015-10-14 11:40:54 +02:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# rtmp download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2015-12-05 15:57:10 +01:00
|
|
|
}, {
|
|
|
|
'url': 'http://www.rts.ch/play/tv/-/video/le-19h30?id=6348260',
|
|
|
|
'md5': '67a2a9ae4e8e62a68d0e9820cc9782df',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '6348260',
|
|
|
|
'display_id': '6348260',
|
2015-12-29 11:36:04 +01:00
|
|
|
'ext': 'mp4',
|
2021-03-02 09:05:59 +01:00
|
|
|
'duration': 1796.76,
|
2015-12-05 15:57:10 +01:00
|
|
|
'title': 'Le 19h30',
|
|
|
|
'upload_date': '20141201',
|
|
|
|
'timestamp': 1417458600,
|
2017-01-02 13:08:07 +01:00
|
|
|
'thumbnail': r're:^https?://.*\.image',
|
2015-12-05 15:57:10 +01:00
|
|
|
},
|
2015-12-29 11:36:04 +01:00
|
|
|
'params': {
|
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2021-03-02 09:05:59 +01:00
|
|
|
}, {
|
|
|
|
'url': 'http://play.swissinfo.ch/play/tv/business/video/why-people-were-against-tax-reforms?id=42960270',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '42960270',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Why people were against tax reforms',
|
|
|
|
'description': 'md5:7ac442c558e9630e947427469c4b824d',
|
|
|
|
'duration': 94.0,
|
|
|
|
'upload_date': '20170215',
|
|
|
|
'timestamp': 1487173560,
|
|
|
|
'thumbnail': r're:https?://www\.swissinfo\.ch/srgscalableimage/42961964',
|
|
|
|
'subtitles': 'count:9',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2019-05-19 18:11:17 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.srf.ch/play/tv/popupvideoplayer?id=c4dba0ca-e75b-43b2-a34f-f708a4932e01',
|
2019-05-23 19:43:22 +02:00
|
|
|
'only_matching': True,
|
2020-09-13 16:07:25 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.srf.ch/play/tv/10vor10/video/snowden-beantragt-asyl-in-russland?urn=urn:srf:video:28e1a57d-5b76-4399-8ab3-9097f071e6c5',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.rts.ch/play/tv/19h30/video/le-19h30?urn=urn:rts:video:6348260',
|
|
|
|
'only_matching': True,
|
2021-03-02 09:05:59 +01:00
|
|
|
}, {
|
|
|
|
# audio segment, has podcastSdUrl of the full episode
|
|
|
|
'url': 'https://www.srf.ch/play/radio/popupaudioplayer?id=50b20dc8-f05b-4972-bf03-e438ff2833eb',
|
|
|
|
'only_matching': True,
|
2015-10-09 21:08:37 +02:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 03:41:24 +02:00
|
|
|
mobj = self._match_valid_url(url)
|
2019-05-23 19:43:22 +02:00
|
|
|
bu = mobj.group('bu')
|
|
|
|
media_type = mobj.group('type') or mobj.group('type_2')
|
|
|
|
media_id = mobj.group('id')
|
2024-06-12 01:09:58 +02:00
|
|
|
return self.url_result(f'srgssr:{bu[:3]}:{media_type}:{media_id}', 'SRGSSR')
|