add handeling of exceptions for some downloadUrl func calls

This commit is contained in:
sfaulds 2016-12-01 09:21:36 +11:00
parent 62610f5e0d
commit e2fa93a6c4
4 changed files with 94 additions and 37 deletions

View file

@ -150,7 +150,12 @@ class ConnectManager(object):
# Return user or raise error # Return user or raise error
server = server or self.state['Servers'][0] server = server or self.state['Servers'][0]
server_address = connectionmanager.getServerAddress(server, server['LastConnectionMode']) server_address = connectionmanager.getServerAddress(server, server['LastConnectionMode'])
users = self.emby.getUsers(server_address)
users = "";
try:
users = self.emby.getUsers(server_address)
except Exception as error:
log.info("Error getting users from server: " + str(error))
if not users: if not users:
try: try:
@ -175,7 +180,12 @@ class ConnectManager(object):
except RuntimeError: except RuntimeError:
return self.login(server) return self.login(server)
else: else:
user = self.emby.loginUser(server_address, username) try:
user = self.emby.loginUser(server_address, username)
except Exception as error:
log.info("Error logging in user: " + str(error))
raise
self._connect.onAuthenticated(user) self._connect.onAuthenticated(user)
return user return user

View file

@ -125,8 +125,13 @@ class LoginManual(xbmcgui.WindowXMLDialog):
def _login(self, username, password): def _login(self, username, password):
result = self.emby.loginUser(self.server, username, password) try:
if not result: result = self.emby.loginUser(self.server, username, password)
except Exception as error:
log.info("Error doing login: " + str(error))
result = None
if result is None:
self._error(ERROR['Invalid'], lang(33009)) self._error(ERROR['Invalid'], lang(33009))
return False return False
else: else:

View file

@ -42,8 +42,13 @@ class Read_EmbyServer():
# This will return the full item # This will return the full item
item = {} item = {}
result = self.doUtils("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid) try:
if result: result = self.doUtils("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid)
except Exception as error:
log.info("Error getting item from server: " + str(error))
result = None
if result is not None:
item = result item = result
return item return item
@ -61,8 +66,14 @@ class Read_EmbyServer():
'Fields': "Etag" 'Fields': "Etag"
} }
url = "{server}/emby/Users/{UserId}/Items?&format=json" url = "{server}/emby/Users/{UserId}/Items?&format=json"
result = self.doUtils(url, parameters=params)
if result: try:
result = self.doUtils(url, parameters=params)
except Exception as error:
log.info("Error getting items form server: " + str(error))
result = None
if result is not None:
items.extend(result['Items']) items.extend(result['Items'])
return items return items
@ -88,8 +99,13 @@ class Read_EmbyServer():
) )
} }
url = "{server}/emby/Users/{UserId}/Items?format=json" url = "{server}/emby/Users/{UserId}/Items?format=json"
result = self.doUtils(url, parameters=params) try:
if result: result = self.doUtils(url, parameters=params)
except Exception as error:
log.info("Error getting full items: " + str(error))
result = None
if result is not None:
items.extend(result['Items']) items.extend(result['Items'])
return items return items
@ -179,14 +195,13 @@ class Read_EmbyServer():
'Recursive': True, 'Recursive': True,
'Limit': 1 'Limit': 1
} }
result = self.doUtils(url, parameters=params)
try: try:
result = self.doUtils(url, parameters=params)
total = result['TotalRecordCount'] total = result['TotalRecordCount']
items['TotalRecordCount'] = total items['TotalRecordCount'] = total
except Exception as error: # Failed to retrieve
except TypeError: # Failed to retrieve log.debug("%s:%s Failed to retrieve the server response: %s" % (url, params, error))
log.debug("%s:%s Failed to retrieve the server response." % (url, params))
else: else:
index = 0 index = 0
jump = self.limitIndex jump = self.limitIndex
@ -229,7 +244,7 @@ class Read_EmbyServer():
if "400" in error: if "400" in error:
log.info("Something went wrong, aborting request.") log.info("Something went wrong, aborting request.")
index += jump index += jump
except TypeError: except Exception as error:
# Something happened to the connection # Something happened to the connection
if not throttled: if not throttled:
throttled = True throttled = True
@ -300,8 +315,8 @@ class Read_EmbyServer():
try: try:
items = self.get_views(root)['Items'] items = self.get_views(root)['Items']
except TypeError: except Exception as error:
log.debug("Error retrieving views for type: %s" % mediatype) log.debug("Error retrieving views for type: %s error:%s" % (mediatype, error))
else: else:
for item in items: for item in items:
@ -347,11 +362,13 @@ class Read_EmbyServer():
'Recursive': True, 'Recursive': True,
'Ids': itemid 'Ids': itemid
} }
result = self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
try: try:
result = self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
total = result['TotalRecordCount'] total = result['TotalRecordCount']
except TypeError: except Exception as error:
# Something happened to the connection # Something happened to the connection
log.info("Error getting item count: " + str(error))
pass pass
else: else:
if total: if total:
@ -396,8 +413,14 @@ class Read_EmbyServer():
'Fields': "Etag" 'Fields': "Etag"
} }
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
result = self.doUtils(url, parameters=params)
if result: try:
result = self.doUtils(url, parameters=params)
except Exception as error:
log.info("Error getting Seasons form server: " + str(error))
result = None
if result is not None:
items = result items = result
return items return items
@ -430,14 +453,13 @@ class Read_EmbyServer():
'Recursive': True, 'Recursive': True,
'Limit': 1 'Limit': 1
} }
result = self.doUtils(url, parameters=params)
try: try:
result = self.doUtils(url, parameters=params)
total = result['TotalRecordCount'] total = result['TotalRecordCount']
items['TotalRecordCount'] = total items['TotalRecordCount'] = total
except Exception as error: # Failed to retrieve
except TypeError: # Failed to retrieve log.debug("%s:%s Failed to retrieve the server response: %s" % (url, params, error))
log.debug("%s:%s Failed to retrieve the server response." % (url, params))
else: else:
index = 0 index = 0
jump = self.limitIndex jump = self.limitIndex
@ -462,10 +484,14 @@ class Read_EmbyServer():
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview" "AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview"
) )
} }
result = self.doUtils(url, parameters=params)
items['Items'].extend(result['Items'])
index += jump try:
result = self.doUtils(url, parameters=params)
items['Items'].extend(result['Items'])
index += jump
except Exception as error:
log.debug("Error getting artists from server: " + str(error))
if dialog: if dialog:
percentage = int((float(index) / float(total))*100) percentage = int((float(index) / float(total))*100)
dialog.update(percentage) dialog.update(percentage)
@ -495,8 +521,14 @@ class Read_EmbyServer():
'TotalRecordCount': 0 'TotalRecordCount': 0
} }
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
result = self.doUtils(url)
if result: try:
result = self.doUtils(url)
except Exception as error:
log.info("Error getting additional parts form server: " + str(error))
result = None
if result is not None:
items = result items = result
return items return items
@ -552,9 +584,13 @@ class Read_EmbyServer():
def getUsers(self, server): def getUsers(self, server):
url = "%s/emby/Users/Public?format=json" % server url = "%s/emby/Users/Public?format=json" % server
users = self.doUtils(url, authenticate=False) try:
users = self.doUtils(url, authenticate=False)
except Exception as error:
log.info("Error getting users from server: " + str(error))
users = []
return users or [] return users
def loginUser(self, server, username, password=None): def loginUser(self, server, username, password=None):

View file

@ -53,7 +53,12 @@ class Views(object):
def _populate_views(self): def _populate_views(self):
# Will get emby views and views in Kodi # Will get emby views and views in Kodi
grouped_views = self.emby.get_views() try:
grouped_views = self.emby.get_views()
except Exception as error:
log.info("Error getting views from server: " + str(error))
grouped_views = None
if grouped_views is not None and "Items" in grouped_views: if grouped_views is not None and "Items" in grouped_views:
self.grouped_views = grouped_views['Items'] self.grouped_views = grouped_views['Items']
else: else:
@ -114,10 +119,11 @@ class Views(object):
def _get_grouped_view(self, media_type, view_id, view_name): def _get_grouped_view(self, media_type, view_id, view_name):
# Get single item from view to compare # Get single item from view to compare
result = self.emby.get_single_item(self.media_types[media_type], view_id)
try: try:
result = self.emby.get_single_item(self.media_types[media_type], view_id)
item = result['Items'][0]['Id'] item = result['Items'][0]['Id']
except (TypeError, IndexError): except Exception as error:
log.info("Error getting single item form server: " + str(error))
# Something is wrong. Keep the same folder name. # Something is wrong. Keep the same folder name.
# Could be the view is empty or the connection # Could be the view is empty or the connection
pass pass