techoverload/slave/main.py

70 lines
1.8 KiB
Python

# importing vlc module
from os import listdir
from os.path import isfile, join
from random import randint
from time import sleep
import paho.mqtt.client as mqtt
from video import Video
import sys
from random import randint
import cv2
from image import Image
import multiprocessing
class App:
def __init__(self, x, y):
self.x = x
self.y = y
self.video = Video(x, y)
self.image = Image(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
self.images = [join("slave/images", f) for f in listdir("slave/images") if isfile(join("slave/images", f))]
self.lastvideo = -1
self.lastimage = -1
print(self.videos)
print(self.videos[randint(0, len(self.videos)-1)])
def idle(self):
last = -1
while True:
# if i == last:
# continue
if randint(0,5) == 0:
self.showimage()
else:
self.playvideo()
def showimage(self):
totalimages = len(self.images)-1
i = randint(0, totalimages)
if i == self.lastimage:
i += 1
if i > totalimages:
i = 0
self.lastimage = i
self.image.show(self.images[i])
cv2.waitKey(10000)
def playvideo(self):
totalvideos = len(self.videos)-1
i = randint(0, totalvideos)
if i == self.lastvideo:
i += 1
if i > totalvideos:
i = 0
self.lastvideo = i
video = self.videos[i]
print(video)
self.video.start(video)
self.image.blank()
cv2.waitKey(1)
def main():
app = App(int(sys.argv[1]), int(sys.argv[2]))
app.idle()
if __name__ == "__main__":
main()