reload playlist if changed

This commit is contained in:
j 2023-10-31 10:03:57 +01:00
parent eb49a320d1
commit 05905ea2b5

View file

@ -32,6 +32,7 @@ class Sync(Thread):
is_main = True
ready = False
destination = "255.255.255.255"
reload_check = None
def __init__(self, *args, **kwargs):
self.is_main = kwargs.get('mode', 'main') == 'main'
@ -52,8 +53,9 @@ class Sync(Thread):
self.mpv.loop_file = 'no'
self.mpv.register_key_binding('q', self.q_binding)
self.playlist = kwargs['playlist']
print(self.playlist)
self.playlist_mtime = os.stat(self.playlist).st_mtime
self.mpv.loadlist(self.playlist)
logger.error("loaded paylist: %s", self.playlist)
self.deviations = collections.deque(maxlen=10)
if not self.is_main:
self.mpv.pause = False
@ -68,16 +70,16 @@ class Sync(Thread):
def run(self):
while self.active:
if self.is_main:
pass
time.sleep(0.5)
else:
self.read_position_main()
#self.adjust_position()
self.reload_playlist()
def q_binding(self, *args):
self.stop()
self.mpv.stop()
def stop(self, *args):
self.active = False
if self.sock:
@ -90,6 +92,16 @@ class Sync(Thread):
elif self.ready:
self.adjust_position()
def reload_playlist(self):
if not self.reload_check:
self.reload_check = time.time()
if time.time() - self.reload_check > 5:
self.reload_check = time.time()
playlist_mtime = os.stat(self.playlist).st_mtime
if self.playlist_mtime != playlist_mtime:
self.playlist_mtime = playlist_mtime
self.mpv.loadlist(self.playlist)
logger.error("reloaded paylist: %s", self.playlist)
def init_socket(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)