mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 09:46:11 +00:00
log clean
This commit is contained in:
parent
b8a5f9c913
commit
ad156d3f6c
1 changed files with 23 additions and 25 deletions
|
@ -23,7 +23,7 @@ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
|
|
||||||
|
|
||||||
class DownloadUtils():
|
class DownloadUtils():
|
||||||
|
|
||||||
# Borg - multiple instances, shared state
|
# Borg - multiple instances, shared state
|
||||||
_shared_state = {}
|
_shared_state = {}
|
||||||
clientInfo = clientinfo.ClientInfo()
|
clientInfo = clientinfo.ClientInfo()
|
||||||
|
@ -77,11 +77,11 @@ class DownloadUtils():
|
||||||
# Post settings to session
|
# Post settings to session
|
||||||
url = "{server}/emby/Sessions/Capabilities/Full?format=json"
|
url = "{server}/emby/Sessions/Capabilities/Full?format=json"
|
||||||
data = {
|
data = {
|
||||||
|
|
||||||
'PlayableMediaTypes': "Audio,Video",
|
'PlayableMediaTypes': "Audio,Video",
|
||||||
'SupportsMediaControl': True,
|
'SupportsMediaControl': True,
|
||||||
'SupportedCommands': (
|
'SupportedCommands': (
|
||||||
|
|
||||||
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
||||||
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
||||||
"GoHome,PageUp,NextLetter,GoToSearch,"
|
"GoHome,PageUp,NextLetter,GoToSearch,"
|
||||||
|
@ -105,19 +105,19 @@ class DownloadUtils():
|
||||||
result = self.downloadUrl(url)
|
result = self.downloadUrl(url)
|
||||||
try:
|
try:
|
||||||
sessionId = result[0]['Id']
|
sessionId = result[0]['Id']
|
||||||
|
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
self.logMsg("Failed to retrieve sessionId.", 1)
|
self.logMsg("Failed to retrieve sessionId.", 1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.logMsg("Session: %s" % result, 2)
|
self.logMsg("Session: %s" % result, 2)
|
||||||
self.logMsg("SessionId: %s" % sessionId, 1)
|
self.logMsg("SessionId: %s" % sessionId, 1)
|
||||||
utils.window('emby_sessionId', value=sessionId)
|
utils.window('emby_sessionId', value=sessionId)
|
||||||
|
|
||||||
# Post any permanent additional users
|
# Post any permanent additional users
|
||||||
additionalUsers = utils.settings('additionalUsers')
|
additionalUsers = utils.settings('additionalUsers')
|
||||||
if additionalUsers:
|
if additionalUsers:
|
||||||
|
|
||||||
additionalUsers = additionalUsers.split(',')
|
additionalUsers = additionalUsers.split(',')
|
||||||
self.logMsg(
|
self.logMsg(
|
||||||
"List of permanent users added to the session: %s"
|
"List of permanent users added to the session: %s"
|
||||||
|
@ -145,8 +145,6 @@ class DownloadUtils():
|
||||||
|
|
||||||
def startSession(self):
|
def startSession(self):
|
||||||
|
|
||||||
log = self.logMsg
|
|
||||||
|
|
||||||
self.deviceId = self.clientInfo.getDeviceId()
|
self.deviceId = self.clientInfo.getDeviceId()
|
||||||
|
|
||||||
# User is identified from this point
|
# User is identified from this point
|
||||||
|
@ -160,8 +158,8 @@ class DownloadUtils():
|
||||||
if self.sslclient is not None:
|
if self.sslclient is not None:
|
||||||
verify = self.sslclient
|
verify = self.sslclient
|
||||||
except:
|
except:
|
||||||
log("Could not load SSL settings.", 1)
|
self.logMsg("Could not load SSL settings.", 1)
|
||||||
|
|
||||||
# Start session
|
# Start session
|
||||||
self.s = requests.Session()
|
self.s = requests.Session()
|
||||||
self.s.headers = header
|
self.s.headers = header
|
||||||
|
@ -170,7 +168,7 @@ class DownloadUtils():
|
||||||
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
|
|
||||||
log("Requests session started on: %s" % self.server, 1)
|
self.logMsg("Requests session started on: %s" % self.server, 1)
|
||||||
|
|
||||||
def stopSession(self):
|
def stopSession(self):
|
||||||
try:
|
try:
|
||||||
|
@ -198,9 +196,9 @@ class DownloadUtils():
|
||||||
'Accept-encoding': 'gzip',
|
'Accept-encoding': 'gzip',
|
||||||
'Accept-Charset': 'UTF-8,*',
|
'Accept-Charset': 'UTF-8,*',
|
||||||
'Authorization': auth
|
'Authorization': auth
|
||||||
}
|
}
|
||||||
self.logMsg("Header: %s" % header, 2)
|
self.logMsg("Header: %s" % header, 2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
userId = self.userId
|
userId = self.userId
|
||||||
token = self.token
|
token = self.token
|
||||||
|
@ -215,13 +213,13 @@ class DownloadUtils():
|
||||||
'Accept-Charset': 'UTF-8,*',
|
'Accept-Charset': 'UTF-8,*',
|
||||||
'Authorization': auth,
|
'Authorization': auth,
|
||||||
'X-MediaBrowser-Token': token
|
'X-MediaBrowser-Token': token
|
||||||
}
|
}
|
||||||
self.logMsg("Header: %s" % header, 2)
|
self.logMsg("Header: %s" % header, 2)
|
||||||
|
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def downloadUrl(self, url, postBody=None, type="GET", parameters=None, authenticate=True):
|
def downloadUrl(self, url, postBody=None, type="GET", parameters=None, authenticate=True):
|
||||||
|
|
||||||
self.logMsg("=== ENTER downloadUrl ===", 2)
|
self.logMsg("=== ENTER downloadUrl ===", 2)
|
||||||
|
|
||||||
timeout = self.timeout
|
timeout = self.timeout
|
||||||
|
@ -231,7 +229,7 @@ class DownloadUtils():
|
||||||
# If user is authenticated
|
# If user is authenticated
|
||||||
if (authenticate):
|
if (authenticate):
|
||||||
# Get requests session
|
# Get requests session
|
||||||
try:
|
try:
|
||||||
s = self.s
|
s = self.s
|
||||||
# Replace for the real values
|
# Replace for the real values
|
||||||
url = url.replace("{server}", self.server)
|
url = url.replace("{server}", self.server)
|
||||||
|
@ -244,7 +242,7 @@ class DownloadUtils():
|
||||||
r = s.post(url, json=postBody, timeout=timeout)
|
r = s.post(url, json=postBody, timeout=timeout)
|
||||||
elif type == "DELETE":
|
elif type == "DELETE":
|
||||||
r = s.delete(url, json=postBody, timeout=timeout)
|
r = s.delete(url, json=postBody, timeout=timeout)
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# request session does not exists
|
# request session does not exists
|
||||||
# Get user information
|
# Get user information
|
||||||
|
@ -301,7 +299,7 @@ class DownloadUtils():
|
||||||
verifyssl = self.sslclient
|
verifyssl = self.sslclient
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Prepare request
|
# Prepare request
|
||||||
if type == "GET":
|
if type == "GET":
|
||||||
r = requests.get(url,
|
r = requests.get(url,
|
||||||
|
@ -317,7 +315,7 @@ class DownloadUtils():
|
||||||
headers=header,
|
headers=header,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
verify=verifyssl)
|
verify=verifyssl)
|
||||||
|
|
||||||
##### THE RESPONSE #####
|
##### THE RESPONSE #####
|
||||||
self.logMsg(r.url, 2)
|
self.logMsg(r.url, 2)
|
||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
|
@ -325,8 +323,8 @@ class DownloadUtils():
|
||||||
self.logMsg("====== 204 Success ======", 2)
|
self.logMsg("====== 204 Success ======", 2)
|
||||||
|
|
||||||
elif r.status_code == requests.codes.ok:
|
elif r.status_code == requests.codes.ok:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# UNICODE - JSON object
|
# UNICODE - JSON object
|
||||||
r = r.json()
|
r = r.json()
|
||||||
self.logMsg("====== 200 Success ======", 2)
|
self.logMsg("====== 200 Success ======", 2)
|
||||||
|
@ -338,7 +336,7 @@ class DownloadUtils():
|
||||||
self.logMsg("Unable to convert the response for: %s" % url, 1)
|
self.logMsg("Unable to convert the response for: %s" % url, 1)
|
||||||
else:
|
else:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
##### EXCEPTIONS #####
|
##### EXCEPTIONS #####
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
|
@ -369,7 +367,7 @@ class DownloadUtils():
|
||||||
icon=xbmcgui.NOTIFICATION_ERROR,
|
icon=xbmcgui.NOTIFICATION_ERROR,
|
||||||
time=5000)
|
time=5000)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif r.headers['X-Application-Error-Code'] == "UnauthorizedAccessException":
|
elif r.headers['X-Application-Error-Code'] == "UnauthorizedAccessException":
|
||||||
# User tried to do something his emby account doesn't allow
|
# User tried to do something his emby account doesn't allow
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue