better handling of no server, server off line or sever restarting scenarios

This commit is contained in:
Shaun 2017-12-22 11:40:49 +11:00
parent f591d16190
commit 2317d9b055
6 changed files with 35 additions and 33 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.4.7"
version="1.4.8"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.24.0"/>

View File

@ -543,7 +543,7 @@ msgid "Your skin %s is currently not supported"
msgstr ""
msgctxt "#30282"
msgid "No servers detected"
msgid "No Emby servers on your local network detected"
msgstr ""
msgctxt "#30283"

View File

@ -285,11 +285,15 @@ class DownloadUtils():
def downloadUrl(self, url, suppress=False, postBody=None, method="GET", popup=0, authenticate=True, headers=None):
log.debug("downloadUrl")
return_data = "null"
settings = xbmcaddon.Addon(id='plugin.video.embycon')
log.debug(url)
if url.find("{server}") != -1:
server = self.getServer()
if server is None:
return return_data
url = url.replace("{server}", server)
if url.find("{userid}") != -1:
userid = self.getUserId()
@ -315,7 +319,6 @@ class DownloadUtils():
url = url.replace("{,IsUnplayed,}", ",IsUnplayed,")
log.debug(url)
return_data = "null"
try:
if url.startswith('http'):
serversplit = 2

View File

@ -35,21 +35,21 @@ def showGenreList(item_type=None):
emby_type = "Series"
kodi_type = "tvshows"
try:
jsonData = downloadUtils.downloadUrl("{server}/emby/Genres?" +
"SortBy=SortName" +
"&SortOrder=Ascending" +
"&IncludeItemTypes=" + emby_type +
"&Recursive=true" +
"&UserId={userid}" +
"&format=json")
log.debug("GENRE_LIST_DATA : " + jsonData)
except Exception, msg:
error = "Get connect : " + str(msg)
log.error(error)
jsonData = downloadUtils.downloadUrl("{server}/emby/Genres?" +
"SortBy=SortName" +
"&SortOrder=Ascending" +
"&IncludeItemTypes=" + emby_type +
"&Recursive=true" +
"&UserId={userid}" +
"&format=json")
log.debug("GENRE_LIST_DATA : %s" % jsonData)
result = json.loads(jsonData)
result = result.get("Items")
if result is not None:
result = result.get("Items")
else:
result = []
collections = []
@ -134,10 +134,13 @@ def showYearsList():
"&Recursive=true" +
"&UserId={userid}" +
"&format=json")
log.debug("YEAR_LIST_DATA : " + jsonData)
log.debug("YEAR_LIST_DATA : %s" % jsonData)
result = json.loads(jsonData)
result = result.get("Items")
if result is not None:
result = result.get("Items")
else:
result = []
collections = []
@ -220,14 +223,9 @@ def getCollections(detailsString):
log.debug("No userid so returning []")
return []
try:
jsonData = downloadUtils.downloadUrl("{server}/emby/Users/{userid}/Items/Root?format=json")
except Exception, msg:
error = "Get connect : " + str(msg)
log.error(error)
return []
jsonData = downloadUtils.downloadUrl("{server}/emby/Users/{userid}/Items/Root?format=json")
log.debug("jsonData : " + jsonData)
log.debug("jsonData : %s" % jsonData)
result = json.loads(jsonData)
if result is None:
return []
@ -237,15 +235,14 @@ def getCollections(detailsString):
htmlpath = "{server}/emby/Users/{userid}/items?ParentId=" + parentid + "&Sortby=SortName&format=json"
jsonData = downloadUtils.downloadUrl(htmlpath)
log.debug("jsonData : " + jsonData)
log.debug("jsonData : %s" % jsonData)
collections = []
result = []
try:
result = json.loads(jsonData)
result = json.loads(jsonData)
if result is not None:
result = result.get("Items")
except Exception as error:
log.error("Error parsing user collection: " + str(error))
else:
result = []
for item in result:
item_name = (item.get("Name")).encode('utf-8')

View File

@ -241,10 +241,12 @@ class WebSocketClient(threading.Thread):
if self._stop_websocket:
break
if self.monitor.waitForAbort(5):
if self.monitor.waitForAbort(20):
# Abort was requested, exit
break
log.debug("Reconnecting WebSocket")
log.debug("WebSocketClient Stopped")
def stop_client(self):

View File

@ -208,7 +208,7 @@ def populateWidgetItems(itemsUrl, override_select_action=None):
log.debug("WIDGET_DATE_URL: " + itemsUrl)
# get the items
jsonData = downloadUtils.downloadUrl(itemsUrl, suppress=False, popup=1)
jsonData = downloadUtils.downloadUrl(itemsUrl, suppress=False)
log.debug("Widget(Items) jsonData: " + jsonData)
result = json.loads(jsonData)