diff --git a/addon.xml b/addon.xml index 268ed53..ceb91a6 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 8f5988d..ac60730 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -429,6 +429,11 @@ msgctxt "#30207" msgid "No user token" msgstr "" +# For Movistar only +msgctxt "#30208" +msgid "Session expired" +msgstr "" + # For Orange and Movistar only msgctxt "#30300" msgid "IPTV Manager" diff --git a/resources/language/resource.language.es_es/strings.po b/resources/language/resource.language.es_es/strings.po index b3051c2..12fbc6b 100644 --- a/resources/language/resource.language.es_es/strings.po +++ b/resources/language/resource.language.es_es/strings.po @@ -405,6 +405,11 @@ msgctxt "#30207" msgid "No user token" msgstr "No hay token de usuario" +# For Movistar only +msgctxt "#30208" +msgid "Session expired" +msgstr "La sesión ha caducado" + msgctxt "#30300" msgid "IPTV Manager" msgstr "IPTV Manager" diff --git a/resources/lib/movistar.py b/resources/lib/movistar.py index 32a4e59..a5e09fe 100644 --- a/resources/lib/movistar.py +++ b/resources/lib/movistar.py @@ -39,6 +39,7 @@ class Movistar(object): def __init__(self, config_directory, reuse_devices=False): self.logged = False + self.expired_access_token = False # Network headers = { @@ -64,10 +65,24 @@ class Movistar(object): # Access token self.load_key_file() # Default access_token + if self.account['access_token']: + exp = self.get_token_expire_date(self.account['access_token']) + #LOG('auth.key: expiring date: {}'.format(exp)) + if exp < time.time(): + self.expired_access_token = True + self.account['access_token'] = None + content = self.cache.load_file('access_token.conf') if content: - self.account['access_token'] = content + exp = self.get_token_expire_date(content) + #LOG('access_token.conf: expiring date: {}'.format(exp)) + if exp < time.time(): + self.expired_access_token = True + else: + self.account['access_token'] = content #LOG('access_token: {}'.format(self.account['access_token'])) + LOG('expired_access_token: {}'.format(self.expired_access_token)) + if not self.account['access_token']: return # Account @@ -393,7 +408,9 @@ class Movistar(object): headers['Authorization'] = 'Bearer ' + self.account['access_token'] url = self.endpoints['renovacion_cdntoken2'].format(ACCOUNTNUMBER=self.account['id']) data = self.net.post_data(url, None, headers) - return data.get('access_token') + if isinstance(data, dict): + return data.get('access_token') + return '' def get_session_token(self): data = {"accountNumber": self.account['id'], @@ -1384,12 +1401,15 @@ class Movistar(object): def get_token_expire_date(self, token): from .b64 import decode_base64 - res = None - l = token.split('.') - if len(l) > 1: - padding = len(l[1]) % 4 - l[1] += '=' * (4 - padding) if padding != 0 else '' - s = decode_base64(l[1]) - data = json.loads(s) - res = data['exp'] + res = 0 + try: + l = token.split('.') + if len(l) > 1: + padding = len(l[1]) % 4 + l[1] += '=' * (4 - padding) if padding != 0 else '' + s = decode_base64(l[1]) + data = json.loads(s) + res = data['exp'] + except: + pass return res diff --git a/resources/lib/plugin.py b/resources/lib/plugin.py index fd72ce1..9f6329c 100644 --- a/resources/lib/plugin.py +++ b/resources/lib/plugin.py @@ -732,6 +732,8 @@ def router(paramstring): add_menu_option(addon.getLocalizedString(30112), get_url(action='search'), icon='search.png') # Search add_menu_option(addon.getLocalizedString(30180), get_url(action='profiles'), icon='profiles.png') # Profiles add_menu_option(addon.getLocalizedString(30108), get_url(action='devices'), icon='devices.png') # Devices + elif m.expired_access_token: + show_notification(addon.getLocalizedString(30208)) add_menu_option(addon.getLocalizedString(30160), get_url(action='user'), icon='account.png') # Accounts close_folder(cacheToDisc=False)