Any suggestion on my Media Updater for Slideshow?
#1
Hello, I would like to know if there is some leak or error in my simple Media Updater for Slideshow service add-on.
This addon checks for new file changes in the media folder every 2 minutes, and reloads the Slideshow in that case.

Code:
import time
import xbmc
import subprocess
import re
from os import listdir

minutos = 2
mediafolder = "/storage/pictures"
logfolder = "/storage/.kodi/temp/"

templist = listdir(mediafolder)

if __name__ == '__main__':
    monitor = xbmc.Monitor()
    
    while True:
        if monitor.waitForAbort(minutos * 60):
            # kodi turned off
            break
        
        # debug
        f = open(logfolder + 'actualizar-slideshow.log', 'a')

        # read dir
        newlist = listdir(mediafolder)
                
        # if there are changes
        if (templist != newlist):
            
            # build regex with list of new files
            diff = set(newlist) ^ set(templist)
            regex = ('|').join( [ re.escape(item) for item in diff ] )

            # check if there are files transferring
            try:
                # if grep returns 0, there are actually files transferring
                subprocess.check_output('lsof | grep -E "' + regex + '"', shell=True)
            
                f.write('%s: cambios \n' % time.ctime())
                f.write('%s \n' % list(diff))
                f.close()

                # go to the first line in "while True" statement
                continue

            except:
                # grep returns 1, there are no files transferring
                pass
            
            # refresh slideshow (the dirty way, because XMBC.Slideshow() doesn't support video yet.)
            xbmc.executebuiltin('XBMC.ActivateWindow(Pictures,' + mediafolder + ')')
            xbmc.executebuiltin('XBMC.Action(Play)')

            # save new list into temp list
            templist = newlist
            f.write('%s: actualizado\n' % time.ctime())

        else:
            f.write('%s: todo igual\n' % time.ctime())
        
        f.close()

Here's with spanish comments,
Code:
import time
import xbmc
import subprocess
import re
from os import listdir

minutos = 2
mediafolder = "/storage/pictures"
logfolder = "/storage/.kodi/temp/"

templist = listdir(mediafolder)

if __name__ == '__main__':
    monitor = xbmc.Monitor()
    
    while True:
        if monitor.waitForAbort(minutos * 60):
            # se apaga el kodi, nos vimo
            break
        
        # debug
        f = open(logfolder + 'actualizar-slideshow.log', 'a')

        # leo
        newlist = listdir(mediafolder)
                
        # si hay cambios
        if (templist != newlist):
            
            # armo el regex con la lista de archivos nuevos
            diff = set(newlist) ^ set(templist)
            regex = ('|').join( [ re.escape(item) for item in diff ] )

            # comprobar si hay archivos transfiriendo
            try:
                # si grep retorna 0, hay archivos transfiriendo
                subprocess.check_output('lsof | grep -E "' + regex + '"', shell=True)
            
                f.write('%s: cambios \n' % time.ctime())
                f.write('%s \n' % list(diff))
                f.close()

                # VOY AL COMIENZO DEL WHILE
                continue

            except subprocess.CalledProcessError:
                # grep retorna 1, no encontro archivos transfiriendo
                pass
            
            # refrescar la presentacion (provisorio)
            xbmc.executebuiltin('XBMC.ActivateWindow(Pictures,' + mediafolder + ')')
            xbmc.executebuiltin('XBMC.Action(Play)')

            # guardo
            templist = newlist
            f.write('%s: actualizado\n' % time.ctime())

        else:
            f.write('%s: todo igual\n' % time.ctime())
        
        f.close()
Reply

Logout Mark Read Team Forum Stats Members Help
Any suggestion on my Media Updater for Slideshow?0