Dopo non aver ricevuto una risposta in tempo (avrebbe dovuto pubblicare questo una settimana prima), ho finito per immergermi nell'automazione di VLC. Ho trovato questo gioiello di un post sul blog sul controllo di VLC tramite socket UNIX. L'essenziale è che se si configura VLC correttamente, è possibile inviare comandi tramite la sintassi della riga di comando:
echo [VLC Command] | nc -U /Users/vlc.sock
dove [Comando VLC] è qualsiasi comando supportato da VLC (è possibile trovare un elenco di comandi inviando il comando " longhelp ").
Ho finito per scrivere uno script Python per caricare automaticamente una directory piena di film e quindi scegliere casualmente i clip da mostrare. Lo script prima mette tutti gli avis in una playlist VLC. Quindi sceglie un file casuale dalla playlist e sceglie un punto di partenza casuale in quel video da riprodurre. Lo script attende quindi il periodo di tempo specificato e ripete il processo. Eccolo, non per i deboli di cuore:
import subprocess
import random
import time
import os
import sys
## Just seed if you want to get the same sequence after restarting the script
## random.seed()
SocketLocation = "/Users/vlc.sock"
## You can enter a directory as a command line argument; otherwise it will use the default
if(len(sys.argv) >= 2):
MoviesDir = sys.argv[1]
else:
MoviesDir = "/Users/Movies/Xmas"
## You can enter the interval in seconds as the second command line argument as well
if(len(sys.argv) >= 3):
IntervalInSeconds = int(sys.argv[2])
else:
IntervalInSeconds = 240
## Sends an arbitrary command to VLC
def RunVLCCommand(cmd):
p = subprocess.Popen("echo " + cmd + " | nc -U " + SocketLocation, shell = True, stdout = subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
print "returning: " + retval
return retval
## Clear the playlist
RunVLCCommand("clear")
RawMovieFiles = os.listdir(MoviesDir)
MovieFiles = []
FileLengths = []
## Loop through the directory listing and add each avi or divx file to the playlist
for MovieFile in RawMovieFiles:
if(MovieFile.endswith(".avi") or MovieFile.endswith(".divx")):
MovieFiles.append(MovieFile)
RunVLCCommand("add \"" + MoviesDir + "/" + MovieFile + "\"")
PlayListItemNum = 0
## Loop forever
while 1==1:
## Choose a random movie from the playlist
PlayListItemNum = random.randint(1, len(MovieFiles))
RunVLCCommand("goto " + str(PlayListItemNum))
FileLength = "notadigit"
tries = 0
## Sometimes get_length doesn't work right away so retry 50 times
while tries < 50 and FileLength .strip().isdigit() == False or FileLength.strip() == "0":
tries+=1
FileLength = RunVLCCommand("get_length")
## If get_length fails 50 times in a row, just choose another movie
if tries < 50:
## Choose a random start time
StartTimeCode = random.randint(30, int(FileLength) - IntervalInSeconds);
RunVLCCommand("seek " + str(StartTimeCode))
## Turn on fullscreen
RunVLCCommand("f on")
## Wait until the interval expires
time.sleep(IntervalInSeconds)
## Stop the movie
RunVLCCommand("stop")
tries = 0
## Wait until the video stops playing or 50 tries, whichever comes first
while tries < 50 and RunVLCCommand("is_playing").strip() == "1":
time.sleep(1)
tries+=1
Oh, e come nota a margine, abbiamo fatto funzionare questo su un proiettore ed è stato il successo della festa. Tutti amavano scherzare con i valori dei secondi e scegliere nuovi video da aggiungere. Non mi ha fatto scopare , ma quasi!
EDIT: ho rimosso la linea che apre VLC perché c'erano problemi di temporizzazione in cui VLC sarebbe stato caricato a metà solo quando lo script ha iniziato ad aggiungere file alla playlist. Ora apro manualmente VLC e aspetto che termini il caricamento prima di iniziare lo script.