mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Try to fix import strptime bug
Clean up of downloadutils and utils.
This commit is contained in:
parent
06d71cf00d
commit
da7685b03f
2 changed files with 34 additions and 45 deletions
|
@ -11,7 +11,6 @@ import xbmcgui
|
|||
|
||||
import clientinfo
|
||||
from utils import Logging, window, settings
|
||||
import utils
|
||||
|
||||
##################################################################################################
|
||||
|
||||
|
@ -29,11 +28,10 @@ class DownloadUtils():
|
|||
# Borg - multiple instances, shared state
|
||||
_shared_state = {}
|
||||
clientInfo = clientinfo.ClientInfo()
|
||||
addonName = clientInfo.getAddonName()
|
||||
|
||||
# Requests session
|
||||
s = None
|
||||
timeout = 30
|
||||
default_timeout = 30
|
||||
|
||||
|
||||
def __init__(self):
|
||||
|
@ -182,7 +180,19 @@ class DownloadUtils():
|
|||
deviceId = self.clientInfo.getDeviceId()
|
||||
version = self.clientInfo.getVersion()
|
||||
|
||||
if not authenticate:
|
||||
if authenticate:
|
||||
auth = (
|
||||
'MediaBrowser UserId="%s", Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
||||
% (self.userId, deviceName, deviceId, version))
|
||||
header = {
|
||||
|
||||
'Content-type': 'application/json',
|
||||
'Accept-encoding': 'gzip',
|
||||
'Accept-Charset': 'UTF-8,*',
|
||||
'Authorization': auth,
|
||||
'X-MediaBrowser-Token': self.token
|
||||
}
|
||||
else:
|
||||
# If user is not authenticated
|
||||
auth = (
|
||||
'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
||||
|
@ -194,21 +204,6 @@ class DownloadUtils():
|
|||
'Accept-Charset': 'UTF-8,*',
|
||||
'Authorization': auth
|
||||
}
|
||||
else:
|
||||
userId = self.userId
|
||||
token = self.token
|
||||
# Attached to the requests session
|
||||
auth = (
|
||||
'MediaBrowser UserId="%s", Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
||||
% (userId, deviceName, deviceId, version))
|
||||
header = {
|
||||
|
||||
'Content-type': 'application/json',
|
||||
'Accept-encoding': 'gzip',
|
||||
'Accept-Charset': 'UTF-8,*',
|
||||
'Authorization': auth,
|
||||
'X-MediaBrowser-Token': token
|
||||
}
|
||||
|
||||
return header
|
||||
|
||||
|
@ -266,14 +261,14 @@ class DownloadUtils():
|
|||
##### PREPARE REQUEST #####
|
||||
kwargs.update({
|
||||
'url': url,
|
||||
'timeout': self.timeout,
|
||||
'timeout': self.default_timeout,
|
||||
'json': postBody,
|
||||
'params': parameters
|
||||
})
|
||||
|
||||
##### THE RESPONSE #####
|
||||
log(kwargs, 2)
|
||||
r = self.__requests(action_type, session, **kwargs)
|
||||
r = self._requests(action_type, session, **kwargs)
|
||||
|
||||
if r.status_code == 204:
|
||||
# No body in the response
|
||||
|
@ -358,7 +353,7 @@ class DownloadUtils():
|
|||
|
||||
return default_link
|
||||
|
||||
def __requests(self, action, session=requests, **kwargs):
|
||||
def _requests(self, action, session=requests, **kwargs):
|
||||
|
||||
if action == "GET":
|
||||
r = session.get(**kwargs)
|
||||
|
|
|
@ -22,40 +22,34 @@ import xbmcvfs
|
|||
#################################################################################################
|
||||
# Main methods
|
||||
|
||||
class Logging():
|
||||
|
||||
LOGGINGCLASS = None
|
||||
class Logging(object):
|
||||
|
||||
|
||||
def __init__(self, classname=""):
|
||||
def __init__(self, title=""):
|
||||
|
||||
self.LOGGINGCLASS = classname
|
||||
self.title = title
|
||||
|
||||
def log(self, msg, level=1):
|
||||
def _getLogLevel(self, level):
|
||||
|
||||
self.logMsg("EMBY %s" % self.LOGGINGCLASS, msg, level)
|
||||
|
||||
def logMsg(self, title, msg, level=1):
|
||||
|
||||
# Get the logLevel set in UserClient
|
||||
try:
|
||||
logLevel = int(window('emby_logLevel'))
|
||||
except ValueError:
|
||||
logLevel = 0
|
||||
|
||||
if logLevel >= level:
|
||||
return logLevel >= level
|
||||
|
||||
def _printMsg(self, title, msg):
|
||||
|
||||
if logLevel == 2: # inspect.stack() is expensive
|
||||
try:
|
||||
xbmc.log("%s -> %s : %s" % (title, inspect.stack()[1][3], msg))
|
||||
except UnicodeEncodeError:
|
||||
xbmc.log("%s -> %s : %s" % (title, inspect.stack()[1][3], msg.encode('utf-8')))
|
||||
else:
|
||||
try:
|
||||
xbmc.log("%s -> %s" % (title, msg))
|
||||
except UnicodeEncodeError:
|
||||
xbmc.log("%s -> %s" % (title, msg.encode('utf-8')))
|
||||
|
||||
def log(self, msg, level=1):
|
||||
|
||||
if self._getLogLevel(level):
|
||||
self._printMsg("EMBY %s" % self.title, msg)
|
||||
|
||||
# Initiate class for utils.py document logging
|
||||
log = Logging('Utils').log
|
||||
|
||||
|
@ -223,7 +217,7 @@ def setScreensaver(value):
|
|||
def convertDate(date):
|
||||
try:
|
||||
date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
||||
except TypeError:
|
||||
except (ImportError, TypeError):
|
||||
# TypeError: attribute of type 'NoneType' is not callable
|
||||
# Known Kodi/python error
|
||||
date = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
|
||||
|
|
Loading…
Reference in a new issue