From a0a6e6a644399c2c875aaa99d497d5a666759129 Mon Sep 17 00:00:00 2001 From: Etoh Date: Sun, 28 Jan 2024 11:34:32 +0000 Subject: [PATCH] Allow player arguments with spaces/quotes (#665) (#668) --- syncplay/constants.py | 1 + syncplay/players/vlc.py | 8 ++++++-- syncplay/ui/GuiConfiguration.py | 2 +- syncplay/utils.py | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index c4a8b88..d13986c 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -115,6 +115,7 @@ LAST_PAUSED_DIFF_THRESHOLD = 2 FILENAME_STRIP_REGEX = "[-~_\.\[\](): ]" CONTROL_PASSWORD_STRIP_REGEX = "[^a-zA-Z0-9\-]" ROOM_NAME_STRIP_REGEX = "^(\+)(?P.*)(:)(\w{12})$" +ARGUMENT_SPLIT_REGEX = r'(?:[^\s"]+|"[^"]*")+' COMMANDS_UNDO = ["u", "undo", "revert"] COMMANDS_CHAT = ["ch", "chat"] COMMANDS_LIST = ["l", "list", "users"] diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index b60bb62..639f8a9 100755 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -487,10 +487,14 @@ class VlcPlayer(BasePlayer): call.extend(self.__playerController.SLAVE_ARGS) if args: - call.extend(args) + for arg in args: + if "=" in arg and "\"" in arg: + (argName, argValue) = arg.split("=", 1) + if argValue.startswith("\"") and argValue.endswith("\""): + arg = argName + "=" + argValue[1:-1] + call.extend([arg]) self._vlcVersion = None - if isWindows() and getattr(sys, 'frozen', '') and getattr(sys, '_MEIPASS', '') is not None: # Needed for pyinstaller --onefile bundle self.__process = subprocess.Popen( call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 85f020a..43ef000 100755 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -279,7 +279,7 @@ class ConfigDialog(QtWidgets.QDialog): currentplayerpath = self.executablepathCombobox.currentText() if currentplayerpath: - NewPlayerArgs = self.playerargsTextbox.text().split(" ") if self.playerargsTextbox.text() else "" + NewPlayerArgs = utils.parseCommandLineString(self.playerargsTextbox.text()) if self.playerargsTextbox.text() else "" self.perPlayerArgs[self.executablepathCombobox.currentText()] = NewPlayerArgs def languageChanged(self): diff --git a/syncplay/utils.py b/syncplay/utils.py index 781f8cb..076c509 100755 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -191,6 +191,10 @@ def limitedPowerset(s, minLength): return itertools.chain.from_iterable(itertools.combinations(s, r) for r in range(len(s), minLength, -1)) +def parseCommandLineString(s): + arsToReturn = re.findall(constants.ARGUMENT_SPLIT_REGEX, s) + return arsToReturn + def blackholeStdoutForFrozenWindow(): if getattr(sys, 'frozen', '') == "windows_exe": class Stderr(object):