Ha SeySayux,
dank voor je antwoord! Het netcat-openbsd pakket was bij mij al geinstalleerd. Ik heb het commando vervangen.
Ik moest nog een aantal dingen doen:
Vlc moet gestart worden met en correct gedefinieƫrde socket, (dezelfde als in het script). en het rc commando is vervangen door oldrc.
Als je dit werkend wil krijgen doe je dus:
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 = "/tmp/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 = "/media/rutger/Documenten/video"
## 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 = 200
## Sends an arbitrary command to VLC
def RunVLCCommand(cmd):
p = subprocess.Popen("echo " + cmd + " | nc.openbsd -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
Dit opslaan als .py bestand (de movies.dir kun je uiteraard veranderen, de tijd in seconden ook)
vlc starten met vlc -I oldrc --rc-unix /tmp/vlc.sock
het scriptje starten met python scriptnaam.py
Het enige wat ik niet mooi vind is dat er steeds een nieuw vlc scherm geopend wordt.
Update:
Je kunt VLC gewoon starten en dan configureren voor afstandsbedieningtoegang. Kies extra opties, hoofdbediening en selecteer afstandsbediening. Oldrc zou nu in de regel moeten staan. Bij de extra opties kies je simuleer TYY en bij het bovenste regeltje voer je de socket locatie op. Het scriptje gewoon op de oude manier starten. De video`s laden nu netjes in het bestaande VLC scherm.