Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Jun 15, 2021
1 parent 21054d9 commit c911b8e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exclude_paths:
- "resources/skins/"
- "resources/settings.xml"
- "tests/"
- "packages/"
- "addon.xml"
- "changelog.txt"
- "Contributing.md"
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage:
comment: false
ignore:
- tests/
- packages/
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ setuptools
tox
xmlschema
Kodistubs==19.0.3
httpx
5 changes: 5 additions & 0 deletions resources/lib/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions resources/lib/services/nfsession/session/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand All @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions resources/lib/services/nfsession/session/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
20 changes: 13 additions & 7 deletions resources/lib/services/nfsession/session/http_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c911b8e

Please sign in to comment.