文件夹内容更改时 Kodi 刷新幻灯片
Kodi refresh slideshow when folder content changes
我使用 Raspberry Pi 来显示存储在文件夹中的图片的幻灯片。
但是,如果我在放映幻灯片时向文件夹中添加图片 运行,则新图片不会添加到幻灯片中。
如何在不中断幻灯片放映的情况下实现此行为?
为 Kodi 添加一个自动启动脚本:它会在 Kodi 启动时自动 运行 幻灯片,如果文件夹内容发生变化则刷新幻灯片。
这个脚本来自这个答案:https://discourse.osmc.tv/t/refresh-picture-library/4867/13
# ~/.kodi/userdata/autoexec.py
# On Kodi startup, automatically start a Slideshow
# Refresh the slideshow if the content of the folder has been updated
import xbmc
from os import listdir
from time import sleep
xbmc.log('[refresh-slideshow] Starting')
monitor = xbmc.Monitor()
picfolder = "/PATH/TO/FOLDER"
# Generate list of images and start slideshow
l1 = listdir(picfolder)
xbmc.executebuiltin('SlideShow(%s)' %(picfolder))
xbmc.log('[refresh-slideshow] Slideshow started, monitoring')
# Wait for slideshow to start
sleep(5)
# Monitor during slideshow
while not monitor.abortRequested():
# If slideshow is still running, compare directory contents
if xbmc.getCondVisibility('Window.IsActive(slideshow)'):
l2 = listdir(picfolder)
# Restart slideshow if directory contents have changed
if l1 != l2:
xbmc.log('[refresh-slideshow] Folder contents changed, restarting slideshow')
xbmc.executebuiltin('SlideShow(%s)' %(picfolder))
l1 = l2
# If slideshow is no longer running (user has exited), exit script
else:
break
# Wait for 60 seconds, break if abort is requested
if monitor.waitForAbort(60):
break
xbmc.log('[refresh-slideshow] Finished, exiting')
如果没有,请根据 Class 转换您的屏幕保护程序脚本。
创建另一个 class 以使用 threading
更新图像
import xbmc, xbmcgui, threading
class MyMonitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
self.action = kwargs['action']
# do some action here.......
def onScreensaverDeactivated(self):
self.action()
class ImgVideoUpdate(threading.Thread):
def __init__(self, *args, **kwargs):
self._get_items = kwargs['data']
threading.Thread.__init__(self)
self.stop = False
self.check_update = 50 # set thread to update images(in seconds)
self.Monitor = MyMonitor(action=self._exit)
def run(self):
while (not self.Monitor.abortRequested()) and (not self.stop):
count = 0
while count != self.check_update: # check for new images every 50seconds
xbmc.sleep(200)
count += 1
if self.Monitor.abortRequested() or self.stop:
return
self._get_items()
现在在 ScreensaverWindow
class 中从 运行
的屏幕保护程序初始化 ImgVideoUpdate
class ScreensaverWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
xbmcgui.WindowXML.onInit(self)
self.volumeCtrl = None
# Get the videos to use as a screensaver
playlist = self.imagelist()
thread = ImgVideoUpdate(data=self.imagelist)
thread.start()
注意:如果您遇到任何问题,希望这个 helps.let 我知道。
我使用 Raspberry Pi 来显示存储在文件夹中的图片的幻灯片。
但是,如果我在放映幻灯片时向文件夹中添加图片 运行,则新图片不会添加到幻灯片中。
如何在不中断幻灯片放映的情况下实现此行为?
为 Kodi 添加一个自动启动脚本:它会在 Kodi 启动时自动 运行 幻灯片,如果文件夹内容发生变化则刷新幻灯片。
这个脚本来自这个答案:https://discourse.osmc.tv/t/refresh-picture-library/4867/13
# ~/.kodi/userdata/autoexec.py
# On Kodi startup, automatically start a Slideshow
# Refresh the slideshow if the content of the folder has been updated
import xbmc
from os import listdir
from time import sleep
xbmc.log('[refresh-slideshow] Starting')
monitor = xbmc.Monitor()
picfolder = "/PATH/TO/FOLDER"
# Generate list of images and start slideshow
l1 = listdir(picfolder)
xbmc.executebuiltin('SlideShow(%s)' %(picfolder))
xbmc.log('[refresh-slideshow] Slideshow started, monitoring')
# Wait for slideshow to start
sleep(5)
# Monitor during slideshow
while not monitor.abortRequested():
# If slideshow is still running, compare directory contents
if xbmc.getCondVisibility('Window.IsActive(slideshow)'):
l2 = listdir(picfolder)
# Restart slideshow if directory contents have changed
if l1 != l2:
xbmc.log('[refresh-slideshow] Folder contents changed, restarting slideshow')
xbmc.executebuiltin('SlideShow(%s)' %(picfolder))
l1 = l2
# If slideshow is no longer running (user has exited), exit script
else:
break
# Wait for 60 seconds, break if abort is requested
if monitor.waitForAbort(60):
break
xbmc.log('[refresh-slideshow] Finished, exiting')
如果没有,请根据 Class 转换您的屏幕保护程序脚本。
创建另一个 class 以使用 threading
更新图像
import xbmc, xbmcgui, threading
class MyMonitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
self.action = kwargs['action']
# do some action here.......
def onScreensaverDeactivated(self):
self.action()
class ImgVideoUpdate(threading.Thread):
def __init__(self, *args, **kwargs):
self._get_items = kwargs['data']
threading.Thread.__init__(self)
self.stop = False
self.check_update = 50 # set thread to update images(in seconds)
self.Monitor = MyMonitor(action=self._exit)
def run(self):
while (not self.Monitor.abortRequested()) and (not self.stop):
count = 0
while count != self.check_update: # check for new images every 50seconds
xbmc.sleep(200)
count += 1
if self.Monitor.abortRequested() or self.stop:
return
self._get_items()
现在在 ScreensaverWindow
class 中从 运行
的屏幕保护程序初始化 ImgVideoUpdate
class ScreensaverWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
xbmcgui.WindowXML.onInit(self)
self.volumeCtrl = None
# Get the videos to use as a screensaver
playlist = self.imagelist()
thread = ImgVideoUpdate(data=self.imagelist)
thread.start()
注意:如果您遇到任何问题,希望这个 helps.let 我知道。