techoverload/slave/main.py

70 lines
1.8 KiB
Python
Raw Normal View History

2022-07-18 05:30:07 +00:00
# importing vlc module
2022-07-20 09:14:04 +00:00
from os import listdir
from os.path import isfile, join
from random import randint
2022-07-18 05:30:07 +00:00
from time import sleep
import paho.mqtt.client as mqtt
from video import Video
2022-07-18 06:47:01 +00:00
import sys
2022-07-20 09:14:04 +00:00
from random import randint
2022-07-20 11:46:55 +00:00
import cv2
2022-07-21 12:09:36 +00:00
from image import Image
import multiprocessing
2022-07-18 05:30:07 +00:00
class App:
2022-07-22 17:27:29 +00:00
def __init__(self, x, y):
2022-07-20 11:46:55 +00:00
self.x = x
self.y = y
2022-07-18 06:47:01 +00:00
self.video = Video(x, y)
2022-07-21 12:09:36 +00:00
self.image = Image(x, y)
2022-07-20 09:14:04 +00:00
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
2022-07-21 12:09:36 +00:00
self.images = [join("slave/images", f) for f in listdir("slave/images") if isfile(join("slave/images", f))]
self.lastvideo = -1
self.lastimage = -1
2022-07-20 09:14:04 +00:00
print(self.videos)
2022-07-20 11:46:55 +00:00
print(self.videos[randint(0, len(self.videos)-1)])
2022-07-22 17:27:29 +00:00
2022-07-20 09:14:04 +00:00
def idle(self):
2022-07-20 11:46:55 +00:00
last = -1
2022-07-21 12:09:36 +00:00
2022-07-22 17:27:29 +00:00
while True:
2022-07-21 12:09:36 +00:00
# if i == last:
# continue
if randint(0,5) == 0:
self.showimage()
else:
2022-07-22 17:27:29 +00:00
self.playvideo()
2022-07-20 11:46:55 +00:00
2022-07-21 12:09:36 +00:00
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])
2022-07-22 17:27:29 +00:00
cv2.waitKey(10000)
2022-07-20 09:14:04 +00:00
2022-07-21 12:09:36 +00:00
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)
2022-07-20 09:14:04 +00:00
2022-07-18 06:47:01 +00:00
def main():
2022-07-18 05:30:07 +00:00
2022-07-22 17:27:29 +00:00
app = App(int(sys.argv[1]), int(sys.argv[2]))
app.idle()
2022-07-18 06:47:01 +00:00
if __name__ == "__main__":
main()