From 68e549442271314122b15ac85a8146d1ed9dcabd Mon Sep 17 00:00:00 2001 From: Etoh Date: Sun, 31 Dec 2017 13:19:44 +0000 Subject: [PATCH] Fix mpv chat backslash issue --- resources/syncplayintf.lua | 8 +++++--- syncplay/constants.py | 3 ++- syncplay/players/mplayer.py | 2 +- syncplay/players/mpv.py | 7 ++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/syncplayintf.lua b/resources/syncplayintf.lua index 7812dda..c5367f9 100644 --- a/resources/syncplayintf.lua +++ b/resources/syncplayintf.lua @@ -343,7 +343,9 @@ opts = { ['alertTimeout'] = 5, ['chatTimeout'] = 7, -- - ['inputPromptCharacter'] = ">", + ['inputPromptStartCharacter'] = ">", + ['inputPromptEndCharacter'] = "<", + ['backslashSubstituteCharacter'] = "|", --Lang: ['mpv-key-tab-hint'] = "[TAB] to toggle access to alphabet row key shortcuts.", ['mpv-key-hint'] = "[ENTER] to send message. [ESC] to escape chat mode.", @@ -569,12 +571,11 @@ end function wordwrapify_string(line) -- Naive helper function to find the next UTF-8 character in 'str' after 'pos' -- by skipping continuation bytes. Assumes 'str' contains valid UTF-8. - local str = line if str == nil or str == "" then return str, "" end - newstr = "" + local newstr = "" local currentChar = 0 local nextChar = 0 local chars = 0 @@ -593,6 +594,7 @@ function wordwrapify_string(line) end currentChar = nextChar until currentChar > maxChars + newstr = string.gsub(newstr,opts['backslashSubstituteCharacter'], '\\\239\187\191') -- Workaround for \ escape issues return newstr end diff --git a/syncplay/constants.py b/syncplay/constants.py index bfc8c72..76f900c 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -190,13 +190,14 @@ MPV_NEW_VERSION = False MPV_OSC_VISIBILITY_CHANGE_VERSION = False MPV_INPUT_PROMPT_START_CHARACTER = u"〉" MPV_INPUT_PROMPT_END_CHARACTER = u" 〈" +MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER = u"\" MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputEnabled","chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline", "chatInputFontColor", "chatInputPosition","chatOutputFontFamily","chatOutputFontSize", "chatOutputFontWeight","chatOutputFontUnderline","chatOutputMode","chatMaxLines", "chatTopMargin","chatLeftMargin","chatBottomMargin","chatDirectInput", "notificationTimeout","alertTimeout","chatTimeout","chatOutputEnabled"] -MPV_SYNCPLAYINTF_CONSTANTS_TO_SEND = ["MaxChatMessageLength={}".format(MAX_CHAT_MESSAGE_LENGTH),u"inputPromptStartCharacter={}".format(MPV_INPUT_PROMPT_START_CHARACTER),u"inputPromptEndCharacter={}".format(MPV_INPUT_PROMPT_END_CHARACTER)] +MPV_SYNCPLAYINTF_CONSTANTS_TO_SEND = ["MaxChatMessageLength={}".format(MAX_CHAT_MESSAGE_LENGTH),u"inputPromptStartCharacter={}".format(MPV_INPUT_PROMPT_START_CHARACTER),u"inputPromptEndCharacter={}".format(MPV_INPUT_PROMPT_END_CHARACTER),u"backslashSubstituteCharacter={}".format(MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER)] MPV_SYNCPLAYINTF_LANGUAGE_TO_SEND = ["mpv-key-tab-hint","mpv-key-hint", "alphakey-mode-warning-first-line", "alphakey-mode-warning-second-line"] VLC_SLAVE_ARGS = ['--extraintf=luaintf', '--lua-intf=syncplay', '--no-quiet', '--no-input-fast-seek', '--play-and-pause', '--start-time=0'] diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index c9e97a7..be6747d 100644 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -1,3 +1,4 @@ +# coding:utf8 import subprocess import re import threading @@ -11,7 +12,6 @@ from syncplay.utils import isWindows class MplayerPlayer(BasePlayer): speedSupported = True customOpenDialog = False - #chatOSDSupported = False # TODO: Make conditional aletOSDSupported = True chatOSDSupported = False osdMessageSeparator = "; " diff --git a/syncplay/players/mpv.py b/syncplay/players/mpv.py index 93e97dc..5b25486 100644 --- a/syncplay/players/mpv.py +++ b/syncplay/players/mpv.py @@ -1,3 +1,4 @@ +# coding:utf8 import re import subprocess from syncplay.players.mplayer import MplayerPlayer @@ -121,15 +122,15 @@ class NewMpvPlayer(OldMpvPlayer): if not self._client._config["chatOutputEnabled"]: super(self.__class__, self).displayMessage(message=message,duration=duration,OSDType=OSDType,mood=mood) return - messageString = self._sanitizeText(message.replace("\\n", "")).replace("", "\\n") + messageString = self._sanitizeText(message.replace("\\n", "")).replace("\\\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER).replace("", "\\n") self._listener.sendLine(u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType, mood, messageString)) def displayChatMessage(self, username, message): if not self._client._config["chatOutputEnabled"]: super(self.__class__, self).displayChatMessage(username,message) return - username = self._sanitizeText(username) - message = self._sanitizeText(message) + username = self._sanitizeText(username.replace("\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER)) + message = self._sanitizeText(message.replace("\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER)) messageString = u"<{}> {}".format(username, message) self._listener.sendLine(u'script-message-to syncplayintf chat "{}"'.format(messageString))