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