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
|
import clientinfo
|
||||||
from utils import Logging, window, settings
|
from utils import Logging, window, settings
|
||||||
import utils
|
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
@ -29,11 +28,10 @@ class DownloadUtils():
|
||||||
# Borg - multiple instances, shared state
|
# Borg - multiple instances, shared state
|
||||||
_shared_state = {}
|
_shared_state = {}
|
||||||
clientInfo = clientinfo.ClientInfo()
|
clientInfo = clientinfo.ClientInfo()
|
||||||
addonName = clientInfo.getAddonName()
|
|
||||||
|
|
||||||
# Requests session
|
# Requests session
|
||||||
s = None
|
s = None
|
||||||
timeout = 30
|
default_timeout = 30
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -182,7 +180,19 @@ class DownloadUtils():
|
||||||
deviceId = self.clientInfo.getDeviceId()
|
deviceId = self.clientInfo.getDeviceId()
|
||||||
version = self.clientInfo.getVersion()
|
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
|
# If user is not authenticated
|
||||||
auth = (
|
auth = (
|
||||||
'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
||||||
|
@ -194,21 +204,6 @@ class DownloadUtils():
|
||||||
'Accept-Charset': 'UTF-8,*',
|
'Accept-Charset': 'UTF-8,*',
|
||||||
'Authorization': auth
|
'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
|
return header
|
||||||
|
|
||||||
|
@ -266,14 +261,14 @@ class DownloadUtils():
|
||||||
##### PREPARE REQUEST #####
|
##### PREPARE REQUEST #####
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'url': url,
|
'url': url,
|
||||||
'timeout': self.timeout,
|
'timeout': self.default_timeout,
|
||||||
'json': postBody,
|
'json': postBody,
|
||||||
'params': parameters
|
'params': parameters
|
||||||
})
|
})
|
||||||
|
|
||||||
##### THE RESPONSE #####
|
##### THE RESPONSE #####
|
||||||
log(kwargs, 2)
|
log(kwargs, 2)
|
||||||
r = self.__requests(action_type, session, **kwargs)
|
r = self._requests(action_type, session, **kwargs)
|
||||||
|
|
||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
# No body in the response
|
# No body in the response
|
||||||
|
@ -358,7 +353,7 @@ class DownloadUtils():
|
||||||
|
|
||||||
return default_link
|
return default_link
|
||||||
|
|
||||||
def __requests(self, action, session=requests, **kwargs):
|
def _requests(self, action, session=requests, **kwargs):
|
||||||
|
|
||||||
if action == "GET":
|
if action == "GET":
|
||||||
r = session.get(**kwargs)
|
r = session.get(**kwargs)
|
||||||
|
|
|
@ -22,39 +22,33 @@ import xbmcvfs
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
# Main methods
|
# Main methods
|
||||||
|
|
||||||
class Logging():
|
class Logging(object):
|
||||||
|
|
||||||
LOGGINGCLASS = None
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
try:
|
||||||
logLevel = int(window('emby_logLevel'))
|
logLevel = int(window('emby_logLevel'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logLevel = 0
|
logLevel = 0
|
||||||
|
|
||||||
if logLevel >= level:
|
return logLevel >= level
|
||||||
|
|
||||||
if logLevel == 2: # inspect.stack() is expensive
|
def _printMsg(self, title, msg):
|
||||||
try:
|
|
||||||
xbmc.log("%s -> %s : %s" % (title, inspect.stack()[1][3], msg))
|
try:
|
||||||
except UnicodeEncodeError:
|
xbmc.log("%s -> %s" % (title, msg))
|
||||||
xbmc.log("%s -> %s : %s" % (title, inspect.stack()[1][3], msg.encode('utf-8')))
|
except UnicodeEncodeError:
|
||||||
else:
|
xbmc.log("%s -> %s" % (title, msg.encode('utf-8')))
|
||||||
try:
|
|
||||||
xbmc.log("%s -> %s" % (title, msg))
|
def log(self, msg, level=1):
|
||||||
except UnicodeEncodeError:
|
|
||||||
xbmc.log("%s -> %s" % (title, msg.encode('utf-8')))
|
if self._getLogLevel(level):
|
||||||
|
self._printMsg("EMBY %s" % self.title, msg)
|
||||||
|
|
||||||
# Initiate class for utils.py document logging
|
# Initiate class for utils.py document logging
|
||||||
log = Logging('Utils').log
|
log = Logging('Utils').log
|
||||||
|
@ -223,7 +217,7 @@ def setScreensaver(value):
|
||||||
def convertDate(date):
|
def convertDate(date):
|
||||||
try:
|
try:
|
||||||
date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
except TypeError:
|
except (ImportError, TypeError):
|
||||||
# TypeError: attribute of type 'NoneType' is not callable
|
# TypeError: attribute of type 'NoneType' is not callable
|
||||||
# Known Kodi/python error
|
# Known Kodi/python error
|
||||||
date = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
|
date = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
|
||||||
|
|
Loading…
Reference in a new issue