brought downloadutils.py up to speed
This commit is contained in:
parent
ed1915ec7e
commit
72b3b49b6e
1 changed files with 17 additions and 42 deletions
|
@ -12,6 +12,8 @@ import xbmcgui
|
||||||
import utils
|
import utils
|
||||||
import clientinfo
|
import clientinfo
|
||||||
|
|
||||||
|
import PlexAPI
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
# Disable requests logging
|
# Disable requests logging
|
||||||
|
@ -177,48 +179,17 @@ class DownloadUtils():
|
||||||
except:
|
except:
|
||||||
self.logMsg("Requests session could not be terminated.", 1)
|
self.logMsg("Requests session could not be terminated.", 1)
|
||||||
|
|
||||||
def getHeader(self, authenticate=True):
|
def getHeader(self, authenticate=True, options={}):
|
||||||
|
plx = PlexAPI.PlexAPI()
|
||||||
clientInfo = self.clientInfo
|
if authenticate:
|
||||||
|
options['X-Plex-Token'] = self.token
|
||||||
deviceName = clientInfo.getDeviceName()
|
header = plx.getXArgsDeviceInfo(options=options, JSON=True)
|
||||||
deviceId = clientInfo.getDeviceId()
|
|
||||||
version = clientInfo.getVersion()
|
|
||||||
|
|
||||||
if not authenticate:
|
|
||||||
# If user is not authenticated
|
|
||||||
auth = (
|
|
||||||
'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
|
||||||
% (deviceName, deviceId, version))
|
|
||||||
header = {
|
|
||||||
|
|
||||||
'Content-type': 'application/json',
|
|
||||||
'Accept-encoding': 'gzip',
|
|
||||||
'Accept-Charset': 'UTF-8,*',
|
|
||||||
'Authorization': auth
|
|
||||||
}
|
|
||||||
self.logMsg("Header: %s" % header, 2)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
userId = self.userId
|
header = plx.getXArgsDeviceInfo(options=options, JSON=True)
|
||||||
token = self.token
|
self.logMsg("Header: %s" % header, 2)
|
||||||
# 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
|
|
||||||
}
|
|
||||||
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, headerOptions={}):
|
||||||
|
|
||||||
self.logMsg("=== ENTER downloadUrl ===", 2)
|
self.logMsg("=== ENTER downloadUrl ===", 2)
|
||||||
|
|
||||||
|
@ -249,7 +220,7 @@ class DownloadUtils():
|
||||||
self.userId = utils.window('emby_currUser')
|
self.userId = utils.window('emby_currUser')
|
||||||
self.server = utils.window('emby_server%s' % self.userId)
|
self.server = utils.window('emby_server%s' % self.userId)
|
||||||
self.token = utils.window('emby_accessToken%s' % self.userId)
|
self.token = utils.window('emby_accessToken%s' % self.userId)
|
||||||
header = self.getHeader()
|
header = self.getHeader(options=headerOptions)
|
||||||
verifyssl = False
|
verifyssl = False
|
||||||
cert = None
|
cert = None
|
||||||
|
|
||||||
|
@ -292,7 +263,7 @@ class DownloadUtils():
|
||||||
# If user is not authenticated
|
# If user is not authenticated
|
||||||
elif not authenticate:
|
elif not authenticate:
|
||||||
|
|
||||||
header = self.getHeader(authenticate=False)
|
header = self.getHeader(authenticate=False, options=headerOptions)
|
||||||
verifyssl = False
|
verifyssl = False
|
||||||
|
|
||||||
# If user enables ssl verification
|
# If user enables ssl verification
|
||||||
|
@ -333,7 +304,11 @@ class DownloadUtils():
|
||||||
return r
|
return r
|
||||||
|
|
||||||
except:
|
except:
|
||||||
if r.headers.get('content-type') != "text/html":
|
# Allow for xml responses, but do not process them
|
||||||
|
if 'xml' in r.headers.get('content-type'):
|
||||||
|
self.logMsg("Received an XML response for: %s" % url, 1)
|
||||||
|
return 'xml'
|
||||||
|
elif r.headers.get('content-type') != "text/html":
|
||||||
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()
|
||||||
|
|
Loading…
Reference in a new issue