Skip to content

Commit

Permalink
Attempt to provide sensible errors on network issues
Browse files Browse the repository at this point in the history
Currently the add-on works fine if all is well, however various things
can go wrong which makes the add-on bail out with no proper error.

And since the cause of network errors could be anywhere, we do not want
the end-user to have to dig deep into Kodi logs to find probable
suspects.

So we do want to return the exact error message (i.e. Connection
refused, No route to host, etc.) so the user can relate it to other
possible problems. (WIFI issues, Internet down or unreliable, etc.)
  • Loading branch information
dagwieers committed Mar 27, 2020
1 parent d5c9692 commit 7986718
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 16 deletions.
24 changes: 24 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,30 @@ msgctxt "#30967"
msgid "Could not retrieve this program list. VRT Search API url is too long. Unfollowing some favorite programs will reduce url length and may fix this problem."
msgstr ""

msgctxt "#30968"
msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU.\n\nError: {error}\nURL: {url}"
msgstr ""

msgctxt "#30969"
msgid "Unable to open URL"
msgstr ""

msgctxt "#30971"
msgid "Install Widevine using 'InputStream Helper' add-on"
msgstr ""

msgctxt "#30972"
msgid "Installing Widevine libraries using the 'InputStream Helper' add-on is done at your own risk and the VRT NU add-on is not responsible for any results. Nor is it guaranteed that Widevine will be (re)installed correctly."
msgstr ""

msgctxt "#30973"
msgid "Installation of Widevine failed!"
msgstr ""

msgctxt "#30974"
msgid "Installation of Widevine completed!"
msgstr ""

msgctxt "#30975"
msgid "Failed to get user token from VRT NU"
msgstr ""
Expand Down
24 changes: 24 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,30 @@ msgctxt "#30967"
msgid "Could not retrieve this program list. VRT Search API url is too long. Unfollowing some favorite programs will reduce url length and may fix this problem."
msgstr "Deze programmalijst kan niet opgehaald worden. VRT Search API url is te lang. Enkele favoriete programma's vergeten zal de lengte van de URL verminderen en dit probleem mogelijk oplossen."

msgctxt "#30968"
msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU.\n\nError: {error}\nURL: {url}"
msgstr "Er is een fout opgetreden met het Internet gebruik. Dit kan liggen aan Kodi, aan jouw netwerk, aan jouw ISP of aan VRT NU.\n\nFout: {error}\nURL: {url}"

msgctxt "#30969"
msgid "Unable to open URL"
msgstr "Probleem bij het openen van een URL"

msgctxt "#30971"
msgid "Install Widevine using 'InputStream Helper' add-on"
msgstr "Installeer Widevine met de 'InputStream Helper' add-on"

msgctxt "#30972"
msgid "Installing Widevine libraries using the 'InputStream Helper' add-on is done at your own risk and the VRT NU add-on is not responsible for any results. Nor is it guaranteed that Widevine will be (re)installed correctly."
msgstr "Het installeren van de Widevine bestanden met de 'InputStream Helper' add-on is op eigen risico en de VRT NU add-on is niet verantwoordelijk voor enig resultaat. Ook wordt het niet gegarandeerd dat Widevine succesvol kan worden geinstalleerd."

msgctxt "#30973"
msgid "Installation of Widevine failed!"
msgstr "Widevine installatie mislukt!"

msgctxt "#30974"
msgid "Installation of Widevine completed!"
msgstr "Widevine installatie gelukt"

msgctxt "#30975"
msgid "Failed to get user token from VRT NU"
msgstr "Ophalen van het gebruikerstoken van VRT NU is mislukt"
Expand Down
58 changes: 42 additions & 16 deletions resources/lib/tokenresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

try: # Python 3
import http.cookiejar as cookielib
from urllib.parse import urlencode, unquote
from urllib.request import build_opener, install_opener, ProxyHandler, HTTPCookieProcessor, HTTPErrorProcessor, urlopen, Request
from urllib.error import URLError
from urllib.parse import unquote, urlencode
from urllib.request import HTTPCookieProcessor, HTTPErrorProcessor, ProxyHandler, Request, build_opener, install_opener, urlopen
except ImportError: # Python 2
from urllib import urlencode
from urllib2 import build_opener, install_opener, ProxyHandler, HTTPCookieProcessor, HTTPErrorProcessor, unquote, urlopen, Request
from urllib2 import HTTPCookieProcessor, HTTPErrorProcessor, ProxyHandler, Request, URLError, build_opener, install_opener, unquote, urlopen
import cookielib


Expand Down Expand Up @@ -234,9 +235,17 @@ def _get_new_user_xvrttoken(self):
cookiejar = cookielib.CookieJar()
opener = build_opener(HTTPCookieProcessor(cookiejar), ProxyHandler(self._proxies))
log(2, 'URL get: {url}', url=unquote(self._USER_TOKEN_GATEWAY_URL))
opener.open(self._USER_TOKEN_GATEWAY_URL)
try:
opener.open(self._USER_TOKEN_GATEWAY_URL)
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=unquote(self._USER_TOKEN_GATEWAY_URL)))
raise
log(2, 'URL post: {url}', url=unquote(self._VRT_LOGIN_URL))
opener.open(self._VRT_LOGIN_URL, data=data)
try:
opener.open(self._VRT_LOGIN_URL, data=data)
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=unquote(self._VRT_LOGIN_URL)))
raise
xvrttoken = TokenResolver._create_token_dictionary(cookiejar)
refreshtoken = TokenResolver._create_token_dictionary(cookiejar, cookie_name='vrtlogin-rt')
if xvrttoken is None:
Expand All @@ -256,7 +265,11 @@ def _get_fresh_token(self, refresh_token, token_name, token_variant=None):
opener = build_opener(HTTPCookieProcessor(cookiejar), ProxyHandler(self._proxies))
log(2, 'URL get: {url}', url=refresh_url)
req = Request(refresh_url, headers=headers)
opener.open(req)
try:
opener.open(req)
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
raise
token = TokenResolver._create_token_dictionary(cookiejar, token_name)
if token is None:
return None
Expand All @@ -270,7 +283,11 @@ def _get_roaming_xvrttoken(self, xvrttoken):
opener = build_opener(NoRedirection, ProxyHandler(self._proxies))
log(2, 'URL get: {url}', url=unquote(self._ROAMING_TOKEN_GATEWAY_URL))
req = Request(self._ROAMING_TOKEN_GATEWAY_URL, headers=headers)
req_info = opener.open(req).info()
try:
req_info = opener.open(req).info()
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
raise
try: # Python 3
cookie_value += '; state=' + req_info.get('Set-Cookie').split('state=')[1].split('; ')[0]
except AttributeError: # Python 2
Expand All @@ -279,20 +296,29 @@ def _get_roaming_xvrttoken(self, xvrttoken):
else:
url = req_info.get('Location')
log(2, 'URL get: {url}', url=unquote(url))
try: # Python 3
url = opener.open(url).info().get('Location')
except AttributeError: # Python 2
url = opener.open(url).info().getheader('Location')
headers = {'Cookie': cookie_value}
try:
try: # Python 3
url = opener.open(url).info().get('Location')
except AttributeError: # Python 2
url = opener.open(url).info().getheader('Location')
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=url))
raise

if url is None:
return None

headers = {'Cookie': cookie_value}
log(2, 'URL get: {url}', url=unquote(url))
req = Request(url, headers=headers)
try: # Python 3
setcookie_header = opener.open(req).info().get('Set-Cookie')
except AttributeError: # Python 2
setcookie_header = opener.open(req).info().getheader('Set-Cookie')
try:
try: # Python 3
setcookie_header = opener.open(req).info().get('Set-Cookie')
except AttributeError: # Python 2
setcookie_header = opener.open(req).info().getheader('Set-Cookie')
except URLError as exc:
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
raise
return TokenResolver._create_token_dictionary(setcookie_header)

@staticmethod
Expand Down

0 comments on commit 7986718

Please sign in to comment.