load 60 items for background images, make the interval configurable

This commit is contained in:
faush01 2018-10-25 15:44:35 +11:00
parent 9d36bd0b0d
commit 7e5548243b
6 changed files with 67 additions and 23 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.5.51"
version="1.5.52"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.25.0"/>

View File

@ -643,7 +643,7 @@ msgid "Select Media Source"
msgstr ""
msgctxt "#30310"
msgid "Enable Emby remote control"
msgid "Enable Emby remote control (requires restart)"
msgstr ""
msgctxt "#30311"
@ -761,3 +761,11 @@ msgstr ""
msgctxt "#30340"
msgid "Group movies into collections"
msgstr ""
msgctxt "#30341"
msgid "Background update interval (requires restart)"
msgstr ""
msgctxt "#30342"
msgid "New content check interval (requires restart)"
msgstr ""

View File

@ -901,6 +901,12 @@ def set_library_window_values():
if already_set:
return
for index in range(0, 20):
home_window.clearProperty("view_item.%i.name" % index)
home_window.clearProperty("view_item.%i.id" % index)
home_window.clearProperty("view_item.%i.type" % index)
home_window.clearProperty("view_item.%i.thumb" % index)
data_manager = DataManager()
url = "{server}/emby/Users/{userid}/Views"
result = data_manager.GetContent(url)

View File

@ -19,32 +19,55 @@ downloadUtils = DownloadUtils()
dataManager = DataManager()
kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2])
background_items = []
background_current_item = 0
def set_background_image():
log.debug("set_background_image Called")
url = ('{server}/emby/Users/{userid}/Items' +
'?Recursive=true' +
'&limit=1' +
'&SortBy=Random' +
'&IncludeItemTypes=Movie,Series' +
'&ImageTypeLimit=1')
global background_current_item
global background_items
results = downloadUtils.downloadUrl(url, suppress=True)
results = json.loads(results)
if results is not None:
items = results.get("Items", [])
if len(items) > 0:
item = items[0]
server = downloadUtils.getServer()
bg_image = downloadUtils.getArtwork(item, "Backdrop", server=server)
if len(background_items) == 0 or background_current_item >= len(background_items):
log.debug("set_background_image: Need to load more backgrounds {0} - {1}",
len(background_items), background_current_item)
url = ('{server}/emby/Users/{userid}/Items' +
'?Recursive=true' +
'&limit=60' +
'&SortBy=Random' +
'&IncludeItemTypes=Movie,Series' +
'&ImageTypeLimit=1')
label = item.get("Name")
server = downloadUtils.getServer()
results = downloadUtils.downloadUrl(url, suppress=True)
results = json.loads(results)
if results is not None:
items = results.get("Items", [])
background_current_item = 0
background_items = []
for item in items:
bg_image = downloadUtils.getArtwork(item, "Backdrop", server=server)
label = item.get("Name")
item_background = {}
item_background["image"] = bg_image
item_background["name"] = label
background_items.append(item_background)
log.debug("set_background_image: Loaded {0} more backgrounds", len(background_items))
if len(background_items) > 0 and background_current_item < len(background_items):
bg_image = background_items[background_current_item].get("image")
label = background_items[background_current_item].get("name")
log.debug("set_background_image: {0} - {1} - {2}", background_current_item, label, bg_image)
background_current_item += 1
home_window = HomeWindow()
home_window.setProperty("random-gb", bg_image)
home_window.setProperty("random-gb-label", label)
home_window = HomeWindow()
home_window.setProperty("random-gb", bg_image)
home_window.setProperty("random-gb-label", label)
log.debug("random-gb: {0}", bg_image)
def checkForNewContent():

View File

@ -67,5 +67,7 @@
<setting id="showLoadProgress" type="bool" label="30120" default="false" visible="true" enable="true" />
<setting id="remoteControl" type="bool" label="30310" default="false" visible="true" enable="true" />
<setting id="suppressErrors" type="bool" label="30315" default="false" visible="true" enable="true" />
<setting id="background_interval" type="slider" label="30341" default="20" range="0,1,120" option="int" visible="true"/>
<setting id="newcontent_interval" type="slider" label="30342" default="60" range="0,1,300" option="int" visible="true"/>
</category>
</settings>

View File

@ -65,6 +65,9 @@ if context_menu:
context_monitor = ContextMonitor()
context_monitor.start()
background_interval = int(settings.getSetting('background_interval'))
newcontent_interval = int(settings.getSetting('newcontent_interval'))
# monitor.abortRequested() is causes issues, it currently triggers for all addon cancelations which causes
# the service to exit when a user cancels an addon load action. This is a bug in Kodi.
# I am switching back to xbmc.abortRequested approach until kodi is fixed or I find a work arround
@ -78,11 +81,13 @@ while not xbmc.abortRequested:
if (time.time() - last_progress_update) > 10:
last_progress_update = time.time()
sendProgress(monitor)
else:
if (time.time() - last_content_check) > 60:
if (time.time() - last_content_check) > newcontent_interval:
last_content_check = time.time()
checkForNewContent()
if (time.time() - last_background_update) > 30:
if (time.time() - last_background_update) > background_interval:
last_background_update = time.time()
set_library_window_values()
set_background_image()