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)