mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-04-05 14:38:10 -05:00
[ie/vrtmax] Rework extractor (#12479)
Closes #7997, Closes #8174, Closes #9375 Authored by: MichaelDeBoey, bergoid, seproDev Co-authored-by: bergoid <bergoid@users.noreply.github.com> Co-authored-by: sepro <sepro@sepr0.com>
This commit is contained in:
parent
17504f2535
commit
df9ebeec00
@ -1,19 +0,0 @@
|
|||||||
from .common import InfoExtractor
|
|
||||||
from ..utils import (
|
|
||||||
ExtractorError,
|
|
||||||
urlencode_postdata,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GigyaBaseIE(InfoExtractor):
|
|
||||||
def _gigya_login(self, auth_data):
|
|
||||||
auth_info = self._download_json(
|
|
||||||
'https://accounts.eu1.gigya.com/accounts.login', None,
|
|
||||||
note='Logging in', errnote='Unable to log in',
|
|
||||||
data=urlencode_postdata(auth_data))
|
|
||||||
|
|
||||||
error_message = auth_info.get('errorDetails') or auth_info.get('errorMessage')
|
|
||||||
if error_message:
|
|
||||||
raise ExtractorError(
|
|
||||||
f'Unable to login: {error_message}', expected=True)
|
|
||||||
return auth_info
|
|
@ -2,31 +2,33 @@ import json
|
|||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from .gigya import GigyaBaseIE
|
from .common import InfoExtractor
|
||||||
from ..networking.exceptions import HTTPError
|
from ..networking.exceptions import HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
clean_html,
|
clean_html,
|
||||||
extract_attributes,
|
extract_attributes,
|
||||||
|
filter_dict,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
get_element_by_class,
|
get_element_by_class,
|
||||||
get_element_html_by_class,
|
get_element_html_by_class,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
join_nonempty,
|
jwt_decode_hs256,
|
||||||
jwt_encode_hs256,
|
jwt_encode_hs256,
|
||||||
make_archive_id,
|
make_archive_id,
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
parse_age_limit,
|
parse_age_limit,
|
||||||
|
parse_duration,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
strip_or_none,
|
strip_or_none,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
|
try_call,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VRTBaseIE(GigyaBaseIE):
|
class VRTBaseIE(InfoExtractor):
|
||||||
_GEO_BYPASS = False
|
_GEO_BYPASS = False
|
||||||
_PLAYER_INFO = {
|
_PLAYER_INFO = {
|
||||||
'platform': 'desktop',
|
'platform': 'desktop',
|
||||||
@ -37,11 +39,11 @@ class VRTBaseIE(GigyaBaseIE):
|
|||||||
'device': 'undefined (undefined)',
|
'device': 'undefined (undefined)',
|
||||||
'os': {
|
'os': {
|
||||||
'name': 'Windows',
|
'name': 'Windows',
|
||||||
'version': 'x86_64',
|
'version': '10',
|
||||||
},
|
},
|
||||||
'player': {
|
'player': {
|
||||||
'name': 'VRT web player',
|
'name': 'VRT web player',
|
||||||
'version': '2.7.4-prod-2023-04-19T06:05:45',
|
'version': '5.1.1-prod-2025-02-14T08:44:16"',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
# From https://player.vrt.be/vrtnws/js/main.js & https://player.vrt.be/ketnet/js/main.8cdb11341bcb79e4cd44.js
|
# From https://player.vrt.be/vrtnws/js/main.js & https://player.vrt.be/ketnet/js/main.8cdb11341bcb79e4cd44.js
|
||||||
@ -90,20 +92,21 @@ class VRTBaseIE(GigyaBaseIE):
|
|||||||
def _call_api(self, video_id, client='null', id_token=None, version='v2'):
|
def _call_api(self, video_id, client='null', id_token=None, version='v2'):
|
||||||
player_info = {'exp': (round(time.time(), 3) + 900), **self._PLAYER_INFO}
|
player_info = {'exp': (round(time.time(), 3) + 900), **self._PLAYER_INFO}
|
||||||
player_token = self._download_json(
|
player_token = self._download_json(
|
||||||
'https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v2/tokens',
|
f'https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/{version}/tokens',
|
||||||
video_id, 'Downloading player token', headers={
|
video_id, 'Downloading player token', 'Failed to download player token', headers={
|
||||||
**self.geo_verification_headers(),
|
**self.geo_verification_headers(),
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}, data=json.dumps({
|
}, data=json.dumps({
|
||||||
'identityToken': id_token or {},
|
'identityToken': id_token or '',
|
||||||
'playerInfo': jwt_encode_hs256(player_info, self._JWT_SIGNING_KEY, headers={
|
'playerInfo': jwt_encode_hs256(player_info, self._JWT_SIGNING_KEY, headers={
|
||||||
'kid': self._JWT_KEY_ID,
|
'kid': self._JWT_KEY_ID,
|
||||||
}).decode(),
|
}).decode(),
|
||||||
}, separators=(',', ':')).encode())['vrtPlayerToken']
|
}, separators=(',', ':')).encode())['vrtPlayerToken']
|
||||||
|
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
f'https://media-services-public.vrt.be/media-aggregator/{version}/media-items/{video_id}',
|
# The URL below redirects to https://media-services-public.vrt.be/media-aggregator/{version}/media-items/{video_id}
|
||||||
video_id, 'Downloading API JSON', query={
|
f'https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/{version}/videos/{video_id}',
|
||||||
|
video_id, 'Downloading API JSON', 'Failed to download API JSON', query={
|
||||||
'vrtPlayerToken': player_token,
|
'vrtPlayerToken': player_token,
|
||||||
'client': client,
|
'client': client,
|
||||||
}, expected_status=400)
|
}, expected_status=400)
|
||||||
@ -177,154 +180,252 @@ class VRTIE(VRTBaseIE):
|
|||||||
|
|
||||||
|
|
||||||
class VrtNUIE(VRTBaseIE):
|
class VrtNUIE(VRTBaseIE):
|
||||||
IE_DESC = 'VRT MAX'
|
IE_NAME = 'vrtmax'
|
||||||
_VALID_URL = r'https?://(?:www\.)?vrt\.be/vrtnu/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
|
IE_DESC = 'VRT MAX (formerly VRT NU)'
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?vrt\.be/(?:vrtnu|vrtmax)/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# CONTENT_IS_AGE_RESTRICTED
|
'url': 'https://www.vrt.be/vrtmax/a-z/ket---doc/trailer/ket---doc-trailer-s6/',
|
||||||
'url': 'https://www.vrt.be/vrtnu/a-z/de-ideale-wereld/2023-vj/de-ideale-wereld-d20230116/',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'pbs-pub-855b00a8-6ce2-4032-ac4f-1fcf3ae78524$vid-d2243aa1-ec46-4e34-a55b-92568459906f',
|
'id': 'pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Tom Waes',
|
'channel': 'ketnet',
|
||||||
'description': 'Satirisch actualiteitenmagazine met Ella Leyers. Tom Waes is te gast.',
|
'description': 'Neem een kijkje in de bijzondere wereld van deze Ketnetters.',
|
||||||
'timestamp': 1673905125,
|
'display_id': 'ket---doc-trailer-s6',
|
||||||
'release_timestamp': 1673905125,
|
'duration': 30.0,
|
||||||
'series': 'De ideale wereld',
|
'episode': 'Reeks 6 volledig vanaf 3 maart',
|
||||||
'season_id': '1672830988794',
|
'episode_id': '1739450401467',
|
||||||
'episode': 'Aflevering 1',
|
'season': 'Trailer',
|
||||||
'episode_number': 1,
|
'season_id': '1739450401467',
|
||||||
'episode_id': '1672830988861',
|
'series': 'Ket & Doc',
|
||||||
'display_id': 'de-ideale-wereld-d20230116',
|
'thumbnail': 'https://images.vrt.be/orig/2025/02/21/63f07122-5bbd-4ca1-b42e-8565c6cd95df.jpg',
|
||||||
'channel': 'VRT',
|
'timestamp': 1740373200,
|
||||||
'duration': 1939.0,
|
'title': 'Reeks 6 volledig vanaf 3 maart',
|
||||||
'thumbnail': 'https://images.vrt.be/orig/2023/01/10/1bb39cb3-9115-11ed-b07d-02b7b76bf47f.jpg',
|
'upload_date': '20250224',
|
||||||
'release_date': '20230116',
|
'_old_archive_ids': ['canvas pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251'],
|
||||||
'upload_date': '20230116',
|
|
||||||
'age_limit': 12,
|
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.vrt.be/vrtnu/a-z/buurman--wat-doet-u-nu-/6/buurman--wat-doet-u-nu--s6-trailer/',
|
'url': 'https://www.vrt.be/vrtnu/a-z/taboe/3/taboe-s3a4/',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'pbs-pub-ad4050eb-d9e5-48c2-9ec8-b6c355032361$vid-0465537a-34a8-4617-8352-4d8d983b4eee',
|
'id': 'pbs-pub-f50faa3a-1778-46b6-9117-4ba85f197703$vid-547507fe-1c8b-4394-b361-21e627cbd0fd',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Trailer seizoen 6 \'Buurman, wat doet u nu?\'',
|
'channel': 'een',
|
||||||
'description': 'md5:197424726c61384b4e5c519f16c0cf02',
|
'description': 'md5:bf61345a95eca9393a95de4a7a54b5c6',
|
||||||
'timestamp': 1652940000,
|
'display_id': 'taboe-s3a4',
|
||||||
'release_timestamp': 1652940000,
|
'duration': 2882.02,
|
||||||
'series': 'Buurman, wat doet u nu?',
|
'episode': 'Mensen met het syndroom van Gilles de la Tourette',
|
||||||
'season': 'Seizoen 6',
|
'episode_id': '1739055911734',
|
||||||
'season_number': 6,
|
'episode_number': 4,
|
||||||
'season_id': '1652344200907',
|
'season': '3',
|
||||||
'episode': 'Aflevering 0',
|
'season_id': '1739055911734',
|
||||||
'episode_number': 0,
|
'season_number': 3,
|
||||||
'episode_id': '1652951873524',
|
'series': 'Taboe',
|
||||||
'display_id': 'buurman--wat-doet-u-nu--s6-trailer',
|
'thumbnail': 'https://images.vrt.be/orig/2025/02/19/8198496c-d1ae-4bca-9a48-761cf3ea3ff2.jpg',
|
||||||
'channel': 'VRT',
|
'timestamp': 1740286800,
|
||||||
'duration': 33.13,
|
'title': 'Mensen met het syndroom van Gilles de la Tourette',
|
||||||
'thumbnail': 'https://images.vrt.be/orig/2022/05/23/3c234d21-da83-11ec-b07d-02b7b76bf47f.jpg',
|
'upload_date': '20250223',
|
||||||
'release_date': '20220519',
|
'_old_archive_ids': ['canvas pbs-pub-f50faa3a-1778-46b6-9117-4ba85f197703$vid-547507fe-1c8b-4394-b361-21e627cbd0fd'],
|
||||||
'upload_date': '20220519',
|
|
||||||
},
|
},
|
||||||
'params': {'skip_download': 'm3u8'},
|
|
||||||
}]
|
}]
|
||||||
_NETRC_MACHINE = 'vrtnu'
|
_NETRC_MACHINE = 'vrtnu'
|
||||||
_authenticated = False
|
|
||||||
|
_TOKEN_COOKIE_DOMAIN = '.www.vrt.be'
|
||||||
|
_ACCESS_TOKEN_COOKIE_NAME = 'vrtnu-site_profile_at'
|
||||||
|
_REFRESH_TOKEN_COOKIE_NAME = 'vrtnu-site_profile_rt'
|
||||||
|
_VIDEO_TOKEN_COOKIE_NAME = 'vrtnu-site_profile_vt'
|
||||||
|
_VIDEO_PAGE_QUERY = '''
|
||||||
|
query VideoPage($pageId: ID!) {
|
||||||
|
page(id: $pageId) {
|
||||||
|
... on EpisodePage {
|
||||||
|
episode {
|
||||||
|
ageRaw
|
||||||
|
description
|
||||||
|
durationRaw
|
||||||
|
episodeNumberRaw
|
||||||
|
id
|
||||||
|
name
|
||||||
|
onTimeRaw
|
||||||
|
program {
|
||||||
|
title
|
||||||
|
}
|
||||||
|
season {
|
||||||
|
id
|
||||||
|
titleRaw
|
||||||
|
}
|
||||||
|
title
|
||||||
|
brand
|
||||||
|
}
|
||||||
|
ldjson
|
||||||
|
player {
|
||||||
|
image {
|
||||||
|
templateUrl
|
||||||
|
}
|
||||||
|
modes {
|
||||||
|
streamId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
def _fetch_tokens(self):
|
||||||
|
has_credentials = self._get_login_info()[0]
|
||||||
|
access_token = self._get_vrt_cookie(self._ACCESS_TOKEN_COOKIE_NAME)
|
||||||
|
video_token = self._get_vrt_cookie(self._VIDEO_TOKEN_COOKIE_NAME)
|
||||||
|
|
||||||
|
if (access_token and not self._is_jwt_token_expired(access_token)
|
||||||
|
and video_token and not self._is_jwt_token_expired(video_token)):
|
||||||
|
return access_token, video_token
|
||||||
|
|
||||||
|
if has_credentials:
|
||||||
|
access_token, video_token = self.cache.load(self._NETRC_MACHINE, 'token_data', default=(None, None))
|
||||||
|
|
||||||
|
if (access_token and not self._is_jwt_token_expired(access_token)
|
||||||
|
and video_token and not self._is_jwt_token_expired(video_token)):
|
||||||
|
self.write_debug('Restored tokens from cache')
|
||||||
|
self._set_cookie(self._TOKEN_COOKIE_DOMAIN, self._ACCESS_TOKEN_COOKIE_NAME, access_token)
|
||||||
|
self._set_cookie(self._TOKEN_COOKIE_DOMAIN, self._VIDEO_TOKEN_COOKIE_NAME, video_token)
|
||||||
|
return access_token, video_token
|
||||||
|
|
||||||
|
if not self._get_vrt_cookie(self._REFRESH_TOKEN_COOKIE_NAME):
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
self._request_webpage(
|
||||||
|
'https://www.vrt.be/vrtmax/sso/refresh', None,
|
||||||
|
note='Refreshing tokens', errnote='Failed to refresh tokens', fatal=False)
|
||||||
|
|
||||||
|
access_token = self._get_vrt_cookie(self._ACCESS_TOKEN_COOKIE_NAME)
|
||||||
|
video_token = self._get_vrt_cookie(self._VIDEO_TOKEN_COOKIE_NAME)
|
||||||
|
|
||||||
|
if not access_token or not video_token:
|
||||||
|
self.cache.store(self._NETRC_MACHINE, 'refresh_token', None)
|
||||||
|
self.cookiejar.clear(self._TOKEN_COOKIE_DOMAIN, '/vrtmax/sso', self._REFRESH_TOKEN_COOKIE_NAME)
|
||||||
|
msg = 'Refreshing of tokens failed'
|
||||||
|
if not has_credentials:
|
||||||
|
self.report_warning(msg)
|
||||||
|
return None, None
|
||||||
|
self.report_warning(f'{msg}. Re-logging in')
|
||||||
|
return self._perform_login(*self._get_login_info())
|
||||||
|
|
||||||
|
if has_credentials:
|
||||||
|
self.cache.store(self._NETRC_MACHINE, 'token_data', (access_token, video_token))
|
||||||
|
|
||||||
|
return access_token, video_token
|
||||||
|
|
||||||
|
def _get_vrt_cookie(self, cookie_name):
|
||||||
|
# Refresh token cookie is scoped to /vrtmax/sso, others are scoped to /
|
||||||
|
return try_call(lambda: self._get_cookies('https://www.vrt.be/vrtmax/sso')[cookie_name].value)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _is_jwt_token_expired(token):
|
||||||
|
return jwt_decode_hs256(token)['exp'] - time.time() < 300
|
||||||
|
|
||||||
def _perform_login(self, username, password):
|
def _perform_login(self, username, password):
|
||||||
auth_info = self._gigya_login({
|
refresh_token = self._get_vrt_cookie(self._REFRESH_TOKEN_COOKIE_NAME)
|
||||||
'APIKey': '3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy',
|
if refresh_token and not self._is_jwt_token_expired(refresh_token):
|
||||||
'targetEnv': 'jssdk',
|
self.write_debug('Using refresh token from logged-in cookies; skipping login with credentials')
|
||||||
'loginID': username,
|
return
|
||||||
'password': password,
|
|
||||||
'authMode': 'cookie',
|
|
||||||
})
|
|
||||||
|
|
||||||
if auth_info.get('errorDetails'):
|
refresh_token = self.cache.load(self._NETRC_MACHINE, 'refresh_token', default=None)
|
||||||
raise ExtractorError(f'Unable to login. VrtNU said: {auth_info["errorDetails"]}', expected=True)
|
if refresh_token and not self._is_jwt_token_expired(refresh_token):
|
||||||
|
self.write_debug('Restored refresh token from cache')
|
||||||
|
self._set_cookie(self._TOKEN_COOKIE_DOMAIN, self._REFRESH_TOKEN_COOKIE_NAME, refresh_token, path='/vrtmax/sso')
|
||||||
|
return
|
||||||
|
|
||||||
# Sometimes authentication fails for no good reason, retry
|
self._request_webpage(
|
||||||
for retry in self.RetryManager():
|
'https://www.vrt.be/vrtmax/sso/login', None,
|
||||||
if retry.attempt > 1:
|
note='Getting session cookies', errnote='Failed to get session cookies')
|
||||||
self._sleep(1, None)
|
|
||||||
try:
|
|
||||||
self._request_webpage(
|
|
||||||
'https://token.vrt.be/vrtnuinitlogin', None, note='Requesting XSRF Token',
|
|
||||||
errnote='Could not get XSRF Token', query={
|
|
||||||
'provider': 'site',
|
|
||||||
'destination': 'https://www.vrt.be/vrtnu/',
|
|
||||||
})
|
|
||||||
self._request_webpage(
|
|
||||||
'https://login.vrt.be/perform_login', None,
|
|
||||||
note='Performing login', errnote='Login failed',
|
|
||||||
query={'client_id': 'vrtnu-site'}, data=urlencode_postdata({
|
|
||||||
'UID': auth_info['UID'],
|
|
||||||
'UIDSignature': auth_info['UIDSignature'],
|
|
||||||
'signatureTimestamp': auth_info['signatureTimestamp'],
|
|
||||||
'_csrf': self._get_cookies('https://login.vrt.be').get('OIDCXSRF').value,
|
|
||||||
}))
|
|
||||||
except ExtractorError as e:
|
|
||||||
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
|
|
||||||
retry.error = e
|
|
||||||
continue
|
|
||||||
raise
|
|
||||||
|
|
||||||
self._authenticated = True
|
login_data = self._download_json(
|
||||||
|
'https://login.vrt.be/perform_login', None, data=json.dumps({
|
||||||
|
'clientId': 'vrtnu-site',
|
||||||
|
'loginID': username,
|
||||||
|
'password': password,
|
||||||
|
}).encode(), headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Oidcxsrf': self._get_cookies('https://login.vrt.be')['OIDCXSRF'].value,
|
||||||
|
}, note='Logging in', errnote='Login failed', expected_status=403)
|
||||||
|
if login_data.get('errorCode'):
|
||||||
|
raise ExtractorError(f'Login failed: {login_data.get("errorMessage")}', expected=True)
|
||||||
|
|
||||||
|
self._request_webpage(
|
||||||
|
login_data['redirectUrl'], None,
|
||||||
|
note='Getting access token', errnote='Failed to get access token')
|
||||||
|
|
||||||
|
access_token = self._get_vrt_cookie(self._ACCESS_TOKEN_COOKIE_NAME)
|
||||||
|
video_token = self._get_vrt_cookie(self._VIDEO_TOKEN_COOKIE_NAME)
|
||||||
|
refresh_token = self._get_vrt_cookie(self._REFRESH_TOKEN_COOKIE_NAME)
|
||||||
|
|
||||||
|
if not all((access_token, video_token, refresh_token)):
|
||||||
|
raise ExtractorError('Unable to extract token cookie values')
|
||||||
|
|
||||||
|
self.cache.store(self._NETRC_MACHINE, 'token_data', (access_token, video_token))
|
||||||
|
self.cache.store(self._NETRC_MACHINE, 'refresh_token', refresh_token)
|
||||||
|
|
||||||
|
return access_token, video_token
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
parsed_url = urllib.parse.urlparse(url)
|
access_token, video_token = self._fetch_tokens()
|
||||||
details = self._download_json(
|
|
||||||
f'{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path.rstrip("/")}.model.json',
|
|
||||||
display_id, 'Downloading asset JSON', 'Unable to download asset JSON')['details']
|
|
||||||
|
|
||||||
watch_info = traverse_obj(details, (
|
metadata = self._download_json(
|
||||||
'actions', lambda _, v: v['type'] == 'watch-episode', {dict}), get_all=False) or {}
|
f'https://www.vrt.be/vrtnu-api/graphql{"" if access_token else "/public"}/v1',
|
||||||
video_id = join_nonempty(
|
display_id, 'Downloading asset JSON', 'Unable to download asset JSON',
|
||||||
'episodePublicationId', 'episodeVideoId', delim='$', from_dict=watch_info)
|
data=json.dumps({
|
||||||
if '$' not in video_id:
|
'operationName': 'VideoPage',
|
||||||
raise ExtractorError('Unable to extract video ID')
|
'query': self._VIDEO_PAGE_QUERY,
|
||||||
|
'variables': {'pageId': urllib.parse.urlparse(url).path},
|
||||||
|
}).encode(),
|
||||||
|
headers=filter_dict({
|
||||||
|
'Authorization': f'Bearer {access_token}' if access_token else None,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-vrt-client-name': 'WEB',
|
||||||
|
'x-vrt-client-version': '1.5.9',
|
||||||
|
'x-vrt-zone': 'default',
|
||||||
|
}))['data']['page']
|
||||||
|
|
||||||
vrtnutoken = self._download_json(
|
video_id = metadata['player']['modes'][0]['streamId']
|
||||||
'https://token.vrt.be/refreshtoken', video_id, note='Retrieving vrtnutoken',
|
|
||||||
errnote='Token refresh failed')['vrtnutoken'] if self._authenticated else None
|
|
||||||
|
|
||||||
video_info = self._call_api(video_id, 'vrtnu-web@PROD', vrtnutoken)
|
try:
|
||||||
|
streaming_info = self._call_api(video_id, 'vrtnu-web@PROD', id_token=video_token)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if not video_token and isinstance(e.cause, HTTPError) and e.cause.status == 404:
|
||||||
|
self.raise_login_required()
|
||||||
|
raise
|
||||||
|
|
||||||
if 'title' not in video_info:
|
formats, subtitles = self._extract_formats_and_subtitles(streaming_info, video_id)
|
||||||
code = video_info.get('code')
|
|
||||||
if code in ('AUTHENTICATION_REQUIRED', 'CONTENT_IS_AGE_RESTRICTED'):
|
code = traverse_obj(streaming_info, ('code', {str}))
|
||||||
self.raise_login_required(code, method='password')
|
if not formats and code:
|
||||||
elif code in ('INVALID_LOCATION', 'CONTENT_AVAILABLE_ONLY_IN_BE'):
|
if code in ('CONTENT_AVAILABLE_ONLY_FOR_BE_RESIDENTS', 'CONTENT_AVAILABLE_ONLY_IN_BE', 'CONTENT_UNAVAILABLE_VIA_PROXY'):
|
||||||
self.raise_geo_restricted(countries=['BE'])
|
self.raise_geo_restricted(countries=['BE'])
|
||||||
elif code == 'CONTENT_AVAILABLE_ONLY_FOR_BE_RESIDENTS_AND_EXPATS':
|
elif code in ('CONTENT_AVAILABLE_ONLY_FOR_BE_RESIDENTS_AND_EXPATS', 'CONTENT_IS_AGE_RESTRICTED', 'CONTENT_REQUIRES_AUTHENTICATION'):
|
||||||
if not self._authenticated:
|
self.raise_login_required()
|
||||||
self.raise_login_required(code, method='password')
|
else:
|
||||||
self.raise_geo_restricted(countries=['BE'])
|
self.raise_no_formats(f'Unable to extract formats: {code}')
|
||||||
raise ExtractorError(code, expected=True)
|
|
||||||
|
|
||||||
formats, subtitles = self._extract_formats_and_subtitles(video_info, video_id)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
**traverse_obj(details, {
|
'duration': float_or_none(streaming_info.get('duration'), 1000),
|
||||||
'title': 'title',
|
'thumbnail': url_or_none(streaming_info.get('posterImageUrl')),
|
||||||
'description': ('description', {clean_html}),
|
**self._json_ld(traverse_obj(metadata, ('ldjson', ..., {json.loads})), video_id, fatal=False),
|
||||||
'timestamp': ('data', 'episode', 'onTime', 'raw', {parse_iso8601}),
|
**traverse_obj(metadata, ('episode', {
|
||||||
'release_timestamp': ('data', 'episode', 'onTime', 'raw', {parse_iso8601}),
|
'title': ('title', {str}),
|
||||||
'series': ('data', 'program', 'title'),
|
'description': ('description', {str}),
|
||||||
'season': ('data', 'season', 'title', 'value'),
|
'timestamp': ('onTimeRaw', {parse_iso8601}),
|
||||||
'season_number': ('data', 'season', 'title', 'raw', {int_or_none}),
|
'series': ('program', 'title', {str}),
|
||||||
'season_id': ('data', 'season', 'id', {str_or_none}),
|
'season': ('season', 'titleRaw', {str}),
|
||||||
'episode': ('data', 'episode', 'number', 'value', {str_or_none}),
|
'season_number': ('season', 'titleRaw', {int_or_none}),
|
||||||
'episode_number': ('data', 'episode', 'number', 'raw', {int_or_none}),
|
'season_id': ('id', {str_or_none}),
|
||||||
'episode_id': ('data', 'episode', 'id', {str_or_none}),
|
'episode': ('title', {str}),
|
||||||
'age_limit': ('data', 'episode', 'age', 'raw', {parse_age_limit}),
|
'episode_number': ('episodeNumberRaw', {int_or_none}),
|
||||||
}),
|
'episode_id': ('id', {str_or_none}),
|
||||||
|
'age_limit': ('ageRaw', {parse_age_limit}),
|
||||||
|
'channel': ('brand', {str}),
|
||||||
|
'duration': ('durationRaw', {parse_duration}),
|
||||||
|
})),
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'display_id': display_id,
|
||||||
'channel': 'VRT',
|
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'duration': float_or_none(video_info.get('duration'), 1000),
|
|
||||||
'thumbnail': url_or_none(video_info.get('posterImageUrl')),
|
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
'_old_archive_ids': [make_archive_id('Canvas', video_id)],
|
'_old_archive_ids': [make_archive_id('Canvas', video_id)],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user