mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
Fix typo in method
Pylint downloadutils
This commit is contained in:
parent
55438749bb
commit
8b0164d5a3
1 changed files with 36 additions and 41 deletions
|
@ -6,7 +6,6 @@ import json
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import xbmc
|
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
|
||||||
import clientinfo
|
import clientinfo
|
||||||
|
@ -79,7 +78,7 @@ class DownloadUtils(object):
|
||||||
# Reserved for userclient only
|
# Reserved for userclient only
|
||||||
for server in self.servers:
|
for server in self.servers:
|
||||||
if server['ServerId'] == server_id:
|
if server['ServerId'] == server_id:
|
||||||
self.servers.remove(s)
|
self.servers.pop(server)
|
||||||
window('emby_server%s.json' % server_id, clear=True)
|
window('emby_server%s.json' % server_id, clear=True)
|
||||||
window('emby_server%s.name' % server_id, clear=True)
|
window('emby_server%s.name' % server_id, clear=True)
|
||||||
log.info("removing %s from available servers", server_id)
|
log.info("removing %s from available servers", server_id)
|
||||||
|
@ -216,12 +215,12 @@ class DownloadUtils(object):
|
||||||
authenticate=True, server_id=None):
|
authenticate=True, server_id=None):
|
||||||
|
|
||||||
log.debug("===== ENTER downloadUrl =====")
|
log.debug("===== ENTER downloadUrl =====")
|
||||||
|
|
||||||
session = requests
|
session = requests
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
default_link = ""
|
default_link = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Ensure server info is loaded
|
# Ensure server info is loaded
|
||||||
self._ensure_server(server_id)
|
self._ensure_server(server_id)
|
||||||
server = self.session if server_id is None else self.servers[server_id]
|
server = self.session if server_id is None else self.servers[server_id]
|
||||||
|
@ -248,62 +247,63 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
##### THE RESPONSE #####
|
##### THE RESPONSE #####
|
||||||
log.debug(kwargs)
|
log.debug(kwargs)
|
||||||
r = self._requests(action_type, session, **kwargs)
|
response = self._requests(action_type, session, **kwargs)
|
||||||
|
|
||||||
if r.status_code == 204:
|
if response.status_code == 204:
|
||||||
# No body in the response
|
# No body in the response
|
||||||
log.debug("====== 204 Success ======")
|
log.debug("====== 204 Success ======")
|
||||||
# Read response to release connection
|
# Read response to release connection
|
||||||
r.content
|
response.content
|
||||||
|
|
||||||
elif r.status_code == requests.codes.ok:
|
elif response.status_code == requests.codes.ok:
|
||||||
try:
|
try:
|
||||||
# UNICODE - JSON object
|
# UNICODE - JSON object
|
||||||
r = r.json()
|
response = response.json()
|
||||||
log.debug("====== 200 Success ======")
|
log.debug("====== 200 Success ======")
|
||||||
log.debug("Response: %s" % r)
|
log.debug("Response: %s", response)
|
||||||
return r
|
return response
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if r.headers.get('content-type') != "text/html":
|
if response.headers.get('content-type') != "text/html":
|
||||||
log.info("Unable to convert the response for: %s" % url)
|
log.info("Unable to convert the response for: %s", url)
|
||||||
|
|
||||||
else: # Bad status code
|
else: # Bad status code
|
||||||
log.error("=== Bad status response: %s ===" % r.status_code)
|
log.error("=== Bad status response: %s ===", response.status_code)
|
||||||
r.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
##### EXCEPTIONS #####
|
##### EXCEPTIONS #####
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.SSLError as error:
|
||||||
# Make the addon aware of status
|
log.error("invalid SSL certificate for: %s", url)
|
||||||
if window('emby_online') != "false":
|
|
||||||
log.error("Server unreachable at: %s" % url)
|
|
||||||
window('emby_online', value="false")
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectTimeout as error:
|
except requests.exceptions.ConnectTimeout as error:
|
||||||
log.error("Server timeout at: %s", url)
|
log.error("Server timeout at: %s", url)
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as error:
|
except requests.exceptions.HTTPError as error:
|
||||||
|
|
||||||
if r.status_code == 401:
|
if response.status_code == 401:
|
||||||
# Unauthorized
|
# Unauthorized
|
||||||
status = window('emby_serverStatus')
|
status = window('emby_serverStatus')
|
||||||
|
|
||||||
if 'X-Application-Error-Code' in r.headers:
|
if 'X-Application-Error-Code' in response.headers:
|
||||||
# Emby server errors
|
# Emby server errors
|
||||||
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
if response.headers['X-Application-Error-Code'] == "ParentalControl":
|
||||||
# Parental control - access restricted
|
# Parental control - access restricted
|
||||||
if status != "restricted":
|
if status != "restricted":
|
||||||
xbmcgui.Dialog().notification(
|
xbmcgui.Dialog().notification(heading=lang(29999),
|
||||||
heading=lang(29999),
|
message="Access restricted.",
|
||||||
message="Access restricted.",
|
icon=xbmcgui.NOTIFICATION_ERROR,
|
||||||
icon=xbmcgui.NOTIFICATION_ERROR,
|
time=5000)
|
||||||
time=5000)
|
|
||||||
|
|
||||||
window('emby_serverStatus', value="restricted")
|
window('emby_serverStatus', value="restricted")
|
||||||
raise Warning('restricted')
|
raise Warning('restricted')
|
||||||
|
|
||||||
elif r.headers['X-Application-Error-Code'] == "UnauthorizedAccessException":
|
elif response.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
|
||||||
|
|
||||||
|
@ -311,21 +311,16 @@ class DownloadUtils(object):
|
||||||
# Tell userclient token has been revoked.
|
# Tell userclient token has been revoked.
|
||||||
window('emby_serverStatus', value="401")
|
window('emby_serverStatus', value="401")
|
||||||
log.error("HTTP Error: %s", error)
|
log.error("HTTP Error: %s", error)
|
||||||
xbmcgui.Dialog().notification(
|
xbmcgui.Dialog().notification(heading="Error connecting",
|
||||||
heading="Error connecting",
|
message="Unauthorized.",
|
||||||
message="Unauthorized.",
|
icon=xbmcgui.NOTIFICATION_ERROR)
|
||||||
icon=xbmcgui.NOTIFICATION_ERROR)
|
|
||||||
raise Warning('401')
|
raise Warning('401')
|
||||||
|
|
||||||
except requests.exceptions.SSLError as error:
|
|
||||||
log.error("invalid SSL certificate for: %s", url)
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as error:
|
except requests.exceptions.RequestException as error:
|
||||||
log.error("unknown error connecting to: %s" % url)
|
log.error("unknown error connecting to: %s", url)
|
||||||
|
|
||||||
return default_link
|
return default_link
|
||||||
|
|
||||||
|
|
||||||
def _ensure_server(self, server_id=None):
|
def _ensure_server(self, server_id=None):
|
||||||
|
|
||||||
if server_id is None and self.session_requests is None:
|
if server_id is None and self.session_requests is None:
|
||||||
|
@ -342,7 +337,7 @@ class DownloadUtils(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_session_info(cls, server_id=None):
|
def _get_session_info(cls, server_id=None):
|
||||||
|
|
||||||
info = {
|
info = {
|
||||||
'UserId': "",
|
'UserId': "",
|
||||||
'Server': "",
|
'Server': "",
|
||||||
|
@ -354,7 +349,7 @@ class DownloadUtils(object):
|
||||||
server = window('emby_server.json')
|
server = window('emby_server.json')
|
||||||
else: # Other connect servers
|
else: # Other connect servers
|
||||||
server = window('emby_server%s.json' % server_id)
|
server = window('emby_server%s.json' % server_id)
|
||||||
|
|
||||||
if server:
|
if server:
|
||||||
info.update(json.loads(server))
|
info.update(json.loads(server))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue