From b8c0a1550c9d79de37b7d6e5ca99ce0a3b404f96 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Sat, 11 Feb 2023 11:31:05 +0100 Subject: [PATCH] =?UTF-8?q?Client=20Id=20y=20secret=20correctos=20para=20c?= =?UTF-8?q?ada=20regi=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon.xml | 6 ++-- resources/lib/api.py | 35 ++++++++++++++++++--- resources/lib/exceptions/DialogException.py | 9 ++++++ 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 resources/lib/exceptions/DialogException.py diff --git a/addon.xml b/addon.xml index de69e2c..e15feb2 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -19,8 +19,8 @@ https://github.com/pablouser1/plugin.video.filmin http://github.com/pablouser1/plugin.video.filmin - v1.6.0 (10/02/2023) - Soporte inicial a Filmin Portugal y Filmin México + v1.6.1 (11/02/2023) + Client-Id y Client-Secret correctos resources/icon.png diff --git a/resources/lib/api.py b/resources/lib/api.py index 7a6cba5..91bed09 100644 --- a/resources/lib/api.py +++ b/resources/lib/api.py @@ -2,13 +2,32 @@ from xbmc import getLanguage, ISO_639_1 from .exceptions.ApiV3Exception import ApiV3Exception from .exceptions.UApiException import UApiException +from .exceptions.DialogException import DialogException class Api: s = requests.Session() - # Both extracted from the Android app - CLIENT_ID = "zXZXrpum7ayGcWlo" - CLIENT_SECRET = "yICstBCQ8CKB8RF6KuDmr9R20xtfyYbm" + # Taken from es.filmin.app.BuildConfig + TOKENS = { + # Spain + 'es': { + 'CLIENT_ID': 'zXZXrpum7ayGcWlo', + 'CLIENT_SECRET': 'yICstBCQ8CKB8RF6KuDmr9R20xtfyYbm' + }, + # Portugal + 'pt': { + 'CLIENT_ID': 'zhiv2IKILLYNZ3pq', + 'CLIENT_SECRET': 'kzPKMK2aXJzFoHNWOCR6gcd60WTK1BL3' + }, + # México + 'mx': { + 'CLIENT_ID': 'sse7QwjpcNoZgGZO', + 'CLIENT_SECRET': '2yqTm7thQLc2NQUQSbKehn7xrg1Pi59q' + } + } + + CLIENT_ID = "" + CLIENT_SECRET = "" DEVICE_MODEL = 'Kodi' DEVICE_OS_VERSION = '12' @@ -17,7 +36,6 @@ class Api: domain = 'es' def __init__(self, domain: str): - self.s.headers["X-Client-Id"] = self.CLIENT_ID self.s.headers["clientlanguage"] = getLanguage(ISO_639_1, True) self.s.headers["clientversion"] = self.CLIENT_VERSION @@ -30,6 +48,11 @@ def __init__(self, domain: str): self.s.headers['X-Device-OS-Version'] = self.DEVICE_OS_VERSION self.domain = domain + tokens = self.TOKENS[domain] + self.CLIENT_ID = tokens['CLIENT_ID'] + self.CLIENT_SECRET = tokens['CLIENT_SECRET'] + + self.s.headers["X-Client-Id"] = self.CLIENT_ID def getApiBaseUrl(self, useUapi: bool = False)-> str: # Extracted from Android app: es.filmin.app.injector.modules.RestApiUrlProviderEx @@ -40,6 +63,10 @@ def getApiBaseUrl(self, useUapi: bool = False)-> str: def makeRequest(self, endpoint: str, method = 'GET', body: dict = {}, query: dict = {}, useUapi: bool = False): base_url = self.getApiBaseUrl(useUapi) res = self.s.request(method, base_url + endpoint, json=body, params=query) + # Avoid non JSON response + if res.headers.get('Content-Type') != 'application/json': + raise DialogException('Non JSON response') + res_json = res.json() if res.ok: return res_json diff --git a/resources/lib/exceptions/DialogException.py b/resources/lib/exceptions/DialogException.py new file mode 100644 index 0000000..911e159 --- /dev/null +++ b/resources/lib/exceptions/DialogException.py @@ -0,0 +1,9 @@ +from xbmcgui import Dialog + +class DialogException(Exception): + """ + Generic exception using Dialogs + """ + def __init__(self, message: str): + super().__init__() + Dialog().ok('Error', message)