mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Fix downloadutils revert
This commit is contained in:
parent
12f0c12dd7
commit
e1c046f218
1 changed files with 32 additions and 38 deletions
|
@ -23,6 +23,11 @@ log = logging.getLogger("EMBY."+__name__)
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
class HTTPException(Exception):
|
||||||
|
# Emby HTTP exception
|
||||||
|
def __init__(self, status):
|
||||||
|
self.status = status
|
||||||
|
|
||||||
|
|
||||||
class DownloadUtils(object):
|
class DownloadUtils(object):
|
||||||
|
|
||||||
|
@ -112,18 +117,18 @@ class DownloadUtils(object):
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
self.downloadUrl(url, postBody=data, action_type="POST")
|
self.downloadUrl(url, postBody=data, action_type="POST")
|
||||||
log.debug("Posted capabilities to %s", self.session['Server'])
|
log.debug("Posted capabilities to %s", self.session['Server'])
|
||||||
|
|
||||||
# Attempt at getting sessionId
|
# Attempt at getting sessionId
|
||||||
url = "{server}/emby/Sessions?DeviceId=%s&format=json" % device_id
|
url = "{server}/emby/Sessions?DeviceId=%s&format=json" % device_id
|
||||||
|
|
||||||
try:
|
|
||||||
result = self.downloadUrl(url)
|
result = self.downloadUrl(url)
|
||||||
session_id = result[0]['Id']
|
session_id = result[0]['Id']
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.error("Failed to retrieve the session id: " + str(error))
|
log.error("Failed to retrieve the session id: " + str(error))
|
||||||
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info("SessionId: %s", session_id)
|
log.info("SessionId: %s", session_id)
|
||||||
|
@ -153,6 +158,8 @@ class DownloadUtils(object):
|
||||||
% (session_id, user_id))
|
% (session_id, user_id))
|
||||||
self.downloadUrl(url, postBody={}, action_type="POST")
|
self.downloadUrl(url, postBody={}, action_type="POST")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def start_session(self):
|
def start_session(self):
|
||||||
# User is identified from this point
|
# User is identified from this point
|
||||||
# Attach authenticated header to the session
|
# Attach authenticated header to the session
|
||||||
|
@ -160,8 +167,8 @@ class DownloadUtils(object):
|
||||||
session.headers = self.get_header()
|
session.headers = self.get_header()
|
||||||
session.verify = self.session['SSL']
|
session.verify = self.session['SSL']
|
||||||
# Retry connections to the server
|
# Retry connections to the server
|
||||||
session.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
session.mount("http://", requests.adapters.HTTPAdapter(max_retries=3))
|
||||||
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=3))
|
||||||
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'])
|
||||||
|
@ -227,9 +234,7 @@ 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))
|
||||||
exc = Exception("Aborting download, Server Details Error: %s url=%s" % (server, url))
|
raise 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
|
||||||
|
@ -247,9 +252,7 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
# does the URL look ok
|
# does the URL look ok
|
||||||
if url.startswith('/'):
|
if url.startswith('/'):
|
||||||
exc = Exception("URL Error: " + url)
|
raise Exception("URL Error: " + url)
|
||||||
exc.quiet = True
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
##### PREPARE REQUEST #####
|
##### PREPARE REQUEST #####
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
|
@ -263,6 +266,8 @@ 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,28 +293,20 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
##### EXCEPTIONS #####
|
##### EXCEPTIONS #####
|
||||||
|
|
||||||
except requests.exceptions.SSLError as error:
|
|
||||||
log.error("Invalid SSL certificate for: %s", url)
|
|
||||||
error.quiet = True
|
|
||||||
raise
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectTimeout as error:
|
|
||||||
log.error("ConnectTimeout at: %s", url)
|
|
||||||
error.quiet = True
|
|
||||||
raise
|
|
||||||
|
|
||||||
except requests.exceptions.ReadTimeout as error:
|
|
||||||
log.error("ReadTimeout at: %s", url)
|
|
||||||
error.quiet = True
|
|
||||||
raise
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as error:
|
except requests.exceptions.ConnectionError as error:
|
||||||
# Make the addon aware of status
|
# Make the addon aware of status
|
||||||
|
window('emby_test', value="true")
|
||||||
|
|
||||||
if window('emby_online') != "false":
|
if window('emby_online') != "false":
|
||||||
log.error("Server unreachable at: %s", url)
|
log.error("Server unreachable at: %s", url)
|
||||||
window('emby_online', value="false")
|
window('emby_online', value="false")
|
||||||
error.quiet = True
|
|
||||||
raise
|
raise HTTPException(None)
|
||||||
|
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
log.error("ReadTimeout at: %s", url)
|
||||||
|
|
||||||
|
raise HTTPException(None)
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as error:
|
except requests.exceptions.HTTPError as error:
|
||||||
|
|
||||||
|
@ -336,13 +333,10 @@ class DownloadUtils(object):
|
||||||
message="Unauthorized.",
|
message="Unauthorized.",
|
||||||
icon=xbmcgui.NOTIFICATION_ERROR)
|
icon=xbmcgui.NOTIFICATION_ERROR)
|
||||||
|
|
||||||
error.quiet = True
|
raise HTTPException(response.status_code)
|
||||||
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
|
||||||
exc = Exception("Unhandled Download : %s", url)
|
raise Exception("Unhandled Download : %s", url)
|
||||||
#exc.quiet = True
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
def _ensure_server(self, server_id=None):
|
def _ensure_server(self, server_id=None):
|
||||||
|
|
||||||
|
@ -365,7 +359,7 @@ class DownloadUtils(object):
|
||||||
'UserId': "",
|
'UserId': "",
|
||||||
'Server': "",
|
'Server': "",
|
||||||
'Token': "",
|
'Token': "",
|
||||||
'SSL': False
|
'SSL': True
|
||||||
}
|
}
|
||||||
|
|
||||||
if server_id is None: # Main server
|
if server_id is None: # Main server
|
||||||
|
|
Loading…
Reference in a new issue