PlexKodiConnect/resources/lib/ReadEmbyDB.py

286 lines
12 KiB
Python
Raw Normal View History

2015-03-18 04:51:45 +11:00
#################################################################################################
# ReadEmbyDB
#################################################################################################
import xbmc
import xbmcgui
import xbmcaddon
from DownloadUtils import DownloadUtils
2015-03-26 04:37:21 +11:00
addon = xbmcaddon.Addon(id='plugin.video.emby')
2015-03-18 04:51:45 +11:00
class ReadEmbyDB():
2015-04-22 09:12:09 +10:00
def getMovies(self, id, fullinfo = False, fullSync = True, itemList = []):
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
if fullSync:
sortstring = "&SortBy=SortName"
else:
if(len(itemList) > 0): # if we want a certain list specify it
#sortstring = "&Ids=" + ",".join(itemList)
sortstring = "" # work around for now until ParetnId and Id work together
else: # just get the last 20 created items
sortstring = "&Limit=20&SortBy=DateCreated"
2015-03-18 04:51:45 +11:00
if fullinfo:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s%s&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1" % (id, sortstring)
2015-03-18 04:51:45 +11:00
else:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s%s&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1" % (id, sortstring)
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
2015-04-22 09:12:09 +10:00
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-18 04:51:45 +11:00
# work around for now until ParetnId and Id work together
2015-04-22 09:12:09 +10:00
if (result != None and len(result) > 0 and len(itemList) > 0):
newResult = []
for item in result:
2015-04-22 09:12:09 +10:00
if (item[u'Id'] in itemList):
newResult.append(item)
result = newResult
2015-03-18 04:51:45 +11:00
return result
2015-03-22 00:31:30 +11:00
def getMusicVideos(self, fullinfo = False, fullSync = True):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-22 00:31:30 +11:00
if not fullSync:
sortstring = "&Limit=20&SortBy=DateCreated"
else:
sortstring = "&SortBy=SortName"
if fullinfo:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/items?%s&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=MusicVideo&format=json&ImageTypeLimit=1" % sortstring
2015-03-22 00:31:30 +11:00
else:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/items?%s&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=MusicVideo&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1" % sortstring
2015-03-22 00:31:30 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-22 00:31:30 +11:00
return result
2015-03-20 04:40:29 +11:00
def getItem(self, id):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-20 04:40:29 +11:00
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % id
jsonData = doUtils.downloadUrl(url)
if (jsonData != ""):
result = jsonData
2015-03-20 04:40:29 +11:00
return result
2015-03-26 01:00:08 +11:00
def getFullItem(self, id):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-26 01:00:08 +11:00
2015-04-22 09:12:09 +10:00
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)
if (jsonData != ""):
result = jsonData
2015-03-26 01:00:08 +11:00
return result
2015-04-05 07:48:02 +10:00
def getTVShows(self, id, fullinfo = False, fullSync = False):
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
if not fullSync:
sortstring = "&Limit=20&SortBy=DateCreated"
else:
sortstring = "&SortBy=SortName"
2015-03-18 04:51:45 +11:00
if fullinfo:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s%s&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1" % (id, sortstring)
2015-03-18 04:51:45 +11:00
else:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s%s&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1" % (id, sortstring)
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-20 08:31:06 +11:00
return result
def getTVShowSeasons(self, tvShowId):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-20 08:31:06 +11:00
2015-04-22 09:12:09 +10:00
url = "{server}/Shows/%s/Seasons?UserId={UserId}&format=json&ImageTypeLimit=1" % tvShowId
2015-03-20 08:31:06 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-18 04:51:45 +11:00
return result
2015-03-18 04:51:45 +11:00
def getEpisodes(self, showId, fullinfo = False):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-18 04:51:45 +11:00
if fullinfo:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % showId
2015-03-18 04:51:45 +11:00
else:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % showId
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-18 04:51:45 +11:00
return result
def getLatestEpisodes(self, fullinfo = False, itemList = []):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
limitString = "Limit=20&SortBy=DateCreated&"
if(len(itemList) > 0): # if we want a certain list specify it
limitString = "Ids=" + ",".join(itemList) + "&"
if fullinfo:
2015-04-22 09:12:09 +10:00
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&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString
else:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?%sIsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1" % limitString
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result
2015-03-18 04:51:45 +11:00
def getCollections(self, type):
#Build a list of the user views
downloadUtils = DownloadUtils()
try:
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items/Root?format=json"
result = downloadUtils.downloadUrl(url)
except Exception, msg:
2015-04-22 09:12:09 +10:00
error = "Can't connect: %s" % msg
xbmc.log(error)
return []
2015-04-22 09:12:09 +10:00
if (result == ""):
return []
2015-04-22 09:12:09 +10:00
parentid = result[u'Id']
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s&Sortby=SortName&format=json" % parentid
result = downloadUtils.downloadUrl(url)
collections=[]
2015-04-22 09:12:09 +10:00
if (result == ""):
return []
2015-04-22 09:12:09 +10:00
result = result[u'Items']
for item in result:
2015-04-22 09:12:09 +10:00
if (item[u'RecursiveItemCount'] != 0):
Name = item[u'Name']
itemtype = item[u'CollectionType']
if itemtype == None or itemtype == "":
itemtype = "movies" # User may not have declared the type
2015-04-22 09:12:09 +10:00
if itemtype == type and Name != "Collections":
collections.append({'title': Name,
'type' : itemtype,
'id' : item[u'Id']})
return collections
def getViewCollections(self, type):
#Build a list of the user views
2015-04-22 09:12:09 +10:00
doUtils = DownloadUtils()
viewsUrl = "{server}/mediabrowser/Users/{UserId}/Views?format=json&ImageTypeLimit=1"
jsonData = doUtils.downloadUrl(viewsUrl)
collections=[]
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
if (jsonData != ""):
views = views[u'Items']
2015-03-18 04:51:45 +11:00
for view in views:
2015-04-22 09:12:09 +10:00
if (view[u'Type'] == 'UserView'): # Need to grab the real main node
newViewsUrl = "{server}/mediabrowser/Users/{UserId}/items?ParentId=%s&SortBy=SortName&SortOrder=Ascending&format=json&ImageTypeLimit=1" % view[u'Id']
jsonData = doUtils.downloadUrl(newViewsUrl)
if (jsonData != ""):
newViews = newViews[u'Items']
2015-03-18 04:51:45 +11:00
for newView in newViews:
# There are multiple nodes in here like 'Latest', 'NextUp' - below we grab the full node.
2015-04-22 09:12:09 +10:00
if newView[u'CollectionType'] == "MovieMovies" or newView[u'CollectionType'] == "TvShowSeries":
2015-03-18 04:51:45 +11:00
view=newView
2015-04-22 09:12:09 +10:00
if (view[u'ChildCount'] != 0):
Name = view[u'Name']
2015-03-18 04:51:45 +11:00
2015-04-22 09:12:09 +10:00
total = str(view[u'ChildCount'])
type = view[u'CollectionType']
2015-03-18 04:51:45 +11:00
if type == None:
type = "None" # User may not have declared the type
if type == type:
collections.append({'title': Name,
'type' : type,
'id' : view[u'Id']})
2015-03-18 04:51:45 +11:00
return collections
2015-03-25 03:47:26 +11:00
def getBoxSets(self):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-25 03:47:26 +11:00
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?SortBy=SortName&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=BoxSet&format=json&ImageTypeLimit=1"
2015-03-25 03:47:26 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
2015-03-25 03:47:26 +11:00
return result
def getMoviesInBoxSet(self,boxsetId):
2015-04-22 09:12:09 +10:00
result = None
doUtils = DownloadUtils()
2015-03-25 03:47:26 +11:00
2015-04-22 09:12:09 +10:00
url = "{server}/mediabrowser/Users/{UserId}/Items?ParentId=%s&Fields=ItemCounts&format=json&ImageTypeLimit=1" % boxsetId
2015-03-25 03:47:26 +11:00
2015-04-22 09:12:09 +10:00
jsonData = doUtils.downloadUrl(url)
if (jsonData == ""):
return result
if (jsonData[u'Items'] != ""):
result = jsonData[u'Items']
return result