avoid recursion

This commit is contained in:
j 2024-09-10 12:46:47 +01:00
parent e221626191
commit 45e2acbbb8

View file

@ -302,30 +302,34 @@ class Sync(Thread):
def read_position_main(self): def read_position_main(self):
self.sock.settimeout(5) self.sock.settimeout(5)
try: while True:
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1) try:
except socket.timeout: data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
if self._last_ping != "pause": except socket.timeout:
logger.error("failed to receive data from main") if self._last_ping != "pause":
except OSError: logger.error("failed to receive data from main")
logger.error("socket closed") return
else: except OSError:
logger.error("socket closed")
return
if CONFIG.get("sync_group"): if CONFIG.get("sync_group"):
if data[0] != str(CONFIG["sync_group"]): if data[0] == str(CONFIG["sync_group"]):
return self.read_position_main()
else:
data = data[1:] data = data[1:]
self._last_ping = data[0] break
if data[0] == "pause":
self.is_paused = True
self.mpv.pause = True
elif data[0] == "play":
self.is_paused = False
self._tick = 0
self.mpv.pause = False
else: else:
self.main.time_pos = float(data[0]) break
self.main.playlist_current_pos = int(data[1])
self._last_ping = data[0]
if data[0] == "pause":
self.is_paused = True
self.mpv.pause = True
elif data[0] == "play":
self.is_paused = False
self._tick = 0
self.mpv.pause = False
else:
self.main.time_pos = float(data[0])
self.main.playlist_current_pos = int(data[1])
def adjust_position(self): def adjust_position(self):
if self.mpv.time_pos is not None: if self.mpv.time_pos is not None: