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):
self.sock.settimeout(5)
try:
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
except socket.timeout:
if self._last_ping != "pause":
logger.error("failed to receive data from main")
except OSError:
logger.error("socket closed")
else:
while True:
try:
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
except socket.timeout:
if self._last_ping != "pause":
logger.error("failed to receive data from main")
return
except OSError:
logger.error("socket closed")
return
if CONFIG.get("sync_group"):
if data[0] != str(CONFIG["sync_group"]):
return self.read_position_main()
else:
if data[0] == str(CONFIG["sync_group"]):
data = 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
break
else:
self.main.time_pos = float(data[0])
self.main.playlist_current_pos = int(data[1])
break
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):
if self.mpv.time_pos is not None: