Skip to content

Commit

Permalink
added new xvrttoken to support video-user-data.vrt.be
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed May 14, 2019
1 parent 2f31d8b commit 6463b66
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions resources/lib/vrtplayer/tokenresolver.py
Expand Up @@ -7,10 +7,10 @@

try:
from urllib.parse import urlencode, unquote
from urllib.request import build_opener, install_opener, ProxyHandler, HTTPErrorProcessor, urlopen, Request
from urllib.request import build_opener, install_opener, ProxyHandler, HTTPErrorProcessor, HTTPCookieProcessor, urlopen, Request
except ImportError:
from urllib import urlencode # pylint: disable=ungrouped-imports
from urllib2 import build_opener, install_opener, ProxyHandler, HTTPErrorProcessor, unquote, urlopen, Request
from urllib2 import build_opener, install_opener, ProxyHandler, HTTPErrorProcessor, HTTPCookieProcessor, unquote, urlopen, Request


class NoRedirection(HTTPErrorProcessor):
Expand All @@ -25,7 +25,8 @@ class TokenResolver:

_API_KEY = '3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG'
_LOGIN_URL = 'https://accounts.vrt.be/accounts.login'
_TOKEN_GATEWAY_URL = 'https://token.vrt.be'
_VRT_LOGIN_URL = 'https://login.vrt.be/perform_login'
_TOKEN_GATEWAY_URL = 'https://token.vrt.be/vrtnuinitlogin?provider=site&destination=https://www.vrt.be/vrtnu/'
_ONDEMAND_COOKIE = 'ondemand_vrtPlayerToken'
_LIVE_COOKIE = 'live_vrtPlayerToken'
_ROAMING_XVRTTOKEN_COOKIE = 'roaming_XVRTToken'
Expand Down Expand Up @@ -104,6 +105,7 @@ def _get_cached_token(self, path, token_name):

def _get_new_xvrttoken(self, path, get_roaming_token):
import json
import cookielib
cred = helperobjects.Credentials(self._kodiwrapper)
if not cred.are_filled_in():
self._kodiwrapper.open_settings()
Expand All @@ -120,19 +122,20 @@ def _get_new_xvrttoken(self, path, get_roaming_token):
logon_json = json.loads(urlopen(req).read())
token = None
if logon_json.get('errorCode') == 0:
login_token = logon_json.get('sessionInfo', dict()).get('login_token')
login_cookie = 'glt_%s=%s' % (self._API_KEY, login_token)
payload = dict(
uid=logon_json.get('UID'),
uidsig=logon_json.get('UIDSignature'),
ts=logon_json.get('signatureTimestamp'),
email=cred.username,
UID=logon_json.get('UID'),
UIDSignature=logon_json.get('UIDSignature'),
signatureTimestamp=logon_json.get('signatureTimestamp'),
client_id='vrtnu-site',
submit='submit',
)
headers = {'Content-Type': 'application/json', 'Cookie': login_cookie}
cookiejar = cookielib.CookieJar()
opener = build_opener(HTTPCookieProcessor(cookiejar))
self._kodiwrapper.log_notice('URL get: ' + unquote(self._TOKEN_GATEWAY_URL), 'Verbose')
opener.open(self._TOKEN_GATEWAY_URL)
self._kodiwrapper.log_notice('URL post: ' + unquote(self._TOKEN_GATEWAY_URL), 'Verbose')
req = Request(self._TOKEN_GATEWAY_URL, data=json.dumps(payload), headers=headers)
cookie_data = urlopen(req).info().getheader('Set-Cookie').split('X-VRT-Token=')[1].split('; ')
xvrttoken = TokenResolver._create_token_dictionary_from_urllib(cookie_data)
opener.open(self._VRT_LOGIN_URL, data=urlencode(payload))
xvrttoken = TokenResolver._create_token_dictionary(cookiejar)
if get_roaming_token:
xvrttoken = self._get_roaming_xvrttoken(xvrttoken)
if xvrttoken is not None:
Expand Down

0 comments on commit 6463b66

Please sign in to comment.