diff --git a/.codeclimate.yml b/.codeclimate.yml index 8eec6c427b..d89f248149 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -27,6 +27,7 @@ exclude_paths: - "resources/skins/" - "resources/settings.xml" - "tests/" + - "packages/" - "addon.xml" - "changelog.txt" - "Contributing.md" diff --git a/codecov.yml b/codecov.yml index 04f82dff07..a6cb929402 100644 --- a/codecov.yml +++ b/codecov.yml @@ -10,3 +10,4 @@ coverage: comment: false ignore: - tests/ +- packages/ diff --git a/requirements.txt b/requirements.txt index 713305dad9..2425142b13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ setuptools tox xmlschema Kodistubs==19.0.3 +httpx diff --git a/resources/lib/globals.py b/resources/lib/globals.py index a22bb70948..ce6408af57 100644 --- a/resources/lib/globals.py +++ b/resources/lib/globals.py @@ -13,6 +13,7 @@ # All other modules (imports) are initialized only on the first invocation of the add-on. import collections import os +import sys from urllib.parse import parse_qsl, unquote, urlparse import xbmcaddon @@ -230,6 +231,7 @@ def init_globals(self, argv): self.DEFAULT_FANART = self.ADDON.getAddonInfo('fanart') self.ADDON_DATA_PATH = self.ADDON.getAddonInfo('path') # Add-on folder self.DATA_PATH = self.ADDON.getAddonInfo('profile') # Add-on user data folder + self.ADDON_PACKAGES_PATH = os.path.join(self.ADDON_DATA_PATH, 'packages') self.CACHE_PATH = os.path.join(self.DATA_PATH, 'cache') self.COOKIES_PATH = os.path.join(self.DATA_PATH, 'COOKIES') try: @@ -247,6 +249,9 @@ def init_globals(self, argv): LOG.initialize(self.ADDON_ID, self.PLUGIN_HANDLE, self.ADDON.getSettingBool('enable_debug'), self.ADDON.getSettingBool('enable_timing')) + # Add path of embedded packages (not supplied by Kodi) to python system directory + if self.ADDON_PACKAGES_PATH not in sys.path: + sys.path.insert(0, self.ADDON_PACKAGES_PATH) if self.IS_ADDON_FIRSTRUN: self.init_database() # Initialize the cache diff --git a/resources/lib/services/nfsession/session/base.py b/resources/lib/services/nfsession/session/base.py index 8293a19bf4..95a0923256 100644 --- a/resources/lib/services/nfsession/session/base.py +++ b/resources/lib/services/nfsession/session/base.py @@ -11,7 +11,7 @@ import resources.lib.common as common from resources.lib.database.db_utils import TABLE_SESSION from resources.lib.globals import G -from resources.lib.services.tcp_keep_alive import enable_tcp_keep_alive +# from resources.lib.services.tcp_keep_alive import enable_tcp_keep_alive from resources.lib.utils.logging import LOG @@ -21,9 +21,6 @@ class SessionBase: session = None """The requests.session object to handle communication to Netflix""" - verify_ssl = True - """Use SSL verification when performing requests""" - # Functions from derived classes to allow perform particular operations in parent classes external_func_activate_profile = None # (set by nfsession_op.py) @@ -37,9 +34,9 @@ def _init_session(self): LOG.info('Session closed') except AttributeError: pass - from requests import Session - self.session = Session() - enable_tcp_keep_alive(self.session) + import httpx + self.session = httpx.Client(http2=True) + # enable_tcp_keep_alive(self.session) self.session.max_redirects = 10 # Too much redirects should means some problem self.session.headers.update({ 'User-Agent': common.get_user_agent(enable_android_mediaflag_fix=True), diff --git a/resources/lib/services/nfsession/session/cookie.py b/resources/lib/services/nfsession/session/cookie.py index 9b0c5d2360..92a1cdb26f 100644 --- a/resources/lib/services/nfsession/session/cookie.py +++ b/resources/lib/services/nfsession/session/cookie.py @@ -46,8 +46,9 @@ def _verify_session_cookies(self): LOG.error('The cookie "{}" do not exist, it is not possible to check the expiration', cookie_name) return False - for cookie in list(self.session.cookies): - if cookie.name != cookie_name: + for cookie in self.session.cookies.items(): + # TODO to check if 'cookie' name comparison works and also expires property + if cookie != cookie_name: continue if cookie.expires <= int(time.time()): LOG.info('Login is expired') diff --git a/resources/lib/services/nfsession/session/http_requests.py b/resources/lib/services/nfsession/session/http_requests.py index daedd4b193..426537a3e9 100644 --- a/resources/lib/services/nfsession/session/http_requests.py +++ b/resources/lib/services/nfsession/session/http_requests.py @@ -59,13 +59,19 @@ def _request(self, method, endpoint, session_refreshed, **kwargs): LOG.debug('Executing {verb} request to {url}', verb='GET' if method == self.session.get else 'POST', url=url) start = time.perf_counter() - response = method( - url=url, - verify=self.verify_ssl, - headers=headers, - params=params, - data=data, - timeout=8) + if method == self.session.get: + response = method( + url=url, + headers=headers, + params=params, + timeout=8) + else: + response = method( + url=url, + headers=headers, + params=params, + data=data, + timeout=8) LOG.debug('Request took {}s', time.perf_counter() - start) LOG.debug('Request returned status code {}', response.status_code) break