Fix nodes - forgot the encoding

Also replace none with empty dictionary for getItem
This commit is contained in:
angelblue05 2015-08-03 04:45:23 -05:00
parent d548ab6e27
commit 3aa2598c79
2 changed files with 128 additions and 284 deletions

View File

@ -1,354 +1,230 @@
# -*- coding: utf-8 -*-
################################################################################################# #################################################################################################
# ReadEmbyDB # ReadEmbyDB
################################################################################################# #################################################################################################
import xbmc
import xbmcgui
import xbmcaddon
from DownloadUtils import DownloadUtils from DownloadUtils import DownloadUtils
addon = xbmcaddon.Addon(id='plugin.video.emby')
class ReadEmbyDB(): class ReadEmbyDB():
doUtils = DownloadUtils()
def getMovies(self, id, itemList = []): def getMovies(self, parentId, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils() url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&SortBy=SortName&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&ImageTypeLimit=1&format=json" % parentId
# Process itemList if any
#only get basic info for our sync-compares if itemList:
sortstring = "&SortBy=SortName" url = "%s&Ids=%s" % (url, ",".join(itemList))
url = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s%s&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1" % (id, sortstring) jsondata = self.doUtils.downloadUrl(url)
if itemList != [] and len(itemList) < 50: if jsondata:
if len(itemList) == 1: result = jsondata['Items']
Ids=itemList[0]
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getMusicVideos(self, itemList = []): def getMusicVideos(self, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils() url = "{server}/mediabrowser/Users/{UserId}/items?&SortBy=SortName&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=MusicVideo&CollapseBoxSetItems=false&ImageTypeLimit=1&format=json"
# Process itemList if any
if itemList:
url = "%s&Ids=%s" % (url, ",".join(itemList))
#only get basic info for our sync-compares jsondata = self.doUtils.downloadUrl(url)
sortstring = "&SortBy=SortName" if jsondata:
url = "{server}/mediabrowser/Users/{UserId}/items?%s&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=MusicVideo&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1" % sortstring result = jsondata['Items']
if itemList != [] and len(itemList) < 50:
if len(itemList) == 1:
Ids=itemList[0]
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getMusicArtists(self, itemList = []): def getMusicArtists(self, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils()
#only get basic info for our sync-compares
url = "{server}/Artists?Recursive=true&Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&UserId={UserId}&format=json" url = "{server}/Artists?Recursive=true&Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&UserId={UserId}&format=json"
if itemList != [] and len(itemList) < 50: # Process itemList if any
if len(itemList) == 1: if itemList:
Ids=itemList[0] url = "%s&Ids=%s" % (url, ",".join(itemList))
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData == ""): if jsondata:
return result result = jsondata['Items']
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getMusicSongs(self, itemList = []): def getMusicSongs(self, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils()
#only get basic info for our sync-compares
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=Audio&format=json" url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=Audio&format=json"
if itemList != [] and len(itemList) < 50: if itemList:
if len(itemList) == 1: url = "%s&Ids=%s" % (url, ",".join(itemList))
Ids=itemList[0]
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsondata = self.doUtils.downloadUrl(url)
jsonData = doUtils.downloadUrl(url) if jsondata:
if (jsonData == ""): result = jsondata['Items']
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getMusicAlbums(self, itemList = []): def getMusicAlbums(self, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils()
#only get basic info for our sync-compares
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=MusicAlbum&format=json" url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=MusicAlbum&format=json"
if itemList != [] and len(itemList) < 50: if itemList:
if len(itemList) == 1: url = "%s&Ids=%s" % (url, ",".join(itemList))
Ids=itemList[0]
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData == ""): try:
return result result = jsondata['Items']
except: pass
if (jsonData[u'Items'] != ""): else:
result = jsonData[u'Items']
#only return valid albums - which have artists
tempresult = [] tempresult = []
# Only return valid albums - which have artists
for item in result: for item in result:
if item["AlbumArtists"]: if item['AlbumArtists']:
tempresult.append(item) tempresult.append(item)
result = tempresult result = tempresult
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getItem(self, id): def getItem(self, id):
result = None result = {}
doUtils = DownloadUtils()
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1&Fields=Etag" % id url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1&Fields=Etag" % id
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData != ""): if jsondata:
result = jsonData result = jsondata
return result return result
def getFullItem(self, id): def getFullItem(self, id):
result = None result = {}
doUtils = DownloadUtils()
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview" % id url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview" % id
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData != ""): if jsondata:
result = jsonData result = jsondata
return result return result
def getTvShows(self, id, itemList = []): def getTvShows(self, parentId, itemList = []):
# Only get basic info for our sync-compares
result = [] result = []
doUtils = DownloadUtils()
#only get basic info for our sync-compares
sortstring = "&SortBy=SortName"
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s%s&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1" % (id, sortstring)
if itemList != [] and len(itemList) < 50:
if len(itemList) == 1:
Ids=itemList[0]
else:
Ids=",".join(itemList)
url = url + "&Ids=" + Ids
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""): url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&SortBy=SortName&Fields=CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1" % parentId
result = jsonData[u'Items'] if itemList:
url = "%s&Ids=%s" % (url, ",".join(itemList))
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50): jsondata = self.doUtils.downloadUrl(url)
newResult = [] if jsondata:
for item in result: result = jsondata['Items']
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getTVShowSeasons(self, tvShowId): def getTVShowSeasons(self, tvShowId):
result = [] result = []
doUtils = DownloadUtils()
url = "{server}/Shows/%s/Seasons?UserId={UserId}&format=json&ImageTypeLimit=1" % tvShowId url = "{server}/Shows/%s/Seasons?UserId={UserId}&format=json&ImageTypeLimit=1" % tvShowId
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData == ""): if jsondata:
return result result = jsondata['Items']
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result return result
def getEpisodes(self, showId, itemList = []): def getEpisodes(self, showId, itemList = []):
result = [] result = []
doUtils = DownloadUtils()
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % showId url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % showId
if itemList != [] and len(itemList) < 50: if itemList:
if len(itemList) == 1: url = "%s&Ids=%s" % (url, ",".join(itemList))
Ids=itemList[0]
else: jsondata = self.doUtils.downloadUrl(url)
Ids=",".join(itemList) if jsondata:
url = url + "&Ids=" + Ids result = jsondata['Items']
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
# Work around to only return items from the given list
if (result != None and len(result) > 0 and len(itemList) > 0 and len(itemList) >= 50):
newResult = []
for item in result:
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
return result return result
def getLatestEpisodes(self, fullinfo = False, itemList = []): def getLatestEpisodes(self, fullinfo = False, itemList = []):
result = [] result = []
doUtils = DownloadUtils()
limitString = "Limit=20&SortBy=DateCreated&" limitString = "Limit=20&SortBy=DateCreated&"
if(len(itemList) > 0): # if we want a certain list specify it if itemList: # if we want a certain list specify it
limitString = "Ids=" + ",".join(itemList) + "&" limitString = "Ids=%s&" % ",".join(itemList)
if fullinfo: if fullinfo:
url = "{server}/mediabrowser/Users/{UserId}/Items?%sIsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString url = "{server}/mediabrowser/Users/{UserId}/Items?%sIsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString
else: else:
url = "{server}/mediabrowser/Users/{UserId}/Items?%sIsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString url = "{server}/mediabrowser/Users/{UserId}/Items?%sIsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString
jsonData = doUtils.downloadUrl(url) jsondata = self.doUtils.downloadUrl(url)
if (jsonData == ""): if jsondata:
return result result = jsondata['Items']
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result return result
def getCollections(self, type): def getCollections(self, type):
#Build a list of the user views # Build a list of the user views
doUtils = DownloadUtils() doUtils = self.doUtils
collections = []
try:
url = "{server}/mediabrowser/Users/{UserId}/Items/Root?format=json" url = "{server}/mediabrowser/Users/{UserId}/Items?Sortby=SortName&format=json"
result = doUtils.downloadUrl(url) jsondata = doUtils.downloadUrl(url)
except Exception, msg:
error = "Can't connect: %s" % msg try:
xbmc.log(error) result = jsondata['Items']
return [] except: pass
else:
if (result == ""): for item in result:
return [] if item['RecursiveItemCount']:
name = item['Name']
itemtype = item.get('CollectionType', "movies")
if itemtype == type and name != "Collections":
collections.append({
'title': name,
'type': itemtype,
'id': item['Id']
})
parentid = result[u'Id']
url = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s&Sortby=SortName&format=json" % parentid
result = doUtils.downloadUrl(url)
collections=[]
if (result == ""):
return []
result = result[u'Items']
for item in result:
if (item[u'RecursiveItemCount'] != 0):
Name = item[u'Name']
if u'CollectionType' not in item:
itemtype = "movies" # User may not have declared the type
else:
itemtype = item[u'CollectionType']
if itemtype == type and Name != "Collections":
collections.append({'title': Name,
'type' : itemtype,
'id' : item[u'Id']})
return collections return collections
def getBoxSets(self):
result = []
url = "{server}/mediabrowser/Users/{UserId}/Items?SortBy=SortName&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Ascending&IncludeItemTypes=BoxSet&format=json&ImageTypeLimit=1"
jsondata = self.doUtils.downloadUrl(url)
if jsondata:
result = jsondata['Items']
return result
def getMoviesInBoxSet(self, boxsetId):
result = []
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&Fields=ItemCounts,Etag&format=json&ImageTypeLimit=1" % boxsetId
jsondata = self.doUtils.downloadUrl(url)
if jsondata:
result = jsondata['Items']
return result
# This is not being used.
# To be removed?
def getViewCollections(self, type): def getViewCollections(self, type):
#Build a list of the user views #Build a list of the user views
doUtils = DownloadUtils() doUtils = DownloadUtils()
@ -390,36 +266,4 @@ class ReadEmbyDB():
collections.append( {'title' : Name, collections.append( {'title' : Name,
'type' : type, 'type' : type,
'id' : view[u'Id']}) 'id' : view[u'Id']})
return collections return collections
def getBoxSets(self):
result = []
doUtils = DownloadUtils()
url = "{server}/mediabrowser/Users/{UserId}/Items?SortBy=SortName&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks,Etag&Recursive=true&SortOrder=Ascending&IncludeItemTypes=BoxSet&format=json&ImageTypeLimit=1"
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result
def getMoviesInBoxSet(self,boxsetId):
result = []
doUtils = DownloadUtils()
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&Fields=ItemCounts,Etag&format=json&ImageTypeLimit=1" % boxsetId
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result

View File

@ -27,7 +27,7 @@ class VideoNodes():
def buildVideoNodeForView(self, tagname, type, windowPropId): def buildVideoNodeForView(self, tagname, type, windowPropId):
#this method will build a video node for a particular Emby view (= tag in kodi) #this method will build a video node for a particular Emby view (= tag in kodi)
#we set some window props here to for easy future reference and to be used in skins (for easy access only) #we set some window props here to for easy future reference and to be used in skins (for easy access only)
tagname_normalized = utils.normalize_nodes(tagname) tagname_normalized = utils.normalize_nodes(tagname.encode('utf-8'))
libraryPath = xbmc.translatePath("special://profile/library/video/Emby - %s/" %tagname_normalized) libraryPath = xbmc.translatePath("special://profile/library/video/Emby - %s/" %tagname_normalized)
kodiVersion = 14 kodiVersion = 14