From 1608ed75e6be76814746108dfad67da04882e3bd Mon Sep 17 00:00:00 2001 From: remzouille Date: Fri, 3 Nov 2023 14:37:08 +0100 Subject: [PATCH] =?UTF-8?q?Modifications=20syntaxiques=20pour=20faire=20pl?= =?UTF-8?q?aisir=20=C3=A0=20pylint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/lib/provider_templates/orange.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/lib/provider_templates/orange.py b/resources/lib/provider_templates/orange.py index ea16050..b02c3e1 100644 --- a/resources/lib/provider_templates/orange.py +++ b/resources/lib/provider_templates/orange.py @@ -5,10 +5,10 @@ import json import os import re -import xbmcvfs from urllib.error import HTTPError from urllib.parse import urlparse, quote from urllib.request import Request, urlopen +import xbmcvfs from lib.providers.provider_interface import ProviderInterface from lib.utils import get_drm, get_global_setting, log, LogLevel, random_ua, get_addon_profile @@ -37,7 +37,7 @@ def _auth_urlopen(self, url: str, headers: dict = None) -> tuple: filepath = os.path.join(xbmcvfs.translatePath(get_addon_profile()), 'auth') try: - with open(filepath) as file: + with open(filepath, encoding='UTF-8') as file: auth = json.loads(file.read()) except FileNotFoundError: auth = {'timestamp': timestamp} @@ -54,9 +54,9 @@ def _auth_urlopen(self, url: str, headers: dict = None) -> tuple: return res.read(), auth['cookie'], auth['tv_token'] except HTTPError as error: if error.code in (401, 403): - log("cookie/token invalide, âge = %d" % (timestamp - auth['timestamp']), LogLevel.INFO) + log(f"cookie/token invalide, âge = {int(timestamp - auth['timestamp'])}", LogLevel.INFO) else: - log("erreur %s" % error, LogLevel.INFO) + log(f"erreur {error}", LogLevel.INFO) raise req = Request("https://chaines-tv.orange.fr", headers={ @@ -66,12 +66,14 @@ def _auth_urlopen(self, url: str, headers: dict = None) -> tuple: with urlopen(req) as res: cookie = res.headers['Set-Cookie'].split(";")[0] - tv_token = "Bearer %s" % re.sub('.*token:"', '', str(res.read()), 1) + tv_token = re.sub('.*token:"', 'Bearer ', str(res.read()), 1) tv_token = re.sub('",claims:.*', '', tv_token, 1) auth = {'timestamp': timestamp, 'cookie': cookie, 'tv_token': tv_token} - with open(filepath, 'w') as file: + with open(filepath, 'w', encoding='UTF-8') as file: file.write(json.dumps(auth)) + return None + def get_stream_info(self, channel_id: int) -> dict: res, cookie, tv_token = self._auth_urlopen(self.endpoint_stream_info.format(channel_id=channel_id), headers={ 'User-Agent': random_ua(), @@ -87,7 +89,7 @@ def get_stream_info(self, channel_id: int) -> dict: license_server_url = system.get('laUrl') headers = f'Content-Type=&User-Agent={random_ua()}&Host={urlparse(license_server_url).netloc}' - headers += '&Cookie=%s&tv_token=%s' % (quote(cookie), quote(tv_token)) + headers += f'&Cookie={quote(cookie)}&tv_token={quote(tv_token)}' post_data = 'R{SSM}' response = '' @@ -104,6 +106,7 @@ def get_stream_info(self, channel_id: int) -> dict: return stream_info def get_streams(self) -> list: + # pylint: disable=unreachable return [] res, _, _ = self._auth_urlopen(self.endpoint_streams, headers={