Skip to content

Commit 7986718

Browse files
committed
Attempt to provide sensible errors on network issues
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.)
1 parent d5c9692 commit 7986718

File tree

3 files changed

+90
-16
lines changed

3 files changed

+90
-16
lines changed

resources/language/resource.language.en_gb/strings.po

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,30 @@ msgctxt "#30967"
918918
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."
919919
msgstr ""
920920

921+
msgctxt "#30968"
922+
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}"
923+
msgstr ""
924+
925+
msgctxt "#30969"
926+
msgid "Unable to open URL"
927+
msgstr ""
928+
929+
msgctxt "#30971"
930+
msgid "Install Widevine using 'InputStream Helper' add-on"
931+
msgstr ""
932+
933+
msgctxt "#30972"
934+
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."
935+
msgstr ""
936+
937+
msgctxt "#30973"
938+
msgid "Installation of Widevine failed!"
939+
msgstr ""
940+
941+
msgctxt "#30974"
942+
msgid "Installation of Widevine completed!"
943+
msgstr ""
944+
921945
msgctxt "#30975"
922946
msgid "Failed to get user token from VRT NU"
923947
msgstr ""

resources/language/resource.language.nl_nl/strings.po

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,30 @@ msgctxt "#30967"
918918
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."
919919
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."
920920

921+
msgctxt "#30968"
922+
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}"
923+
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}"
924+
925+
msgctxt "#30969"
926+
msgid "Unable to open URL"
927+
msgstr "Probleem bij het openen van een URL"
928+
929+
msgctxt "#30971"
930+
msgid "Install Widevine using 'InputStream Helper' add-on"
931+
msgstr "Installeer Widevine met de 'InputStream Helper' add-on"
932+
933+
msgctxt "#30972"
934+
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."
935+
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."
936+
937+
msgctxt "#30973"
938+
msgid "Installation of Widevine failed!"
939+
msgstr "Widevine installatie mislukt!"
940+
941+
msgctxt "#30974"
942+
msgid "Installation of Widevine completed!"
943+
msgstr "Widevine installatie gelukt"
944+
921945
msgctxt "#30975"
922946
msgid "Failed to get user token from VRT NU"
923947
msgstr "Ophalen van het gebruikerstoken van VRT NU is mislukt"

resources/lib/tokenresolver.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
try: # Python 3
1313
import http.cookiejar as cookielib
14-
from urllib.parse import urlencode, unquote
15-
from urllib.request import build_opener, install_opener, ProxyHandler, HTTPCookieProcessor, HTTPErrorProcessor, urlopen, Request
14+
from urllib.error import URLError
15+
from urllib.parse import unquote, urlencode
16+
from urllib.request import HTTPCookieProcessor, HTTPErrorProcessor, ProxyHandler, Request, build_opener, install_opener, urlopen
1617
except ImportError: # Python 2
1718
from urllib import urlencode
18-
from urllib2 import build_opener, install_opener, ProxyHandler, HTTPCookieProcessor, HTTPErrorProcessor, unquote, urlopen, Request
19+
from urllib2 import HTTPCookieProcessor, HTTPErrorProcessor, ProxyHandler, Request, URLError, build_opener, install_opener, unquote, urlopen
1920
import cookielib
2021

2122

@@ -234,9 +235,17 @@ def _get_new_user_xvrttoken(self):
234235
cookiejar = cookielib.CookieJar()
235236
opener = build_opener(HTTPCookieProcessor(cookiejar), ProxyHandler(self._proxies))
236237
log(2, 'URL get: {url}', url=unquote(self._USER_TOKEN_GATEWAY_URL))
237-
opener.open(self._USER_TOKEN_GATEWAY_URL)
238+
try:
239+
opener.open(self._USER_TOKEN_GATEWAY_URL)
240+
except URLError as exc:
241+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=unquote(self._USER_TOKEN_GATEWAY_URL)))
242+
raise
238243
log(2, 'URL post: {url}', url=unquote(self._VRT_LOGIN_URL))
239-
opener.open(self._VRT_LOGIN_URL, data=data)
244+
try:
245+
opener.open(self._VRT_LOGIN_URL, data=data)
246+
except URLError as exc:
247+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=unquote(self._VRT_LOGIN_URL)))
248+
raise
240249
xvrttoken = TokenResolver._create_token_dictionary(cookiejar)
241250
refreshtoken = TokenResolver._create_token_dictionary(cookiejar, cookie_name='vrtlogin-rt')
242251
if xvrttoken is None:
@@ -256,7 +265,11 @@ def _get_fresh_token(self, refresh_token, token_name, token_variant=None):
256265
opener = build_opener(HTTPCookieProcessor(cookiejar), ProxyHandler(self._proxies))
257266
log(2, 'URL get: {url}', url=refresh_url)
258267
req = Request(refresh_url, headers=headers)
259-
opener.open(req)
268+
try:
269+
opener.open(req)
270+
except URLError as exc:
271+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
272+
raise
260273
token = TokenResolver._create_token_dictionary(cookiejar, token_name)
261274
if token is None:
262275
return None
@@ -270,7 +283,11 @@ def _get_roaming_xvrttoken(self, xvrttoken):
270283
opener = build_opener(NoRedirection, ProxyHandler(self._proxies))
271284
log(2, 'URL get: {url}', url=unquote(self._ROAMING_TOKEN_GATEWAY_URL))
272285
req = Request(self._ROAMING_TOKEN_GATEWAY_URL, headers=headers)
273-
req_info = opener.open(req).info()
286+
try:
287+
req_info = opener.open(req).info()
288+
except URLError as exc:
289+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
290+
raise
274291
try: # Python 3
275292
cookie_value += '; state=' + req_info.get('Set-Cookie').split('state=')[1].split('; ')[0]
276293
except AttributeError: # Python 2
@@ -279,20 +296,29 @@ def _get_roaming_xvrttoken(self, xvrttoken):
279296
else:
280297
url = req_info.get('Location')
281298
log(2, 'URL get: {url}', url=unquote(url))
282-
try: # Python 3
283-
url = opener.open(url).info().get('Location')
284-
except AttributeError: # Python 2
285-
url = opener.open(url).info().getheader('Location')
286-
headers = {'Cookie': cookie_value}
299+
try:
300+
try: # Python 3
301+
url = opener.open(url).info().get('Location')
302+
except AttributeError: # Python 2
303+
url = opener.open(url).info().getheader('Location')
304+
except URLError as exc:
305+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=url))
306+
raise
307+
287308
if url is None:
288309
return None
289310

311+
headers = {'Cookie': cookie_value}
290312
log(2, 'URL get: {url}', url=unquote(url))
291313
req = Request(url, headers=headers)
292-
try: # Python 3
293-
setcookie_header = opener.open(req).info().get('Set-Cookie')
294-
except AttributeError: # Python 2
295-
setcookie_header = opener.open(req).info().getheader('Set-Cookie')
314+
try:
315+
try: # Python 3
316+
setcookie_header = opener.open(req).info().get('Set-Cookie')
317+
except AttributeError: # Python 2
318+
setcookie_header = opener.open(req).info().getheader('Set-Cookie')
319+
except URLError as exc:
320+
ok_dialog(heading=localize(30963), message=localize(30964, error=exc, url=req.full_url))
321+
raise
296322
return TokenResolver._create_token_dictionary(setcookie_header)
297323

298324
@staticmethod

0 commit comments

Comments
 (0)