diff --git a/syncplay/players/iina.py b/syncplay/players/iina.py index 0fd09f9..0c439fb 100644 --- a/syncplay/players/iina.py +++ b/syncplay/players/iina.py @@ -2,11 +2,10 @@ import os from syncplay import constants from syncplay.utils import findResourcePath from syncplay.players.mpv import MpvPlayer -from syncplay.players.python_mpv_jsonipc.python_mpv_jsonipc import IINA +from syncplay.players.ipc_iina import IINA class IinaPlayer(MpvPlayer): - @staticmethod def run(client, playerPath, filePath, args): constants.MPV_NEW_VERSION = True diff --git a/syncplay/players/ipc_iina.py b/syncplay/players/ipc_iina.py new file mode 100755 index 0000000..dda0b9c --- /dev/null +++ b/syncplay/players/ipc_iina.py @@ -0,0 +1,55 @@ +import os.path +import subprocess +import time + +from syncplay.players.python_mpv_jsonipc.python_mpv_jsonipc import log, MPV, MPVError, MPVProcess +from syncplay.utils import resourcespath + +class IINA(MPV): + """The main IINA interface class. Use this to control the MPV player instantiated by IINA.""" + + def _start_mpv(self, ipc_socket, mpv_location, **kwargs): + # Attempt to start IINA 3 times. + for i in range(3): + try: + self.mpv_process = IINAProcess(ipc_socket, mpv_location, **kwargs) + break + except MPVError: + log.warning("IINA start failed.", exc_info=1) + continue + else: + raise MPVError("IINA process retry limit reached.") + +class IINAProcess(MPVProcess): + """ + Manages an IINA process, ensuring the socket or pipe is available. (Internal) + """ + + def _start_process(self, ipc_socket, args): + self.process = subprocess.Popen(args) + ipc_exists = False + for _ in range(100): # Give IINA 10 seconds to start. + time.sleep(0.1) + self.process.poll() + if os.path.exists(ipc_socket): + ipc_exists = True + log.debug("Found IINA socket.") + break + if self.process.returncode != 0: # iina-cli returns immediately after its start + log.error("IINA failed with returncode {0}.".format(self.process.returncode)) + break + else: + self.process.terminate() + raise MPVError("IINA start timed out.") + + if not ipc_exists or self.process.returncode != 0: + self.process.terminate() + raise MPVError("IINA not started.") + + def _get_arglist(self, exec_location, **kwargs): + args = [exec_location] + args.append(resourcespath + 'iina-bkg.png') + self._set_default(kwargs, "mpv-input-ipc-server", self.ipc_socket) + args.extend("--{0}={1}".format(v[0].replace("_", "-"), self._mpv_fmt(v[1])) + for v in kwargs.items()) + return args diff --git a/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py b/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py index a6cbbad..ce3d2de 100644 --- a/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py +++ b/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py @@ -8,8 +8,6 @@ import random import queue import logging -from syncplay.utils import resourcespath - log = logging.getLogger('mpv-jsonipc') if os.name == "nt": @@ -262,40 +260,6 @@ class MPVProcess: if os.name != 'nt' and os.path.exists(self.ipc_socket): os.remove(self.ipc_socket) -class IINAProcess(MPVProcess): - """ - Manages an IINA process, ensuring the socket or pipe is available. (Internal) - """ - - def _start_process(self, ipc_socket, args): - self.process = subprocess.Popen(args) - ipc_exists = False - for _ in range(100): # Give IINA 10 seconds to start. - time.sleep(0.1) - self.process.poll() - if os.path.exists(ipc_socket): - ipc_exists = True - log.debug("Found IINA socket.") - break - if self.process.returncode != 0: # iina-cli returns immediately after its start - log.error("IINA failed with returncode {0}.".format(self.process.returncode)) - break - else: - self.process.terminate() - raise MPVError("IINA start timed out.") - - if not ipc_exists or self.process.returncode != 0: - self.process.terminate() - raise MPVError("IINA not started.") - - def _get_arglist(self, exec_location, **kwargs): - args = [exec_location] - args.append(resourcespath + 'iina-bkg.png') - self._set_default(kwargs, "mpv-input-ipc-server", self.ipc_socket) - args.extend("--{0}={1}".format(v[0].replace("_", "-"), self._mpv_fmt(v[1])) - for v in kwargs.items()) - return args - class MPVInter: """ Low-level interface to MPV. Does NOT manage an mpv process. (Internal) @@ -685,18 +649,3 @@ class MPV: def __dir__(self): return self._dir - -class IINA(MPV): - """The main IINA interface class. Use this to control the MPV player instantiated by IINA.""" - - def _start_mpv(self, ipc_socket, mpv_location, **kwargs): - # Attempt to start IINA 3 times. - for i in range(3): - try: - self.mpv_process = IINAProcess(ipc_socket, mpv_location, **kwargs) - break - except MPVError: - log.warning("IINA start failed.", exc_info=1) - continue - else: - raise MPVError("IINA process retry limit reached.")