From fe2f12b714228c461ba6a50b006501ba56457628 Mon Sep 17 00:00:00 2001 From: Paco8 <5084042+Paco8@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:04:36 +0100 Subject: [PATCH] Version 0.9.15 --- addon.xml | 2 +- .../resource.language.en_gb/strings.po | 16 +++++++ .../resource.language.es_es/strings.po | 16 +++++++ resources/lib/movistar.py | 46 +++++++++++++------ resources/lib/plugin.py | 25 ++++++++-- resources/lib/proxy.py | 4 +- 6 files changed, 87 insertions(+), 22 deletions(-) diff --git a/addon.xml b/addon.xml index 55afbe1..41d61dc 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 576e7f7..4647b9d 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -422,6 +422,22 @@ msgctxt "#30192" msgid "Use a {} account" msgstr "" +msgctxt "#30193" +msgid "Select the credentials file" +msgstr "" + +msgctxt "#30194" +msgid "Select a folder to save the credentials file" +msgstr "" + +msgctxt "#30195" +msgid "Export credentials" +msgstr "" + +msgctxt "#30196" +msgid "Import credentials" +msgstr "" + msgctxt "#30200" msgid "Error" msgstr "" diff --git a/resources/language/resource.language.es_es/strings.po b/resources/language/resource.language.es_es/strings.po index b7ab4fc..968b474 100644 --- a/resources/language/resource.language.es_es/strings.po +++ b/resources/language/resource.language.es_es/strings.po @@ -399,6 +399,22 @@ msgctxt "#30192" msgid "Use a {} account" msgstr "Usar una cuenta de {}" +msgctxt "#30193" +msgid "Select the credentials file" +msgstr "Selecciona el fichero de credenciales" + +msgctxt "#30194" +msgid "Select a folder to save the credentials file" +msgstr "Seleccion una carpeta donde guardar las credenciales" + +msgctxt "#30195" +msgid "Export credentials" +msgstr "Exportar credenciales" + +msgctxt "#30196" +msgid "Import credentials" +msgstr "Importar credenciales" + msgctxt "#30200" msgid "Error" msgstr "Error" diff --git a/resources/lib/movistar.py b/resources/lib/movistar.py index b8d620c..994508f 100644 --- a/resources/lib/movistar.py +++ b/resources/lib/movistar.py @@ -116,7 +116,7 @@ def __init__(self, config_directory, reuse_devices=False): if content: data = json.loads(content) if not data or 'ofertas' not in data: - data = self.authenticate() + data = self.get_account_info() if not data or 'ofertas' not in data: return self.cache.save_file('account.json', json.dumps(data, ensure_ascii=False)) self.account['id'] = data['ofertas'][0]['accountNumber'] @@ -139,7 +139,7 @@ def __init__(self, config_directory, reuse_devices=False): if not reuse_devices: LOG('not reusing devices') if not self.account['device_id']: - self.account['device_id'] = self.new_device_id() + self.account['device_id'] = self.request_device_id() self.cache.save_file('device_id.conf', self.account['device_id']) else: LOG('reusing devices') @@ -159,7 +159,7 @@ def __init__(self, config_directory, reuse_devices=False): self.account['device_id'] = wp_device else: LOG('device not found, registering new device') - self.account['device_id'] = self.new_device_id() + self.account['device_id'] = self.request_device_id() self.cache.save_file('device_id.conf', self.account['device_id']) LOG('device_id: {}'. format(self.account['device_id'])) @@ -293,7 +293,7 @@ def login(self, username, password): pass return success, content - def authenticate(self): + def get_account_info(self): headers = self.net.headers.copy() headers['Content-Type'] = 'application/x-www-form-urlencoded' #headers['x-movistarplus-deviceid'] = self.account['device_id'] @@ -302,9 +302,9 @@ def authenticate(self): headers['Authorization'] = 'Bearer ' + self.account['access_token'] url = self.endpoints['autenticacion_tk'].format(deviceType=self.dplayer) + '?_=' + str(int(time.time()*1000)) #LOG(url) - #LOG('authenticate: headers: {}'.format(headers)) + #LOG('get_account_info: headers: {}'.format(headers)) data = self.net.load_data(url, headers) - #LOG('authenticate: data: {}'.format(data)) + #LOG('get_account_info: data: {}'.format(data)) return data def change_device(self, id): @@ -348,7 +348,7 @@ def register_device(self): def unregister_device(self): return self.delete_device(self.account['device_id']) - def new_device_id(self): + def request_device_id(self): headers = self.net.headers.copy() headers['Content-Type'] = 'application/json' #headers['x-movistarplus-ui'] = '2.36.30' @@ -361,10 +361,11 @@ def new_device_id(self): content = response.content.decode('utf-8') return content.strip('"') - #import random - #s = '' - #for _ in range(0, 32): s += random.choice('abcdef0123456789') - #return s + #def generate_device_id(self): + # import random + # s = '' + # for _ in range(0, 32): s += random.choice('abcdef0123456789') + # return s def delete_device(self, device_id): headers = self.net.headers.copy() @@ -1281,6 +1282,16 @@ def save_key_file(self, d): data = {'timestamp': int(time.time()*1000), 'response': d} self.cache.save_file('auth.key', json.dumps(data, ensure_ascii=False)) + def import_credentials(self, filename): + if sys.version_info[0] > 2: + filename = bytes(filename, 'utf-8') + shutil.copyfile(filename, self.cache.config_directory + 'credentials.json') + + def export_credentials(self, filename): + if sys.version_info[0] > 2: + filename = bytes(filename, 'utf-8') + shutil.copyfile(self.cache.config_directory + 'credentials.json', filename) + def delete_session_files(self): for f in ['access_token.conf', 'account.json', 'device_id.conf', 'devices.json', 'profile_id.conf', 'tokens.json', 'channels2.json', 'channels_UHD.json', 'channels_HD.json', 'epg2.json', 'epg_UHD.json', 'epg_HD.json']: self.cache.remove_file(f) @@ -1464,9 +1475,11 @@ def load_credentials(self): else: return '', '' - def get_token_expire_date(self, token): + def get_token_properties(self, token=None): from .b64 import decode_base64 - res = 0 + if not token: + token = self.account['access_token'] + data = None try: l = token.split('.') if len(l) > 1: @@ -1474,10 +1487,13 @@ def get_token_expire_date(self, token): l[1] += '=' * (4 - padding) if padding != 0 else '' s = decode_base64(l[1]) data = json.loads(s) - res = data['exp'] except: pass - return res + return data + + def get_token_expire_date(self, token): + data = self.get_token_properties(token) + return data.get('exp', 0) def get_accounts(self): accounts = [] diff --git a/resources/lib/plugin.py b/resources/lib/plugin.py index e09dfd0..ad609d7 100644 --- a/resources/lib/plugin.py +++ b/resources/lib/plugin.py @@ -221,9 +221,9 @@ def play(params): subpaths.append(filename_srt) play_item.setSubtitles(subpaths) - if True: - m.unregister_device() - m.register_device() + #if True: + # m.unregister_device() + # m.register_device() xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item) @@ -647,6 +647,16 @@ def export_key(): if directory: m.export_key_file(directory + 'movistarplus.key') +def import_credentials(): + filename = xbmcgui.Dialog().browseSingle(1, addon.getLocalizedString(30193), '', '.json') + if filename: + m.import_credentials(filename) + +def export_credentials(): + directory = xbmcgui.Dialog().browseSingle(0, addon.getLocalizedString(30194), '') + if directory: + m.export_credentials(os.path.join(directory, 'credenciales.json')) + def select_account(id, name): m.switch_account(id) open_folder(name) @@ -656,7 +666,10 @@ def select_account(id, name): if os.path.exists(os.path.join(m.cache.config_directory, 'auth.key')): add_menu_option(addon.getLocalizedString(30184), get_url(action='export_key')) # Export key add_menu_option(addon.getLocalizedString(30150), get_url(action='logout')) # Close session - close_folder() + add_menu_option(addon.getLocalizedString(30196), get_url(action='import_credentials')) + if os.path.exists(os.path.join(m.cache.config_directory, 'credentials.json')): + add_menu_option(addon.getLocalizedString(30195), get_url(action='export_credentials')) + close_folder(cacheToDisc=False) def list_accounts(params): LOG('list_accounts: {}'.format(params)) @@ -779,6 +792,10 @@ def router(paramstring): login() elif params['action'] == 'export_key': export_key() + elif params['action'] == 'export_credentials': + export_credentials() + elif params['action'] == 'import_credentials': + import_credentials() elif params['action'] == 'select_account': select_account(params['id'], params['name']) elif params['action'] == 'accounts': diff --git a/resources/lib/proxy.py b/resources/lib/proxy.py index 90ab2b7..5213619 100644 --- a/resources/lib/proxy.py +++ b/resources/lib/proxy.py @@ -217,12 +217,12 @@ def do_POST(self): LOG('license response: {}'.format(license_data)) d = try_load_json(license_data) if d and 'errorCode' in d: + from .gui import show_notification + show_notification('Error {}: {}'.format(d['errorCode'], d['message'])) if d['errorCode'] == 4027: if not reregister_needed and addon.getSettingBool('reregister'): reregister_needed = True continue - from .gui import show_notification - show_notification('Error {}: {}'.format(d['errorCode'], d['message'])) else: LOG('license response: {}'.format(encode_base64(license_data))) break