2016-03-31 18:13:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
import xbmc
|
|
|
|
|
|
|
|
import downloadutils
|
2016-07-24 08:59:48 +00:00
|
|
|
from utils import window, settings, kodiSQL
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
class Read_EmbyServer():
|
|
|
|
|
2016-06-16 05:43:36 +00:00
|
|
|
limitIndex = int(settings('limitindex'))
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
|
|
|
|
|
|
|
self.userId = window('emby_currUser')
|
|
|
|
self.server = window('emby_server%s' % self.userId)
|
|
|
|
|
|
|
|
|
|
|
|
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 = {}
|
|
|
|
|
2016-04-15 20:01:12 +00:00
|
|
|
result = self.doUtils("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid)
|
2016-03-31 18:13:26 +00: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
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Ids': ",".join(itemlist),
|
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/Items?&format=json"
|
|
|
|
result = self.doUtils(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
if result:
|
|
|
|
items.extend(result['Items'])
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getFullItems(self, itemlist):
|
|
|
|
|
|
|
|
items = []
|
|
|
|
|
|
|
|
itemlists = self.split_list(itemlist, 50)
|
|
|
|
for itemlist in itemlists:
|
|
|
|
|
|
|
|
params = {
|
|
|
|
|
|
|
|
"Ids": ",".join(itemlist),
|
|
|
|
"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-04-24 00:14:21 +00:00
|
|
|
"MediaSources,VoteCount"
|
2016-03-31 18:13:26 +00:00
|
|
|
)
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
result = self.doUtils(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
if result:
|
|
|
|
items.extend(result['Items'])
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getView_embyId(self, itemid):
|
|
|
|
# Returns ancestors using embyId
|
|
|
|
viewId = None
|
|
|
|
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Items/%s/Ancestors?UserId={UserId}&format=json" % itemid
|
|
|
|
for view in self.doUtils(url):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
if view['Type'] == "CollectionFolder":
|
|
|
|
# Found view
|
|
|
|
viewId = view['Id']
|
|
|
|
|
|
|
|
# Compare to view table in emby database
|
2016-06-16 05:43:36 +00:00
|
|
|
emby = kodiSQL('emby')
|
2016-03-31 18:13:26 +00:00
|
|
|
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-06-16 05:43:36 +00:00
|
|
|
def getFilteredSection(self, parentid, itemtype=None, sortby="SortName", recursive=True,
|
|
|
|
limit=None, sortorder="Ascending", filter=""):
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': recursive,
|
|
|
|
'Limit': limit,
|
|
|
|
'SortBy': sortby,
|
|
|
|
'SortOrder': sortorder,
|
|
|
|
'Filters': filter,
|
2016-06-16 05:43:36 +00:00
|
|
|
'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-03-31 18:13:26 +00:00
|
|
|
}
|
2016-03-31 18:18:49 +00:00
|
|
|
return self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getTvChannels(self):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'EnableImages': True,
|
2016-06-16 05:43:36 +00:00
|
|
|
'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-03-31 18:13:26 +00:00
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/LiveTv/Channels/?userid={UserId}&format=json"
|
|
|
|
return self.doUtils(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getTvRecordings(self, groupid):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
|
|
|
if groupid == "root":
|
|
|
|
groupid = ""
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'GroupId': groupid,
|
|
|
|
'EnableImages': True,
|
2016-06-16 05:43:36 +00:00
|
|
|
'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-03-31 18:13:26 +00:00
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json"
|
|
|
|
return self.doUtils(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSection(self, parentid, itemtype=None, sortby="SortName", basic=False, dialog=None):
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
result = self.doUtils(url, parameters=params)
|
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
|
|
|
|
|
|
|
except TypeError: # Failed to retrieve
|
2016-07-24 08:59:48 +00:00
|
|
|
log.debug("%s:%s Failed to retrieve the server response." % (url, params))
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
index = 0
|
|
|
|
jump = self.limitIndex
|
|
|
|
throttled = False
|
|
|
|
highestjump = 0
|
|
|
|
|
|
|
|
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,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
2016-04-24 00:11:29 +00:00
|
|
|
"MediaSources,VoteCount"
|
2016-03-31 18:13:26 +00:00
|
|
|
)
|
|
|
|
result = self.doUtils(url, parameters=params)
|
|
|
|
try:
|
|
|
|
items['Items'].extend(result['Items'])
|
|
|
|
except TypeError:
|
|
|
|
# Something happened to the connection
|
|
|
|
if not throttled:
|
|
|
|
throttled = True
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Throttle activated.")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
if jump == highestjump:
|
|
|
|
# We already tried with the highestjump, but it failed. Reset value.
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Reset highest value.")
|
2016-03-31 18:13:26 +00:00
|
|
|
highestjump = 0
|
|
|
|
|
|
|
|
# Lower the number by half
|
|
|
|
if highestjump:
|
|
|
|
throttled = False
|
|
|
|
jump = highestjump
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Throttle deactivated.")
|
2016-03-31 18:13:26 +00:00
|
|
|
else:
|
|
|
|
jump = int(jump/4)
|
2016-07-24 08:59:48 +00:00
|
|
|
log.debug("Set jump limit to recover: %s" % jump)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
retry = 0
|
2016-06-16 05:43:36 +00:00
|
|
|
while window('emby_online') != "true":
|
2016-03-31 18:13:26 +00:00
|
|
|
# Wait server to come back online
|
|
|
|
if retry == 5:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Unable to reconnect to server. Abort process.")
|
2016-03-31 18:13:26 +00:00
|
|
|
return items
|
|
|
|
|
|
|
|
retry += 1
|
|
|
|
if xbmc.Monitor().waitForAbort(1):
|
|
|
|
# Abort was requested while waiting.
|
|
|
|
return items
|
|
|
|
else:
|
|
|
|
# Request succeeded
|
|
|
|
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:
|
|
|
|
# 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-07-24 08:59:48 +00:00
|
|
|
log.info("Increase jump limit to: %s" % jump)
|
2016-03-31 18:13:26 +00:00
|
|
|
return items
|
|
|
|
|
|
|
|
def getViews(self, mediatype="", root=False, sortedlist=False):
|
|
|
|
# Build a list of user views
|
|
|
|
views = []
|
|
|
|
mediatype = mediatype.lower()
|
|
|
|
|
|
|
|
if not root:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Views?format=json"
|
|
|
|
else: # Views ungrouped
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?Sortby=SortName&format=json"
|
|
|
|
|
|
|
|
result = self.doUtils(url)
|
|
|
|
try:
|
|
|
|
items = result['Items']
|
|
|
|
except TypeError:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.debug("Error retrieving views for type: %s" % mediatype)
|
2016-03-31 18:13:26 +00:00
|
|
|
else:
|
|
|
|
for item in items:
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
item['Name'] = item['Name']
|
|
|
|
if item['Type'] == "Channel":
|
2016-03-31 18:13:26 +00:00
|
|
|
# Filter view types
|
|
|
|
continue
|
|
|
|
|
|
|
|
# 3/4/2016 OriginalCollectionType is added
|
|
|
|
itemtype = item.get('OriginalCollectionType', item.get('CollectionType', "mixed"))
|
|
|
|
|
|
|
|
# 11/29/2015 Remove this once OriginalCollectionType is added to stable server.
|
|
|
|
# Assumed missing is mixed then.
|
|
|
|
'''if itemtype is None:
|
|
|
|
url = "{server}/emby/Library/MediaFolders?format=json"
|
|
|
|
result = self.doUtils(url)
|
|
|
|
|
|
|
|
for folder in result['Items']:
|
2016-03-31 18:35:23 +00:00
|
|
|
if item['Id'] == folder['Id']:
|
2016-03-31 18:13:26 +00:00
|
|
|
itemtype = folder.get('CollectionType', "mixed")'''
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
if item['Name'] not in ('Collections', 'Trailers'):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
if sortedlist:
|
|
|
|
views.append({
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
'name': item['Name'],
|
2016-03-31 18:13:26 +00:00
|
|
|
'type': itemtype,
|
2016-03-31 18:35:23 +00:00
|
|
|
'id': item['Id']
|
2016-03-31 18:13:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
elif (itemtype == mediatype or
|
|
|
|
(itemtype == "mixed" and mediatype in ("movies", "tvshows"))):
|
|
|
|
|
|
|
|
views.append({
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
'name': item['Name'],
|
2016-03-31 18:13:26 +00:00
|
|
|
'type': itemtype,
|
2016-03-31 18:35:23 +00:00
|
|
|
'id': item['Id']
|
2016-03-31 18:13:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return views
|
|
|
|
|
|
|
|
def verifyView(self, parentid, itemid):
|
|
|
|
|
|
|
|
belongs = False
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': True,
|
|
|
|
'Ids': itemid
|
|
|
|
}
|
2016-03-31 18:35:23 +00:00
|
|
|
result = self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
except TypeError:
|
|
|
|
# Something happened to the connection
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if total:
|
|
|
|
belongs = True
|
|
|
|
|
|
|
|
return belongs
|
|
|
|
|
|
|
|
def getMovies(self, parentId, basic=False, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Movie", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getBoxset(self, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "BoxSet", dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getMovies_byBoxset(self, boxsetid):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(boxsetid, "Movie")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getMusicVideos(self, parentId, basic=False, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "MusicVideo", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getHomeVideos(self, parentId):
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Video")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getShows(self, parentId, basic=False, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Series", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSeasons(self, showId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
|
|
|
|
result = self.doUtils(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
if result:
|
|
|
|
items = result
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getEpisodes(self, parentId, basic=False, dialog=None):
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Episode", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getEpisodesbyShow(self, showId):
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(showId, "Episode")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getEpisodesbySeason(self, seasonId):
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(seasonId, "Episode")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getArtists(self, dialog=None):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get total number of items
|
|
|
|
url = "{server}/emby/Artists?UserId={UserId}&format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1
|
|
|
|
}
|
|
|
|
result = self.doUtils(url, parameters=params)
|
|
|
|
try:
|
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
|
|
|
|
|
|
|
except TypeError: # Failed to retrieve
|
2016-07-24 08:59:48 +00:00
|
|
|
log.debug("%s:%s Failed to retrieve the server response." % (url, params))
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
result = self.doUtils(url, parameters=params)
|
|
|
|
items['Items'].extend(result['Items'])
|
|
|
|
|
|
|
|
index += jump
|
|
|
|
if dialog:
|
|
|
|
percentage = int((float(index) / float(total))*100)
|
|
|
|
dialog.update(percentage)
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getAlbums(self, basic=False, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "MusicAlbum", sortby="DateCreated", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getAlbumsbyArtist(self, artistId):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(artistId, "MusicAlbum", sortby="DateCreated")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSongs(self, basic=False, dialog=None):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "Audio", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSongsbyAlbum(self, albumId):
|
|
|
|
|
2016-06-16 05:43:36 +00:00
|
|
|
return self.getSection(albumId, "Audio")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getAdditionalParts(self, itemId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
|
|
|
|
result = self.doUtils(url)
|
2016-03-31 18:13:26 +00: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)
|
|
|
|
|
|
|
|
return sorted_items
|
|
|
|
|
2016-06-20 01:32:09 +00:00
|
|
|
def updateUserRating(self, itemid, favourite=None):
|
2016-03-31 18:13:26 +00:00
|
|
|
# Updates the user rating to Emby
|
2016-06-16 05:43:36 +00:00
|
|
|
doUtils = self.doUtils
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
if favourite:
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, action_type="POST")
|
2016-06-20 01:32:09 +00:00
|
|
|
elif not favourite:
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, action_type="DELETE")
|
2016-04-24 00:11:29 +00:00
|
|
|
else:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Error processing user rating.")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Update user rating to emby for itemid: %s | favourite: %s" % (itemid, favourite))
|
2016-06-20 00:24:42 +00:00
|
|
|
|
|
|
|
def refreshItem(self, itemid):
|
|
|
|
|
|
|
|
url = "{server}/emby/Items/%s/Refresh?format=json" % itemid
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Recursive': True,
|
|
|
|
'ImageRefreshMode': "FullRefresh",
|
|
|
|
'MetadataRefreshMode': "FullRefresh",
|
|
|
|
'ReplaceAllImages': False,
|
|
|
|
'ReplaceAllMetadata': True
|
|
|
|
|
|
|
|
}
|
2016-06-20 01:32:09 +00:00
|
|
|
self.doUtils(url, postBody=params, action_type="POST")
|
|
|
|
|
|
|
|
def deleteItem(self, itemid):
|
|
|
|
|
2016-06-21 20:26:42 +00:00
|
|
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
2016-06-20 01:32:09 +00:00
|
|
|
self.doUtils(url, action_type="DELETE")
|