2015-12-25 06:51:47 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-02-09 08:24:35 +11:00
|
|
|
import xbmc
|
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
import utils
|
|
|
|
import clientinfo
|
|
|
|
import downloadutils
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
class Read_EmbyServer():
|
|
|
|
|
2015-12-27 18:05:51 +11:00
|
|
|
limitIndex = int(utils.settings('limitindex'))
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
window = utils.window
|
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
self.clientInfo = clientinfo.ClientInfo()
|
|
|
|
self.addonName = self.clientInfo.getAddonName()
|
2016-02-09 08:24:35 +11:00
|
|
|
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
self.userId = window('emby_currUser')
|
|
|
|
self.server = window('emby_server%s' % self.userId)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
def logMsg(self, msg, lvl=1):
|
|
|
|
|
|
|
|
className = self.__class__.__name__
|
|
|
|
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
|
|
|
|
|
|
|
|
|
|
|
|
def split_list(self, itemlist, size):
|
|
|
|
# Split up list in pieces of size. Will generate a list of lists
|
|
|
|
return [itemlist[i:i+size] for i in range(0, len(itemlist), size)]
|
|
|
|
|
|
|
|
|
|
|
|
def getItem(self, itemid):
|
|
|
|
# This will return the full item
|
|
|
|
item = {}
|
|
|
|
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url)
|
2015-12-25 06:51:47 +11:00
|
|
|
if result:
|
|
|
|
item = result
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
|
|
|
def getItems(self, itemlist):
|
|
|
|
|
|
|
|
items = []
|
|
|
|
|
|
|
|
itemlists = self.split_list(itemlist, 50)
|
|
|
|
for itemlist in itemlists:
|
|
|
|
# Will return basic information
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?&format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Ids': ",".join(itemlist),
|
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url, parameters=params)
|
2015-12-25 06:51:47 +11:00
|
|
|
if result:
|
|
|
|
items.extend(result['Items'])
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getFullItems(self, itemlist):
|
|
|
|
|
|
|
|
items = []
|
|
|
|
|
|
|
|
itemlists = self.split_list(itemlist, 50)
|
|
|
|
for itemlist in itemlists:
|
|
|
|
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
"Ids": ",".join(itemlist),
|
|
|
|
"Fields": (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
2016-01-14 19:59:02 +11:00
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
|
|
|
"MediaSources"
|
2015-12-25 06:51:47 +11:00
|
|
|
)
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url, parameters=params)
|
2015-12-25 06:51:47 +11:00
|
|
|
if result:
|
|
|
|
items.extend(result['Items'])
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getView_embyId(self, itemid):
|
|
|
|
# Returns ancestors using embyId
|
|
|
|
viewId = None
|
|
|
|
url = "{server}/emby/Items/%s/Ancestors?UserId={UserId}&format=json" % itemid
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
for view in result:
|
|
|
|
|
|
|
|
viewtype = view['Type']
|
|
|
|
if viewtype == "CollectionFolder":
|
|
|
|
# Found view
|
|
|
|
viewId = view['Id']
|
|
|
|
|
|
|
|
# Compare to view table in emby database
|
|
|
|
emby = utils.kodiSQL('emby')
|
|
|
|
cursor_emby = emby.cursor()
|
|
|
|
query = ' '.join((
|
|
|
|
|
|
|
|
"SELECT view_name, media_type",
|
|
|
|
"FROM view",
|
|
|
|
"WHERE view_id = ?"
|
|
|
|
))
|
|
|
|
cursor_emby.execute(query, (viewId,))
|
|
|
|
result = cursor_emby.fetchone()
|
|
|
|
try:
|
|
|
|
viewName = result[0]
|
|
|
|
mediatype = result[1]
|
|
|
|
except TypeError:
|
|
|
|
viewName = None
|
|
|
|
mediatype = None
|
|
|
|
|
|
|
|
cursor_emby.close()
|
|
|
|
|
|
|
|
return [viewName, viewId, mediatype]
|
2016-01-13 11:03:35 +11:00
|
|
|
|
|
|
|
def getFilteredSection(self, parentid, itemtype=None, sortby="SortName", recursive=True, limit=None, sortorder="Ascending", filter=""):
|
|
|
|
doUtils = self.doUtils
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
params = {
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-13 11:03:35 +11:00
|
|
|
'ParentId': parentid,
|
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': recursive,
|
|
|
|
'Limit': limit,
|
|
|
|
'SortBy': sortby,
|
|
|
|
'SortOrder': sortorder,
|
|
|
|
'Filters': filter,
|
|
|
|
'Fields': ( "Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
2016-01-20 07:27:58 +11:00
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers")
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
return doUtils(url, parameters=params)
|
2016-01-20 07:27:58 +11:00
|
|
|
|
|
|
|
def getTvChannels(self):
|
|
|
|
doUtils = self.doUtils
|
|
|
|
url = "{server}/emby/LiveTv/Channels/?userid={UserId}&format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'EnableImages': True,
|
|
|
|
'Fields': ( "Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers")
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
return doUtils(url, parameters=params)
|
2016-01-20 07:27:58 +11:00
|
|
|
|
|
|
|
def getTvRecordings(self, groupid):
|
|
|
|
doUtils = self.doUtils
|
|
|
|
url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json"
|
|
|
|
if groupid == "root": groupid = ""
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'GroupId': groupid,
|
|
|
|
'EnableImages': True,
|
|
|
|
'Fields': ( "Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
2016-01-13 11:03:35 +11:00
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers")
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
return doUtils(url, parameters=params)
|
2016-01-13 11:03:35 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getSection(self, parentid, itemtype=None, sortby="SortName", basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
log = self.logMsg
|
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
doUtils = self.doUtils
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get total number of items
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = doUtils(url, parameters=params)
|
2015-12-25 06:51:47 +11:00
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
|
|
|
|
|
|
|
except TypeError: # Failed to retrieve
|
2016-02-17 19:13:37 +11:00
|
|
|
log("%s:%s Failed to retrieve the server response." % (url, params), 2)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
else:
|
|
|
|
index = 0
|
|
|
|
jump = self.limitIndex
|
2016-02-08 19:36:09 +11:00
|
|
|
throttled = False
|
|
|
|
highestjump = 0
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
while index < total:
|
|
|
|
# Get items by chunk to increase retrieval speed at scale
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': True,
|
|
|
|
'StartIndex': index,
|
|
|
|
'Limit': jump,
|
|
|
|
'SortBy': sortby,
|
|
|
|
'SortOrder': "Ascending",
|
|
|
|
}
|
|
|
|
if basic:
|
|
|
|
params['Fields'] = "Etag"
|
|
|
|
else:
|
|
|
|
params['Fields'] = (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
2016-01-14 19:59:02 +11:00
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
|
|
|
"MediaSources"
|
2015-12-25 06:51:47 +11:00
|
|
|
)
|
2016-02-08 19:36:09 +11:00
|
|
|
result = doUtils(url, parameters=params)
|
2016-02-09 11:38:41 +11:00
|
|
|
try:
|
|
|
|
items['Items'].extend(result['Items'])
|
|
|
|
except TypeError:
|
|
|
|
# Something happened to the connection
|
2016-02-08 19:36:09 +11:00
|
|
|
if not throttled:
|
|
|
|
throttled = True
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Throttle activated.", 1)
|
2016-02-09 11:38:41 +11:00
|
|
|
|
|
|
|
if jump == highestjump:
|
2016-02-10 15:50:31 +11:00
|
|
|
# We already tried with the highestjump, but it failed. Reset value.
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Reset highest value.", 1)
|
2016-02-08 19:36:09 +11:00
|
|
|
highestjump = 0
|
|
|
|
|
|
|
|
# Lower the number by half
|
|
|
|
if highestjump:
|
|
|
|
throttled = False
|
|
|
|
jump = highestjump
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Throttle deactivated.", 1)
|
2016-02-08 19:36:09 +11:00
|
|
|
else:
|
2016-02-09 11:38:41 +11:00
|
|
|
jump = int(jump/4)
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Set jump limit to recover: %s" % jump, 2)
|
2016-02-08 19:36:09 +11:00
|
|
|
|
|
|
|
retry = 0
|
|
|
|
while utils.window('emby_online') != "true":
|
|
|
|
# Wait server to come back online
|
2016-03-07 10:21:29 +11:00
|
|
|
if retry == 5:
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Unable to reconnect to server. Abort process.", 1)
|
2016-03-07 10:21:29 +11:00
|
|
|
return items
|
2016-02-09 11:38:41 +11:00
|
|
|
|
2016-02-08 19:36:09 +11:00
|
|
|
retry += 1
|
|
|
|
if xbmc.Monitor().waitForAbort(1):
|
|
|
|
# Abort was requested while waiting.
|
2016-03-07 10:21:29 +11:00
|
|
|
return items
|
2016-02-08 19:36:09 +11:00
|
|
|
else:
|
2016-02-09 11:38:41 +11:00
|
|
|
# Request succeeded
|
2016-02-08 19:36:09 +11:00
|
|
|
index += jump
|
|
|
|
|
|
|
|
if dialog:
|
|
|
|
percentage = int((float(index) / float(total))*100)
|
|
|
|
dialog.update(percentage)
|
|
|
|
|
|
|
|
if jump > highestjump:
|
|
|
|
# Adjust with the latest number, if it's greater
|
|
|
|
highestjump = jump
|
|
|
|
|
|
|
|
if throttled:
|
2016-02-09 11:38:41 +11:00
|
|
|
# We needed to adjust the number of item requested.
|
|
|
|
# keep increasing until the connection times out again
|
|
|
|
# to find the highest value
|
|
|
|
increment = int(jump*0.33)
|
|
|
|
if not increment: # Incase the increment is 0
|
|
|
|
increment = 10
|
|
|
|
|
|
|
|
jump += increment
|
2016-02-17 19:13:37 +11:00
|
|
|
log("Increase jump limit to: %s" % jump, 1)
|
2015-12-25 06:51:47 +11:00
|
|
|
return items
|
|
|
|
|
2016-02-25 15:28:42 +11:00
|
|
|
def getViews(self, mediatype="", root=False, sortedlist=False):
|
2015-12-25 06:51:47 +11:00
|
|
|
# Build a list of user views
|
|
|
|
doUtils = self.doUtils
|
|
|
|
views = []
|
2016-02-25 15:28:42 +11:00
|
|
|
mediatype = mediatype.lower()
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
if not root:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Views?format=json"
|
|
|
|
else: # Views ungrouped
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?Sortby=SortName&format=json"
|
|
|
|
|
2016-02-09 08:24:35 +11:00
|
|
|
result = doUtils(url)
|
2015-12-25 06:51:47 +11:00
|
|
|
try:
|
|
|
|
items = result['Items']
|
|
|
|
except TypeError:
|
2016-02-25 15:28:42 +11:00
|
|
|
self.logMsg("Error retrieving views for type: %s" % mediatype, 2)
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
|
|
|
for item in items:
|
|
|
|
|
|
|
|
name = item['Name']
|
|
|
|
itemId = item['Id']
|
|
|
|
viewtype = item['Type']
|
|
|
|
|
|
|
|
if viewtype == "Channel":
|
|
|
|
# Filter view types
|
|
|
|
continue
|
|
|
|
|
2016-03-05 10:23:07 +11:00
|
|
|
# 3/4/2016 OriginalCollectionType is added
|
|
|
|
itemtype = item.get('OriginalCollectionType', item.get('CollectionType', "mixed"))
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
# 11/29/2015 Remove this once OriginalCollectionType is added to stable server.
|
|
|
|
# Assumed missing is mixed then.
|
2016-03-05 10:23:07 +11:00
|
|
|
'''if itemtype is None:
|
2015-12-25 06:51:47 +11:00
|
|
|
url = "{server}/emby/Library/MediaFolders?format=json"
|
2016-02-09 08:24:35 +11:00
|
|
|
result = doUtils(url)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
for folder in result['Items']:
|
|
|
|
if itemId == folder['Id']:
|
2016-03-05 10:23:07 +11:00
|
|
|
itemtype = folder.get('CollectionType', "mixed")'''
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-25 15:28:42 +11:00
|
|
|
if name not in ('Collections', 'Trailers'):
|
|
|
|
|
|
|
|
if sortedlist:
|
|
|
|
views.append({
|
|
|
|
|
|
|
|
'name': name,
|
|
|
|
'type': itemtype,
|
|
|
|
'id': itemId
|
|
|
|
})
|
|
|
|
|
|
|
|
elif (itemtype == mediatype or
|
|
|
|
(itemtype == "mixed" and mediatype in ("movies", "tvshows"))):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-25 15:28:42 +11:00
|
|
|
views.append({
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-25 15:28:42 +11:00
|
|
|
'name': name,
|
|
|
|
'type': itemtype,
|
|
|
|
'id': itemId
|
|
|
|
})
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return views
|
|
|
|
|
2016-03-02 11:00:19 +11:00
|
|
|
def verifyView(self, parentid, itemid):
|
|
|
|
|
|
|
|
belongs = False
|
|
|
|
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': True,
|
|
|
|
'Ids': itemid
|
|
|
|
}
|
|
|
|
result = self.doUtils(url, parameters=params)
|
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
except TypeError:
|
|
|
|
# Something happened to the connection
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if total:
|
|
|
|
belongs = True
|
|
|
|
|
|
|
|
return belongs
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getMovies(self, parentId, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(parentId, "Movie", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getBoxset(self, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(None, "BoxSet", dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getMovies_byBoxset(self, boxsetid):
|
|
|
|
|
2015-12-26 14:36:46 +11:00
|
|
|
items = self.getSection(boxsetid, "Movie")
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getMusicVideos(self, parentId, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(parentId, "MusicVideo", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getHomeVideos(self, parentId):
|
|
|
|
|
|
|
|
items = self.getSection(parentId, "Video")
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getShows(self, parentId, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(parentId, "Series", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getSeasons(self, showId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url, parameters=params)
|
2015-12-25 06:51:47 +11:00
|
|
|
if result:
|
|
|
|
items = result
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getEpisodes(self, parentId, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(parentId, "Episode", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getEpisodesbyShow(self, showId):
|
|
|
|
|
|
|
|
items = self.getSection(showId, "Episode")
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getEpisodesbySeason(self, seasonId):
|
|
|
|
|
|
|
|
items = self.getSection(seasonId, "Episode")
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getArtists(self, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
doUtils = self.doUtils
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get total number of items
|
|
|
|
url = "{server}/emby/Artists?UserId={UserId}&format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = doUtils(url, parameters=params)
|
2015-12-25 06:51:47 +11:00
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
|
|
|
|
|
|
|
except TypeError: # Failed to retrieve
|
|
|
|
self.logMsg("%s:%s Failed to retrieve the server response." % (url, params), 2)
|
|
|
|
|
|
|
|
else:
|
|
|
|
index = 1
|
|
|
|
jump = self.limitIndex
|
|
|
|
|
|
|
|
while index < total:
|
|
|
|
# Get items by chunk to increase retrieval speed at scale
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Recursive': True,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'StartIndex': index,
|
|
|
|
'Limit': jump,
|
|
|
|
'SortBy': "SortName",
|
|
|
|
'SortOrder': "Ascending",
|
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Etag,Genres,SortName,Studios,Writer,ProductionYear,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,"
|
|
|
|
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview"
|
|
|
|
)
|
|
|
|
}
|
2016-02-09 08:24:35 +11:00
|
|
|
result = doUtils(url, parameters=params)
|
2016-01-19 21:28:52 +11:00
|
|
|
items['Items'].extend(result['Items'])
|
|
|
|
|
|
|
|
index += jump
|
|
|
|
if dialog:
|
|
|
|
percentage = int((float(index) / float(total))*100)
|
|
|
|
dialog.update(percentage)
|
2015-12-25 06:51:47 +11:00
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getAlbums(self, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(None, "MusicAlbum", sortby="DateCreated", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getAlbumsbyArtist(self, artistId):
|
|
|
|
|
|
|
|
items = self.getSection(artistId, "MusicAlbum", sortby="DateCreated")
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
def getSongs(self, basic=False, dialog=None):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-01-18 20:23:56 +11:00
|
|
|
items = self.getSection(None, "Audio", basic=basic, dialog=dialog)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getSongsbyAlbum(self, albumId):
|
|
|
|
|
|
|
|
items = self.getSection(albumId, "Audio")
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getAdditionalParts(self, itemId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
|
2016-02-09 08:24:35 +11:00
|
|
|
result = self.doUtils(url)
|
2015-12-25 06:51:47 +11:00
|
|
|
if result:
|
|
|
|
items = result
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def sortby_mediatype(self, itemids):
|
|
|
|
|
|
|
|
sorted_items = {}
|
|
|
|
|
|
|
|
# Sort items
|
|
|
|
items = self.getFullItems(itemids)
|
|
|
|
for item in items:
|
|
|
|
|
|
|
|
mediatype = item.get('Type')
|
|
|
|
if mediatype:
|
|
|
|
sorted_items.setdefault(mediatype, []).append(item)
|
|
|
|
|
2016-03-17 15:17:44 +11:00
|
|
|
return sorted_items
|
|
|
|
|
|
|
|
def updateUserRating(self, itemid, like=None, favourite=None, deletelike=False):
|
|
|
|
# Updates the user rating to Emby
|
|
|
|
doUtils = self.doUtils
|
|
|
|
|
|
|
|
if favourite:
|
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, type="POST")
|
|
|
|
elif favourite == False:
|
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, type="DELETE")
|
|
|
|
|
|
|
|
if not deletelike and like:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=true&format=json" % itemid
|
|
|
|
doUtils(url, type="POST")
|
|
|
|
elif not deletelike and like == False:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=false&format=json" % itemid
|
|
|
|
doUtil(url, type="POST")
|
|
|
|
elif deletelike:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items/%s/Rating?format=json" % itemid
|
|
|
|
doUtils(url, type="DELETE")
|
|
|
|
|
|
|
|
self.logMsg("Update user rating to emby for itemid: %s "
|
|
|
|
"| like: %s | favourite: %s | deletelike: %s"
|
|
|
|
% (itemid, like, favourite, deletelike), 1)
|