mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-19 14:49:15 +00:00
Able to get vrtPlayerToken
This commit is contained in:
parent
28e4722b00
commit
c96f4429f3
|
@ -36,22 +36,23 @@ class VRTBaseIE(GigyaBaseIE):
|
||||||
_PLAYER_INFO = {
|
_PLAYER_INFO = {
|
||||||
'platform': 'desktop',
|
'platform': 'desktop',
|
||||||
'app': {
|
'app': {
|
||||||
'type': 'browser',
|
'type': 'browser',
|
||||||
'name': 'Chrome',
|
'name': 'Chrome'
|
||||||
},
|
},
|
||||||
'device': 'undefined (undefined)',
|
'device': 'undefined (undefined)',
|
||||||
'os': {
|
'os': {
|
||||||
'name': 'Windows',
|
'name': 'Windows',
|
||||||
'version': 'x86_64'
|
'version': 'x86_64'
|
||||||
},
|
},
|
||||||
'player': {
|
'player': {
|
||||||
'name': 'VRT web player',
|
'name': 'VRT web player',
|
||||||
'version': '2.7.4-prod-2023-04-19T06:05:45'
|
'version': '3.2.6-prod-2023-09-11T12:37:41'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
# 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
|
||||||
_JWT_KEY_ID = '0-0Fp51UZykfaiCJrfTE3+oMI8zvDteYfPtR+2n1R+z8w='
|
_JWT_KEY_ID = '0-0Fp51UZykfaiCJrfTE3+oMI8zvDteYfPtR+2n1R+z8w='
|
||||||
_JWT_SIGNING_KEY = 'b5f500d55cb44715107249ccd8a5c0136cfb2788dbb71b90a4f142423bacaf38' # -dev
|
_JWT_SIGNING_KEY = '2a9251d782700769fb856da5725daf38661874ca6f80ae7dc2b05ec1a81a24ae'
|
||||||
|
# _JWT_SIGNING_KEY = 'b5f500d55cb44715107249ccd8a5c0136cfb2788dbb71b90a4f142423bacaf38' # -dev
|
||||||
# player-stag.vrt.be key: d23987504521ae6fbf2716caca6700a24bb1579477b43c84e146b279de5ca595
|
# player-stag.vrt.be key: d23987504521ae6fbf2716caca6700a24bb1579477b43c84e146b279de5ca595
|
||||||
# player.vrt.be key: 2a9251d782700769fb856da5725daf38661874ca6f80ae7dc2b05ec1a81a24ae
|
# player.vrt.be key: 2a9251d782700769fb856da5725daf38661874ca6f80ae7dc2b05ec1a81a24ae
|
||||||
|
|
||||||
|
@ -153,6 +154,7 @@ class VRTIE(VRTBaseIE):
|
||||||
}
|
}
|
||||||
|
|
||||||
_authenticated = False
|
_authenticated = False
|
||||||
|
_id_token = ''
|
||||||
|
|
||||||
def _perform_login(self, username, password):
|
def _perform_login(self, username, password):
|
||||||
auth_info = self._gigya_login({
|
auth_info = self._gigya_login({
|
||||||
|
@ -311,12 +313,12 @@ class VrtNUIE(VRTBaseIE):
|
||||||
_NETRC_MACHINE = 'vrtnu'
|
_NETRC_MACHINE = 'vrtnu'
|
||||||
_authenticated = False
|
_authenticated = False
|
||||||
|
|
||||||
def _extract_cookies(self, res):
|
# def _extract_cookies(self, res):
|
||||||
cookies_nvp = [header_value.split(';')[0] for header_value in res.headers.get_all('Set-Cookie')]
|
# cookies_nvp = [header_value.split(';')[0] for header_value in res.headers.get_all('Set-Cookie')]
|
||||||
return {name: value for nvp in cookies_nvp for name, value in [nvp.split('=')]}
|
# return {name: value for nvp in cookies_nvp for name, value in [nvp.split('=')]}
|
||||||
|
#
|
||||||
def _create_cookie_header(self, cookies):
|
# def _create_cookie_header(self, cookies):
|
||||||
return { 'Cookie': '; '.join([f'{key}={value}' for key, value in cookies.items()]) }
|
# return { 'Cookie': '; '.join([f'{key}={value}' for key, value in cookies.items()]) }
|
||||||
|
|
||||||
def _perform_login(self, username, password):
|
def _perform_login(self, username, password):
|
||||||
|
|
||||||
|
@ -340,25 +342,24 @@ def _perform_login(self, username, password):
|
||||||
res = urllib.request.urlopen('https://www.vrt.be/vrtnu/sso/login', None)
|
res = urllib.request.urlopen('https://www.vrt.be/vrtnu/sso/login', None)
|
||||||
auth_url = res.headers.get_all('Location')[0]
|
auth_url = res.headers.get_all('Location')[0]
|
||||||
|
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
print('login')
|
# print('login')
|
||||||
print(res.status)
|
# print(res.status)
|
||||||
print(res.headers.get_all('Location')[0])
|
# print(res.headers.get_all('Location')[0])
|
||||||
# for cookie in cookies:
|
# # for cookie in cookies:
|
||||||
# print(f'{cookie.name}={cookie.value}')
|
# # print(f'{cookie.name}={cookie.value}')
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
|
|
||||||
|
|
||||||
# 1.b Follow redirection: visit 'authorize' URL. Get OIDCXSRF & SESSION cookies
|
# 1.b Follow redirection: visit 'authorize' URL. Get OIDCXSRF & SESSION cookies
|
||||||
res = urllib.request.urlopen(auth_url, None)
|
res = urllib.request.urlopen(auth_url, None)
|
||||||
# cookies = {cookie.name: cookie.value for cookie in cookies}
|
|
||||||
cookies_header = f'OIDCXSRF={cookies["OIDCXSRF"]}; SESSION={cookies["SESSION"]}'
|
cookies_header = f'OIDCXSRF={cookies["OIDCXSRF"]}; SESSION={cookies["SESSION"]}'
|
||||||
|
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
print('authorize')
|
# print('authorize')
|
||||||
print(res.status)
|
# print(res.status)
|
||||||
print(cookies)
|
# print(cookies)
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
|
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
|
@ -371,14 +372,16 @@ def _perform_login(self, username, password):
|
||||||
post_data = { "loginID": f"{username}", "password": f"{password}", "clientId": "vrtnu-site" }
|
post_data = { "loginID": f"{username}", "password": f"{password}", "clientId": "vrtnu-site" }
|
||||||
res = self._request_webpage('https://login.vrt.be/perform_login', None, note='Performing login', errnote='Login failed', fatal=True, data=json.dumps(post_data).encode(), headers=headers)
|
res = self._request_webpage('https://login.vrt.be/perform_login', None, note='Performing login', errnote='Login failed', fatal=True, data=json.dumps(post_data).encode(), headers=headers)
|
||||||
|
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
print('perform_login')
|
# print('perform_login')
|
||||||
print(res.status)
|
# print(res.status)
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
|
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
# TODO: re-enable auto redir here and do step 3 in one urlopen() call?
|
# TODO:
|
||||||
|
# . re-enable auto redir here and do step 3 in one urlopen() call?
|
||||||
|
# . should this step be the new "refreshtoken" in _real_extract?
|
||||||
|
|
||||||
# 3.a Visit 'authorize' again
|
# 3.a Visit 'authorize' again
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -389,13 +392,13 @@ def _perform_login(self, username, password):
|
||||||
res = urllib.request.urlopen(request, None)
|
res = urllib.request.urlopen(request, None)
|
||||||
callback_url = res.headers.get_all('Location')[0]
|
callback_url = res.headers.get_all('Location')[0]
|
||||||
|
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
print('authorize')
|
# print('authorize')
|
||||||
print(res.status)
|
# print(res.status)
|
||||||
print(res.headers.get_all('Location')[0])
|
# print(res.headers.get_all('Location')[0])
|
||||||
# print(cookies)
|
# # print(cookies)
|
||||||
# print(json.dumps(tokens))
|
# # print(json.dumps(tokens))
|
||||||
print("===================================")
|
# print("===================================")
|
||||||
|
|
||||||
# 3.b Visit 'callback'
|
# 3.b Visit 'callback'
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -404,62 +407,70 @@ def _perform_login(self, username, password):
|
||||||
request = urllib.request.Request(callback_url, headers=headers)
|
request = urllib.request.Request(callback_url, headers=headers)
|
||||||
res = urllib.request.urlopen(request, None)
|
res = urllib.request.urlopen(request, None)
|
||||||
|
|
||||||
print("===================================")
|
_id_token = cookies['vrtnu-site_profile_vt']
|
||||||
print('callback')
|
|
||||||
print(res.status)
|
# print("===================================")
|
||||||
print(res.headers)
|
# print('callback')
|
||||||
print(cookies)
|
# print(res.status)
|
||||||
|
# print(res.headers)
|
||||||
|
# print(cookies)
|
||||||
# print(json.dumps(tokens))
|
# print(json.dumps(tokens))
|
||||||
|
|
||||||
# for cookie in cookies:
|
# for cookie in cookies:
|
||||||
# print(f'{cookie.name}={cookie.value}')
|
# print(f'{cookie.name}={cookie.value}')
|
||||||
print("===================================")
|
print("===================================")
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# auth_info = self._gigya_login({
|
|
||||||
# 'APIKey': '3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy',
|
|
||||||
# 'targetEnv': 'jssdk',
|
|
||||||
# 'loginID': username,
|
|
||||||
# 'password': password,
|
|
||||||
# 'authMode': 'cookie',
|
|
||||||
# })
|
|
||||||
#
|
|
||||||
# if auth_info.get('errorDetails'):
|
|
||||||
# raise ExtractorError(f'Unable to login. VrtNU said: {auth_info["errorDetails"]}', expected=True)
|
|
||||||
|
|
||||||
# print("===================================")
|
|
||||||
# print(json.dumps(auth_info, indent=2))
|
|
||||||
# print("===================================")
|
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
# Sometimes authentication fails for no good reason, retry
|
# 4. Obtain vrtPlayerToken
|
||||||
# for retry in self.RetryManager():
|
|
||||||
# if retry.attempt > 1:
|
# TODO: make this a constant at the top
|
||||||
# self._sleep(1, None)
|
#########################################
|
||||||
# try:
|
player_info_base = {
|
||||||
# self._request_webpage(
|
'platform': 'desktop',
|
||||||
# 'https://token.vrt.be/vrtnuinitlogin', None, note='Requesting XSRF Token',
|
'app': {
|
||||||
# errnote='Could not get XSRF Token', query={
|
'type': 'browser',
|
||||||
# 'provider': 'site',
|
'name': 'Chrome'
|
||||||
# 'destination': 'https://www.vrt.be/vrtnu/',
|
},
|
||||||
# })
|
'device': 'undefined (undefined)',
|
||||||
# self._request_webpage(
|
'os': {
|
||||||
# 'https://login.vrt.be/perform_login', None,
|
'name': 'Windows',
|
||||||
# note='Performing login', errnote='Login failed',
|
'version': 'x86_64'
|
||||||
# query={'client_id': 'vrtnu-site'}, data=urlencode_postdata({
|
},
|
||||||
# 'UID': auth_info['UID'],
|
'player': {
|
||||||
# 'UIDSignature': auth_info['UIDSignature'],
|
'name': 'VRT web player',
|
||||||
# 'signatureTimestamp': auth_info['signatureTimestamp'],
|
'version': '3.2.6-prod-2023-09-11T12:37:41'
|
||||||
# '_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
|
# TODO: should move to _call_api()
|
||||||
# raise
|
|
||||||
|
player_info = {'exp': (round(time.time(), 3) + 900), **player_info_base}
|
||||||
|
player_info_jwt = jwt_encode_hs256(player_info, self._JWT_SIGNING_KEY, headers={
|
||||||
|
'kid': self._JWT_KEY_ID
|
||||||
|
}).decode()
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
**self.geo_verification_headers(),
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'identityToken': _id_token,
|
||||||
|
'playerInfo': player_info_jwt
|
||||||
|
}
|
||||||
|
|
||||||
|
json_response = self._download_json(
|
||||||
|
'https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v2/tokens',
|
||||||
|
None, 'Downloading player token', headers=headers, data=json.dumps(data).encode())
|
||||||
|
|
||||||
|
print("===================================")
|
||||||
|
print(json.dumps(json_response))
|
||||||
|
print("===================================")
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
self._authenticated = True
|
self._authenticated = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue