mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Change to throttle
This commit is contained in:
parent
f793f709ef
commit
9f1cf14cf6
3 changed files with 125 additions and 138 deletions
|
@ -201,7 +201,7 @@
|
||||||
<string id="30512">Force artwork caching</string>
|
<string id="30512">Force artwork caching</string>
|
||||||
<string id="30513">Limit artwork cache threads (recommended for rpi)</string>
|
<string id="30513">Limit artwork cache threads (recommended for rpi)</string>
|
||||||
<string id="30514">Enable fast startup (requires server plugin)</string>
|
<string id="30514">Enable fast startup (requires server plugin)</string>
|
||||||
<string id="30515">Maximum items to request from the server at once</string>
|
<string id="30515">Maximum items to request from the server per download thread</string>
|
||||||
<string id="30516">Video Playback</string>
|
<string id="30516">Video Playback</string>
|
||||||
<string id="30517">Network credentials</string>
|
<string id="30517">Network credentials</string>
|
||||||
<string id="30518">Enable Emby cinema mode</string>
|
<string id="30518">Enable Emby cinema mode</string>
|
||||||
|
@ -234,6 +234,7 @@
|
||||||
<string id="30545">Enable server offline message</string>
|
<string id="30545">Enable server offline message</string>
|
||||||
<string id="30546">Enable analytic metric logging</string>
|
<string id="30546">Enable analytic metric logging</string>
|
||||||
<string id="30547">Display message (in seconds)</string>
|
<string id="30547">Display message (in seconds)</string>
|
||||||
|
<string id="30548">Download threads (recommended: 2-3)</string>
|
||||||
|
|
||||||
<!-- dialogs -->
|
<!-- dialogs -->
|
||||||
<string id="30600">Sign in with Emby Connect</string>
|
<string id="30600">Sign in with Emby Connect</string>
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import threading
|
||||||
|
import Queue
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
|
||||||
|
@ -19,20 +21,74 @@ log = logging.getLogger("EMBY."+__name__)
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadThreader(threading.Thread):
|
||||||
|
|
||||||
|
is_finished = False
|
||||||
|
|
||||||
|
def __init__(self, queue, output):
|
||||||
|
|
||||||
|
self.queue = queue
|
||||||
|
self.output = output
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
try:
|
||||||
|
query = self.queue.get()
|
||||||
|
except Queue.Empty:
|
||||||
|
self.is_finished = True
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = downloadutils.DownloadUtils().downloadUrl(query['url'],
|
||||||
|
parameters=query.get('params'))
|
||||||
|
if result:
|
||||||
|
self.output.extend(result['Items'])
|
||||||
|
except Exception as error:
|
||||||
|
log.error(error)
|
||||||
|
|
||||||
|
self.queue.task_done()
|
||||||
|
self.is_finished = True
|
||||||
|
|
||||||
|
|
||||||
class Read_EmbyServer():
|
class Read_EmbyServer():
|
||||||
|
|
||||||
limitIndex = int(settings('limitindex'))
|
limitIndex = min(int(settings('limitIndex')), 50)
|
||||||
|
download_limit = int(settings('downloadThreads'))
|
||||||
|
download_threads = list()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
self.doUtils = downloadutils.DownloadUtils()
|
||||||
self.userId = window('emby_currUser')
|
self.userId = window('emby_currUser')
|
||||||
self.server = window('emby_server%s' % self.userId)
|
self.server = window('emby_server%s' % self.userId)
|
||||||
|
|
||||||
def get_emby_url(self, handler):
|
def get_emby_url(self, handler):
|
||||||
return "{server}/emby/%s" % handler
|
return "{server}/emby/%s" % handler
|
||||||
|
|
||||||
|
def _add_worker_thread(self, queue, output):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for thread in self.download_threads:
|
||||||
|
if thread.is_finished:
|
||||||
|
self.download_threads.remove(thread)
|
||||||
|
|
||||||
|
if window('emby_online') != "true":
|
||||||
|
# Something happened
|
||||||
|
log.error("Server is not online, don't start new download thread")
|
||||||
|
queue.task_done()
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(self.download_threads) < self.download_limit:
|
||||||
|
# Start new "daemon thread" - actual daemon thread is not supported in Kodi
|
||||||
|
new_thread = DownloadThreader(queue, output)
|
||||||
|
new_thread.start()
|
||||||
|
self.download_threads.append(new_thread)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
log.info("Waiting for empty download spot: %s", len(self.download_threads))
|
||||||
|
xbmc.sleep(100)
|
||||||
|
|
||||||
|
|
||||||
def split_list(self, itemlist, size):
|
def split_list(self, itemlist, size):
|
||||||
# Split up list in pieces of size. Will generate a list of lists
|
# Split up list in pieces of size. Will generate a list of lists
|
||||||
|
@ -43,7 +99,7 @@ class Read_EmbyServer():
|
||||||
item = {}
|
item = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid)
|
result = self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.info("Error getting item from server: " + str(error))
|
log.info("Error getting item from server: " + str(error))
|
||||||
result = None
|
result = None
|
||||||
|
@ -53,41 +109,37 @@ class Read_EmbyServer():
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def getItems(self, itemlist):
|
def getItems(self, item_list):
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
queue = Queue.Queue()
|
||||||
|
|
||||||
itemlists = self.split_list(itemlist, 50)
|
url = "{server}/emby/Users/{UserId}/Items?&format=json"
|
||||||
for itemlist in itemlists:
|
for item_ids in self.split_list(item_list, self.limitIndex):
|
||||||
# Will return basic information
|
# Will return basic information
|
||||||
params = {
|
params = {
|
||||||
|
|
||||||
'Ids': ",".join(itemlist),
|
'Ids': ",".join(item_ids),
|
||||||
'Fields': "Etag"
|
'Fields': "Etag"
|
||||||
}
|
}
|
||||||
url = "{server}/emby/Users/{UserId}/Items?&format=json"
|
queue.put({'url': url, 'params': params})
|
||||||
|
if not self._add_worker_thread(queue, items):
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
queue.join()
|
||||||
result = self.doUtils(url, parameters=params)
|
|
||||||
except Exception as error:
|
|
||||||
log.info("Error getting items form server: " + str(error))
|
|
||||||
result = None
|
|
||||||
|
|
||||||
if result is not None:
|
|
||||||
items.extend(result['Items'])
|
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def getFullItems(self, itemlist):
|
def getFullItems(self, item_list):
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
queue = Queue.Queue()
|
||||||
|
|
||||||
itemlists = self.split_list(itemlist, 50)
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
||||||
for itemlist in itemlists:
|
for item_ids in self.split_list(item_list, self.limitIndex):
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
|
||||||
"Ids": ",".join(itemlist),
|
"Ids": ",".join(item_ids),
|
||||||
"Fields": (
|
"Fields": (
|
||||||
|
|
||||||
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
||||||
|
@ -98,15 +150,11 @@ class Read_EmbyServer():
|
||||||
"MediaSources,VoteCount"
|
"MediaSources,VoteCount"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
queue.put({'url': url, 'params': params})
|
||||||
try:
|
if not self._add_worker_thread(queue, items):
|
||||||
result = self.doUtils(url, parameters=params)
|
break
|
||||||
except Exception as error:
|
|
||||||
log.info("Error getting full items: " + str(error))
|
|
||||||
result = None
|
|
||||||
|
|
||||||
if result is not None:
|
queue.join()
|
||||||
items.extend(result['Items'])
|
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
@ -133,7 +181,7 @@ class Read_EmbyServer():
|
||||||
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers"
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
return self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
||||||
|
|
||||||
def getTvChannels(self):
|
def getTvChannels(self):
|
||||||
|
|
||||||
|
@ -150,7 +198,7 @@ class Read_EmbyServer():
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
url = "{server}/emby/LiveTv/Channels/?userid={UserId}&format=json"
|
url = "{server}/emby/LiveTv/Channels/?userid={UserId}&format=json"
|
||||||
return self.doUtils(url, parameters=params)
|
return self.doUtils.downloadUrl(url, parameters=params)
|
||||||
|
|
||||||
def getTvRecordings(self, groupid):
|
def getTvRecordings(self, groupid):
|
||||||
|
|
||||||
|
@ -171,7 +219,7 @@ class Read_EmbyServer():
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json"
|
url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json"
|
||||||
return self.doUtils(url, parameters=params)
|
return self.doUtils.downloadUrl(url, parameters=params)
|
||||||
|
|
||||||
def getSection(self, parentid, itemtype=None, sortby="SortName", artist_id=None, basic=False, dialog=None):
|
def getSection(self, parentid, itemtype=None, sortby="SortName", artist_id=None, basic=False, dialog=None):
|
||||||
|
|
||||||
|
@ -180,7 +228,6 @@ class Read_EmbyServer():
|
||||||
'Items': [],
|
'Items': [],
|
||||||
'TotalRecordCount': 0
|
'TotalRecordCount': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get total number of items
|
# Get total number of items
|
||||||
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
||||||
params = {
|
params = {
|
||||||
|
@ -195,18 +242,16 @@ class Read_EmbyServer():
|
||||||
'Recursive': True,
|
'Recursive': True,
|
||||||
'Limit': 1
|
'Limit': 1
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils(url, parameters=params)
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
||||||
total = result['TotalRecordCount']
|
total = result['TotalRecordCount']
|
||||||
items['TotalRecordCount'] = total
|
items['TotalRecordCount'] = total
|
||||||
except Exception as error: # Failed to retrieve
|
except Exception as error: # Failed to retrieve
|
||||||
log.debug("%s:%s Failed to retrieve the server response: %s" % (url, params, error))
|
log.debug("%s:%s Failed to retrieve the server response: %s", url, params, error)
|
||||||
else:
|
else:
|
||||||
index = 0
|
index = 0
|
||||||
jump = self.limitIndex
|
jump = self.limitIndex
|
||||||
throttled = False
|
queue = Queue.Queue()
|
||||||
highestjump = 0
|
|
||||||
|
|
||||||
while index < total:
|
while index < total:
|
||||||
# Get items by chunk to increase retrieval speed at scale
|
# Get items by chunk to increase retrieval speed at scale
|
||||||
|
@ -217,6 +262,7 @@ class Read_EmbyServer():
|
||||||
'IncludeItemTypes': itemtype,
|
'IncludeItemTypes': itemtype,
|
||||||
'CollapseBoxSetItems': False,
|
'CollapseBoxSetItems': False,
|
||||||
'IsVirtualUnaired': False,
|
'IsVirtualUnaired': False,
|
||||||
|
'EnableTotalRecordCount': False,
|
||||||
'LocationTypes': "FileSystem,Remote,Offline",
|
'LocationTypes': "FileSystem,Remote,Offline",
|
||||||
'IsMissing': False,
|
'IsMissing': False,
|
||||||
'Recursive': True,
|
'Recursive': True,
|
||||||
|
@ -237,66 +283,20 @@ class Read_EmbyServer():
|
||||||
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
||||||
"MediaSources,VoteCount"
|
"MediaSources,VoteCount"
|
||||||
)
|
)
|
||||||
try:
|
queue.put({'url': url, 'params': params})
|
||||||
result = self.doUtils(url, parameters=params)
|
if not self._add_worker_thread(queue, items['Items']):
|
||||||
items['Items'].extend(result['Items'])
|
break
|
||||||
except Warning as error:
|
|
||||||
if "400" in error:
|
|
||||||
log.info("Something went wrong, aborting request.")
|
|
||||||
index += jump
|
|
||||||
except Exception as error:
|
|
||||||
# Something happened to the connection
|
|
||||||
if not throttled:
|
|
||||||
throttled = True
|
|
||||||
log.info("Throttle activated.")
|
|
||||||
|
|
||||||
if jump == highestjump:
|
|
||||||
# We already tried with the highestjump, but it failed. Reset value.
|
|
||||||
log.info("Reset highest value.")
|
|
||||||
highestjump = 0
|
|
||||||
|
|
||||||
# Lower the number by half
|
index += jump
|
||||||
if highestjump:
|
|
||||||
throttled = False
|
|
||||||
jump = highestjump
|
|
||||||
log.info("Throttle deactivated.")
|
|
||||||
else:
|
|
||||||
jump = int(jump/4)
|
|
||||||
log.debug("Set jump limit to recover: %s" % jump)
|
|
||||||
|
|
||||||
retry = 0
|
|
||||||
while window('emby_online') != "true":
|
|
||||||
# Wait server to come back online
|
|
||||||
if retry == 5:
|
|
||||||
log.info("Unable to reconnect to server. Abort process.")
|
|
||||||
return items
|
|
||||||
|
|
||||||
retry += 1
|
|
||||||
if xbmc.Monitor().waitForAbort(1):
|
|
||||||
# Abort was requested while waiting.
|
|
||||||
return items
|
|
||||||
else:
|
|
||||||
# Request succeeded
|
|
||||||
index += jump
|
|
||||||
|
|
||||||
if dialog:
|
if dialog:
|
||||||
percentage = int((float(index) / float(total))*100)
|
percentage = int((float(index) / float(total))*100)
|
||||||
dialog.update(percentage)
|
dialog.update(percentage)
|
||||||
|
|
||||||
if jump > highestjump:
|
queue.join()
|
||||||
# Adjust with the latest number, if it's greater
|
if dialog:
|
||||||
highestjump = jump
|
dialog.update(100)
|
||||||
|
|
||||||
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
|
|
||||||
log.info("Increase jump limit to: %s" % jump)
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_views(self, root=False):
|
def get_views(self, root=False):
|
||||||
|
@ -306,7 +306,7 @@ class Read_EmbyServer():
|
||||||
else: # Views ungrouped
|
else: # Views ungrouped
|
||||||
url = "{server}/emby/Users/{UserId}/Items?Sortby=SortName&format=json"
|
url = "{server}/emby/Users/{UserId}/Items?Sortby=SortName&format=json"
|
||||||
|
|
||||||
return self.doUtils(url)
|
return self.doUtils.downloadUrl(url)
|
||||||
|
|
||||||
def getViews(self, mediatype="", root=False, sortedlist=False):
|
def getViews(self, mediatype="", root=False, sortedlist=False):
|
||||||
# Build a list of user views
|
# Build a list of user views
|
||||||
|
@ -351,7 +351,6 @@ class Read_EmbyServer():
|
||||||
|
|
||||||
def verifyView(self, parentid, itemid):
|
def verifyView(self, parentid, itemid):
|
||||||
|
|
||||||
belongs = False
|
|
||||||
params = {
|
params = {
|
||||||
|
|
||||||
'ParentId': parentid,
|
'ParentId': parentid,
|
||||||
|
@ -362,41 +361,32 @@ class Read_EmbyServer():
|
||||||
'Recursive': True,
|
'Recursive': True,
|
||||||
'Ids': itemid
|
'Ids': itemid
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
result = self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
||||||
total = result['TotalRecordCount']
|
total = result['TotalRecordCount']
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
# Something happened to the connection
|
# Something happened to the connection
|
||||||
log.info("Error getting item count: " + str(error))
|
log.info("Error getting item count: " + str(error))
|
||||||
pass
|
return False
|
||||||
else:
|
|
||||||
if total:
|
|
||||||
belongs = True
|
|
||||||
|
|
||||||
return belongs
|
return True if total else False
|
||||||
|
|
||||||
def getMovies(self, parentId, basic=False, dialog=None):
|
def getMovies(self, parentId, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(parentId, "Movie", basic=basic, dialog=dialog)
|
return self.getSection(parentId, "Movie", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getBoxset(self, dialog=None):
|
def getBoxset(self, dialog=None):
|
||||||
|
|
||||||
return self.getSection(None, "BoxSet", dialog=dialog)
|
return self.getSection(None, "BoxSet", dialog=dialog)
|
||||||
|
|
||||||
def getMovies_byBoxset(self, boxsetid):
|
def getMovies_byBoxset(self, boxsetid):
|
||||||
return self.getSection(boxsetid, "Movie")
|
return self.getSection(boxsetid, "Movie")
|
||||||
|
|
||||||
def getMusicVideos(self, parentId, basic=False, dialog=None):
|
def getMusicVideos(self, parentId, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(parentId, "MusicVideo", basic=basic, dialog=dialog)
|
return self.getSection(parentId, "MusicVideo", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getHomeVideos(self, parentId):
|
def getHomeVideos(self, parentId):
|
||||||
|
|
||||||
return self.getSection(parentId, "Video")
|
return self.getSection(parentId, "Video")
|
||||||
|
|
||||||
def getShows(self, parentId, basic=False, dialog=None):
|
def getShows(self, parentId, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(parentId, "Series", basic=basic, dialog=dialog)
|
return self.getSection(parentId, "Series", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getSeasons(self, showId):
|
def getSeasons(self, showId):
|
||||||
|
@ -415,7 +405,7 @@ class Read_EmbyServer():
|
||||||
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
|
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils(url, parameters=params)
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.info("Error getting Seasons form server: " + str(error))
|
log.info("Error getting Seasons form server: " + str(error))
|
||||||
result = None
|
result = None
|
||||||
|
@ -426,15 +416,12 @@ class Read_EmbyServer():
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def getEpisodes(self, parentId, basic=False, dialog=None):
|
def getEpisodes(self, parentId, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(parentId, "Episode", basic=basic, dialog=dialog)
|
return self.getSection(parentId, "Episode", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getEpisodesbyShow(self, showId):
|
def getEpisodesbyShow(self, showId):
|
||||||
|
|
||||||
return self.getSection(showId, "Episode")
|
return self.getSection(showId, "Episode")
|
||||||
|
|
||||||
def getEpisodesbySeason(self, seasonId):
|
def getEpisodesbySeason(self, seasonId):
|
||||||
|
|
||||||
return self.getSection(seasonId, "Episode")
|
return self.getSection(seasonId, "Episode")
|
||||||
|
|
||||||
def getArtists(self, parent_id=None, dialog=None):
|
def getArtists(self, parent_id=None, dialog=None):
|
||||||
|
@ -444,7 +431,6 @@ class Read_EmbyServer():
|
||||||
'Items': [],
|
'Items': [],
|
||||||
'TotalRecordCount': 0
|
'TotalRecordCount': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get total number of items
|
# Get total number of items
|
||||||
url = "{server}/emby/Artists?UserId={UserId}&format=json"
|
url = "{server}/emby/Artists?UserId={UserId}&format=json"
|
||||||
params = {
|
params = {
|
||||||
|
@ -453,16 +439,16 @@ class Read_EmbyServer():
|
||||||
'Recursive': True,
|
'Recursive': True,
|
||||||
'Limit': 1
|
'Limit': 1
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils(url, parameters=params)
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
||||||
total = result['TotalRecordCount']
|
total = result['TotalRecordCount']
|
||||||
items['TotalRecordCount'] = total
|
items['TotalRecordCount'] = total
|
||||||
except Exception as error: # Failed to retrieve
|
except Exception as error: # Failed to retrieve
|
||||||
log.debug("%s:%s Failed to retrieve the server response: %s" % (url, params, error))
|
log.debug("%s:%s Failed to retrieve the server response: %s", url, params, error)
|
||||||
else:
|
else:
|
||||||
index = 0
|
index = 0
|
||||||
jump = self.limitIndex
|
jump = self.limitIndex
|
||||||
|
queue = Queue.Queue()
|
||||||
|
|
||||||
while index < total:
|
while index < total:
|
||||||
# Get items by chunk to increase retrieval speed at scale
|
# Get items by chunk to increase retrieval speed at scale
|
||||||
|
@ -471,6 +457,7 @@ class Read_EmbyServer():
|
||||||
'ParentId': parent_id,
|
'ParentId': parent_id,
|
||||||
'Recursive': True,
|
'Recursive': True,
|
||||||
'IsVirtualUnaired': False,
|
'IsVirtualUnaired': False,
|
||||||
|
'EnableTotalRecordCount': False,
|
||||||
'LocationTypes': "FileSystem,Remote,Offline",
|
'LocationTypes': "FileSystem,Remote,Offline",
|
||||||
'IsMissing': False,
|
'IsMissing': False,
|
||||||
'StartIndex': index,
|
'StartIndex': index,
|
||||||
|
@ -484,33 +471,32 @@ class Read_EmbyServer():
|
||||||
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview"
|
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
queue.put({'url': url, 'params': params})
|
||||||
|
if not self._add_worker_thread(queue, items['Items']):
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
index += jump
|
||||||
result = self.doUtils(url, parameters=params)
|
|
||||||
items['Items'].extend(result['Items'])
|
|
||||||
index += jump
|
|
||||||
except Exception as error:
|
|
||||||
log.debug("Error getting artists from server: " + str(error))
|
|
||||||
|
|
||||||
if dialog:
|
if dialog:
|
||||||
percentage = int((float(index) / float(total))*100)
|
percentage = int((float(index) / float(total))*100)
|
||||||
dialog.update(percentage)
|
dialog.update(percentage)
|
||||||
|
|
||||||
|
queue.join()
|
||||||
|
if dialog:
|
||||||
|
dialog.update(100)
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def getAlbums(self, basic=False, dialog=None):
|
def getAlbums(self, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(None, "MusicAlbum", sortby="DateCreated", basic=basic, dialog=dialog)
|
return self.getSection(None, "MusicAlbum", sortby="DateCreated", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getAlbumsbyArtist(self, artistId):
|
def getAlbumsbyArtist(self, artistId):
|
||||||
|
|
||||||
return self.getSection(None, "MusicAlbum", sortby="DateCreated", artist_id=artistId)
|
return self.getSection(None, "MusicAlbum", sortby="DateCreated", artist_id=artistId)
|
||||||
|
|
||||||
def getSongs(self, basic=False, dialog=None):
|
def getSongs(self, basic=False, dialog=None):
|
||||||
|
|
||||||
return self.getSection(None, "Audio", basic=basic, dialog=dialog)
|
return self.getSection(None, "Audio", basic=basic, dialog=dialog)
|
||||||
|
|
||||||
def getSongsbyAlbum(self, albumId):
|
def getSongsbyAlbum(self, albumId):
|
||||||
|
|
||||||
return self.getSection(albumId, "Audio")
|
return self.getSection(albumId, "Audio")
|
||||||
|
|
||||||
def getAdditionalParts(self, itemId):
|
def getAdditionalParts(self, itemId):
|
||||||
|
@ -523,7 +509,7 @@ class Read_EmbyServer():
|
||||||
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
|
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.doUtils(url)
|
result = self.doUtils.downloadUrl(url)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.info("Error getting additional parts form server: " + str(error))
|
log.info("Error getting additional parts form server: " + str(error))
|
||||||
result = None
|
result = None
|
||||||
|
@ -549,7 +535,7 @@ class Read_EmbyServer():
|
||||||
|
|
||||||
def updateUserRating(self, itemid, favourite=None):
|
def updateUserRating(self, itemid, favourite=None):
|
||||||
# Updates the user rating to Emby
|
# Updates the user rating to Emby
|
||||||
doUtils = self.doUtils
|
doUtils = self.doUtils.downloadUrl
|
||||||
|
|
||||||
if favourite:
|
if favourite:
|
||||||
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
||||||
|
@ -574,18 +560,18 @@ class Read_EmbyServer():
|
||||||
'ReplaceAllMetadata': True
|
'ReplaceAllMetadata': True
|
||||||
|
|
||||||
}
|
}
|
||||||
self.doUtils(url, postBody=params, action_type="POST")
|
self.doUtils.downloadUrl(url, postBody=params, action_type="POST")
|
||||||
|
|
||||||
def deleteItem(self, itemid):
|
def deleteItem(self, itemid):
|
||||||
|
|
||||||
url = "{server}/emby/Items/%s?format=json" % itemid
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
||||||
self.doUtils(url, action_type="DELETE")
|
self.doUtils.downloadUrl(url, action_type="DELETE")
|
||||||
|
|
||||||
def getUsers(self, server):
|
def getUsers(self, server):
|
||||||
|
|
||||||
url = "%s/emby/Users/Public?format=json" % server
|
url = "%s/emby/Users/Public?format=json" % server
|
||||||
try:
|
try:
|
||||||
users = self.doUtils(url, authenticate=False)
|
users = self.doUtils.downloadUrl(url, authenticate=False)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.info("Error getting users from server: " + str(error))
|
log.info("Error getting users from server: " + str(error))
|
||||||
users = []
|
users = []
|
||||||
|
@ -597,7 +583,7 @@ class Read_EmbyServer():
|
||||||
password = password or ""
|
password = password or ""
|
||||||
url = "%s/emby/Users/AuthenticateByName?format=json" % server
|
url = "%s/emby/Users/AuthenticateByName?format=json" % server
|
||||||
data = {'username': username, 'password': hashlib.sha1(password).hexdigest()}
|
data = {'username': username, 'password': hashlib.sha1(password).hexdigest()}
|
||||||
user = self.doUtils(url, postBody=data, action_type="POST", authenticate=False)
|
user = self.doUtils.downloadUrl(url, postBody=data, action_type="POST", authenticate=False)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
@ -610,4 +596,4 @@ class Read_EmbyServer():
|
||||||
'IncludeItemTypes': media_type
|
'IncludeItemTypes': media_type
|
||||||
}
|
}
|
||||||
url = self.get_emby_url('Users/{UserId}/Items?format=json')
|
url = self.get_emby_url('Users/{UserId}/Items?format=json')
|
||||||
return self.doUtils(url, parameters=params)
|
return self.doUtils.downloadUrl(url, parameters=params)
|
|
@ -25,8 +25,8 @@
|
||||||
<setting id="dblock" type="bool" label="30544" default="false" />
|
<setting id="dblock" type="bool" label="30544" default="false" />
|
||||||
<setting id="serverSync" type="bool" label="30514" default="true" />
|
<setting id="serverSync" type="bool" label="30514" default="true" />
|
||||||
<setting id="incSyncIndicator" label="30507" type="number" default="10" visible="eq(-1,true)" subsetting="true"/>
|
<setting id="incSyncIndicator" label="30507" type="number" default="10" visible="eq(-1,true)" subsetting="true"/>
|
||||||
<setting id="limitindex" type="number" label="30515" default="15" option="int" />
|
<setting id="limitIndex" type="number" label="30515" default="15" option="int" />
|
||||||
<setting id="downloadThreads" type="slider" label="Download Threads (recommended: 2-3)" default="3" range="1,1,7" option="int" />
|
<setting id="downloadThreads" type="slider" label="30548" default="3" range="1,1,7" option="int" subsetting="true" />
|
||||||
<setting id="enableTextureCache" label="30512" type="bool" default="true" />
|
<setting id="enableTextureCache" label="30512" type="bool" default="true" />
|
||||||
<setting id="imageCacheLimit" type="enum" label="30513" values="Unlimited|5|10|15|20|25" default="5" visible="eq(-1,true)" subsetting="true" />
|
<setting id="imageCacheLimit" type="enum" label="30513" values="Unlimited|5|10|15|20|25" default="5" visible="eq(-1,true)" subsetting="true" />
|
||||||
<setting id="syncEmptyShows" type="bool" label="30508" default="false" />
|
<setting id="syncEmptyShows" type="bool" label="30508" default="false" />
|
||||||
|
|
Loading…
Reference in a new issue