mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
parent
d6d1265b7c
commit
83ea76d7eb
3 changed files with 56 additions and 27 deletions
|
@ -23,11 +23,6 @@ log = logging.getLogger("EMBY."+__name__)
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
class HTTPException(Exception):
|
|
||||||
# Emby HTTP exception
|
|
||||||
def __init__(self, status):
|
|
||||||
self.status = status
|
|
||||||
|
|
||||||
|
|
||||||
class DownloadUtils(object):
|
class DownloadUtils(object):
|
||||||
|
|
||||||
|
@ -61,13 +56,14 @@ class DownloadUtils(object):
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
return self._get_session_info()['Token']
|
return self._get_session_info()['Token']
|
||||||
|
|
||||||
def add_server(self, server):
|
def add_server(self, server, ssl):
|
||||||
# Reserved for userclient only
|
# Reserved for userclient only
|
||||||
server_id = server['Id']
|
server_id = server['Id']
|
||||||
info = {
|
info = {
|
||||||
'UserId': server['UserId'],
|
'UserId': server['UserId'],
|
||||||
'Server': connectionmanager.getServerAddress(server, server['LastConnectionMode']),
|
'Server': connectionmanager.getServerAddress(server, server['LastConnectionMode']),
|
||||||
'Token': server['AccessToken'],
|
'Token': server['AccessToken'],
|
||||||
|
'SSL': ssl
|
||||||
}
|
}
|
||||||
for server_info in self.servers:
|
for server_info in self.servers:
|
||||||
if server_info == server_id:
|
if server_info == server_id:
|
||||||
|
@ -162,9 +158,10 @@ class DownloadUtils(object):
|
||||||
# Attach authenticated header to the session
|
# Attach authenticated header to the session
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers = self.get_header()
|
session.headers = self.get_header()
|
||||||
|
session.verify = self.session['SSL']
|
||||||
# Retry connections to the server
|
# Retry connections to the server
|
||||||
session.mount("http://", requests.adapters.HTTPAdapter(max_retries=3))
|
session.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=3))
|
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
self.session_requests = session
|
self.session_requests = session
|
||||||
|
|
||||||
log.info("requests session started on: %s", self.session['Server'])
|
log.info("requests session started on: %s", self.session['Server'])
|
||||||
|
@ -230,13 +227,16 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
if requires_server and (not server or not server.get("Server") or not server.get("UserId")):
|
if requires_server and (not server or not server.get("Server") or not server.get("UserId")):
|
||||||
log.info("Aborting download, Server Details Error: %s url=%s" % (server, url))
|
log.info("Aborting download, Server Details Error: %s url=%s" % (server, url))
|
||||||
raise Exception("Aborting download, Server Details Error: %s url=%s" % (server, url))
|
exc = Exception("Aborting download, Server Details Error: %s url=%s" % (server, url))
|
||||||
|
exc.quiet = True
|
||||||
|
raise exc
|
||||||
|
|
||||||
if server_id is None and self.session_requests is not None: # Main server
|
if server_id is None and self.session_requests is not None: # Main server
|
||||||
session = self.session_requests
|
session = self.session_requests
|
||||||
else:
|
else:
|
||||||
session = requests
|
session = requests
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
|
'verify': server['SSL'],
|
||||||
'headers': self.get_header(server_id, authenticate)
|
'headers': self.get_header(server_id, authenticate)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -247,7 +247,9 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
# does the URL look ok
|
# does the URL look ok
|
||||||
if url.startswith('/'):
|
if url.startswith('/'):
|
||||||
raise Exception("URL Error: " + url)
|
exc = Exception("URL Error: " + url)
|
||||||
|
exc.quiet = True
|
||||||
|
raise exc
|
||||||
|
|
||||||
##### PREPARE REQUEST #####
|
##### PREPARE REQUEST #####
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
|
@ -261,8 +263,6 @@ class DownloadUtils(object):
|
||||||
log.debug(kwargs)
|
log.debug(kwargs)
|
||||||
response = self._requests(action_type, session, **kwargs)
|
response = self._requests(action_type, session, **kwargs)
|
||||||
#response = requests.get('http://httpbin.org/status/400')
|
#response = requests.get('http://httpbin.org/status/400')
|
||||||
if window('emby_test') == "false":
|
|
||||||
raise requests.exceptions.ConnectionError
|
|
||||||
|
|
||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
# No body in the response
|
# No body in the response
|
||||||
|
@ -288,19 +288,28 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
##### EXCEPTIONS #####
|
##### EXCEPTIONS #####
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as error:
|
except requests.exceptions.SSLError as error:
|
||||||
# Make the addon aware of status
|
log.error("Invalid SSL certificate for: %s", url)
|
||||||
window('emby_test', value="true")
|
error.quiet = True
|
||||||
|
raise
|
||||||
|
|
||||||
if window('emby_online') != "false":
|
except requests.exceptions.ConnectTimeout as error:
|
||||||
log.error("Server unreachable at: %s", url)
|
log.error("ConnectTimeout at: %s", url)
|
||||||
window('emby_online', value="false")
|
error.quiet = True
|
||||||
|
raise
|
||||||
raise HTTPException(None)
|
|
||||||
|
|
||||||
except requests.exceptions.ReadTimeout as error:
|
except requests.exceptions.ReadTimeout as error:
|
||||||
log.error("ReadTimeout at: %s", url)
|
log.error("ReadTimeout at: %s", url)
|
||||||
raise HTTPException(None)
|
error.quiet = True
|
||||||
|
raise
|
||||||
|
|
||||||
|
except requests.exceptions.ConnectionError as error:
|
||||||
|
# Make the addon aware of status
|
||||||
|
if window('emby_online') != "false":
|
||||||
|
log.error("Server unreachable at: %s", url)
|
||||||
|
window('emby_online', value="false")
|
||||||
|
error.quiet = True
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as error:
|
except requests.exceptions.HTTPError as error:
|
||||||
|
|
||||||
|
@ -326,10 +335,14 @@ class DownloadUtils(object):
|
||||||
xbmcgui.Dialog().notification(heading="Error connecting",
|
xbmcgui.Dialog().notification(heading="Error connecting",
|
||||||
message="Unauthorized.",
|
message="Unauthorized.",
|
||||||
icon=xbmcgui.NOTIFICATION_ERROR)
|
icon=xbmcgui.NOTIFICATION_ERROR)
|
||||||
raise HTTPException(response.status_code)
|
|
||||||
|
error.quiet = True
|
||||||
|
raise
|
||||||
|
|
||||||
# if we got to here and did not process the download for some reason then that is bad
|
# if we got to here and did not process the download for some reason then that is bad
|
||||||
raise Exception("Unhandled Download : %s", url)
|
exc = Exception("Unhandled Download : %s", url)
|
||||||
|
#exc.quiet = True
|
||||||
|
raise exc
|
||||||
|
|
||||||
def _ensure_server(self, server_id=None):
|
def _ensure_server(self, server_id=None):
|
||||||
|
|
||||||
|
@ -351,7 +364,8 @@ class DownloadUtils(object):
|
||||||
info = {
|
info = {
|
||||||
'UserId': "",
|
'UserId': "",
|
||||||
'Server': "",
|
'Server': "",
|
||||||
'Token': ""
|
'Token': "",
|
||||||
|
'SSL': False
|
||||||
}
|
}
|
||||||
|
|
||||||
if server_id is None: # Main server
|
if server_id is None: # Main server
|
||||||
|
|
|
@ -73,6 +73,19 @@ class UserClient(threading.Thread):
|
||||||
log.error(error)
|
log.error(error)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_ssl(cls):
|
||||||
|
"""
|
||||||
|
Returns boolean value or path to certificate
|
||||||
|
True: Verify ssl
|
||||||
|
False: Don't verify connection
|
||||||
|
"""
|
||||||
|
certificate = settings('sslcert')
|
||||||
|
if certificate != "None":
|
||||||
|
return certificate
|
||||||
|
|
||||||
|
return True if settings('sslverify') == "true" else False
|
||||||
|
|
||||||
def get_access(self):
|
def get_access(self):
|
||||||
|
|
||||||
if not self._has_access:
|
if not self._has_access:
|
||||||
|
@ -187,7 +200,8 @@ class UserClient(threading.Thread):
|
||||||
'UserId': userid,
|
'UserId': userid,
|
||||||
'Server': server,
|
'Server': server,
|
||||||
'ServerId': settings('serverId'),
|
'ServerId': settings('serverId'),
|
||||||
'Token': token
|
'Token': token,
|
||||||
|
'SSL': self.get_ssl()
|
||||||
}
|
}
|
||||||
# Set downloadutils.py values
|
# Set downloadutils.py values
|
||||||
doutils.set_session(**server_json)
|
doutils.set_session(**server_json)
|
||||||
|
@ -221,6 +235,7 @@ class UserClient(threading.Thread):
|
||||||
added_servers = []
|
added_servers = []
|
||||||
for server in servers:
|
for server in servers:
|
||||||
if server['Id'] != settings('serverId'):
|
if server['Id'] != settings('serverId'):
|
||||||
|
# TODO: SSL setup
|
||||||
self.doutils.add_server(server, False)
|
self.doutils.add_server(server, False)
|
||||||
added_servers.append(server['Id'])
|
added_servers.append(server['Id'])
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
<!-- User settings -->
|
<!-- User settings -->
|
||||||
<setting id="serverName" label="30001" type="text" default="" />
|
<setting id="serverName" label="30001" type="text" default="" />
|
||||||
<setting id="server" label="30000" type="text" default="" visible="!eq(-1,)" />
|
<setting id="server" label="30000" type="text" default="" visible="!eq(-1,)" />
|
||||||
<!--<setting id="sslverify" label="30500" type="bool" default="false" visible="!eq(-1,)" subsetting="true" />
|
<setting id="sslverify" label="30500" type="bool" default="false" visible="!eq(-1,)" subsetting="true" />
|
||||||
<setting id="sslcert" label="30501" type="file" default="None" visible="eq(-1,true)" subsetting="true" />-->
|
<setting id="sslcert" label="30501" type="file" default="None" visible="eq(-1,true)" subsetting="true" />
|
||||||
<setting id="accessToken" type="text" default="" visible="false" />
|
<setting id="accessToken" type="text" default="" visible="false" />
|
||||||
<setting id="userId" type="text" default="" visible="false" />
|
<setting id="userId" type="text" default="" visible="false" />
|
||||||
<!-- Device settings -->
|
<!-- Device settings -->
|
||||||
|
|
Loading…
Reference in a new issue