Fix mpv chat backslash issue

This commit is contained in:
Etoh 2017-12-31 13:19:44 +00:00
parent d77910d362
commit 68e5494422
4 changed files with 12 additions and 8 deletions

View File

@ -343,7 +343,9 @@ opts = {
['alertTimeout'] = 5, ['alertTimeout'] = 5,
['chatTimeout'] = 7, ['chatTimeout'] = 7,
-- --
['inputPromptCharacter'] = ">", ['inputPromptStartCharacter'] = ">",
['inputPromptEndCharacter'] = "<",
['backslashSubstituteCharacter'] = "|",
--Lang: --Lang:
['mpv-key-tab-hint'] = "[TAB] to toggle access to alphabet row key shortcuts.", ['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.", ['mpv-key-hint'] = "[ENTER] to send message. [ESC] to escape chat mode.",
@ -569,12 +571,11 @@ end
function wordwrapify_string(line) function wordwrapify_string(line)
-- Naive helper function to find the next UTF-8 character in 'str' after 'pos' -- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8. -- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
local str = line local str = line
if str == nil or str == "" then if str == nil or str == "" then
return str, "" return str, ""
end end
newstr = "" local newstr = ""
local currentChar = 0 local currentChar = 0
local nextChar = 0 local nextChar = 0
local chars = 0 local chars = 0
@ -593,6 +594,7 @@ function wordwrapify_string(line)
end end
currentChar = nextChar currentChar = nextChar
until currentChar > maxChars until currentChar > maxChars
newstr = string.gsub(newstr,opts['backslashSubstituteCharacter'], '\\\239\187\191') -- Workaround for \ escape issues
return newstr return newstr
end end

View File

@ -190,13 +190,14 @@ MPV_NEW_VERSION = False
MPV_OSC_VISIBILITY_CHANGE_VERSION = False MPV_OSC_VISIBILITY_CHANGE_VERSION = False
MPV_INPUT_PROMPT_START_CHARACTER = u"" MPV_INPUT_PROMPT_START_CHARACTER = u""
MPV_INPUT_PROMPT_END_CHARACTER = u"" MPV_INPUT_PROMPT_END_CHARACTER = u""
MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER = u""
MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputEnabled","chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline", MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputEnabled","chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline",
"chatInputFontColor", "chatInputPosition","chatOutputFontFamily","chatOutputFontSize", "chatInputFontColor", "chatInputPosition","chatOutputFontFamily","chatOutputFontSize",
"chatOutputFontWeight","chatOutputFontUnderline","chatOutputMode","chatMaxLines", "chatOutputFontWeight","chatOutputFontUnderline","chatOutputMode","chatMaxLines",
"chatTopMargin","chatLeftMargin","chatBottomMargin","chatDirectInput", "chatTopMargin","chatLeftMargin","chatBottomMargin","chatDirectInput",
"notificationTimeout","alertTimeout","chatTimeout","chatOutputEnabled"] "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"] 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', VLC_SLAVE_ARGS = ['--extraintf=luaintf', '--lua-intf=syncplay', '--no-quiet', '--no-input-fast-seek',
'--play-and-pause', '--start-time=0'] '--play-and-pause', '--start-time=0']

View File

@ -1,3 +1,4 @@
# coding:utf8
import subprocess import subprocess
import re import re
import threading import threading
@ -11,7 +12,6 @@ from syncplay.utils import isWindows
class MplayerPlayer(BasePlayer): class MplayerPlayer(BasePlayer):
speedSupported = True speedSupported = True
customOpenDialog = False customOpenDialog = False
#chatOSDSupported = False # TODO: Make conditional
aletOSDSupported = True aletOSDSupported = True
chatOSDSupported = False chatOSDSupported = False
osdMessageSeparator = "; " osdMessageSeparator = "; "

View File

@ -1,3 +1,4 @@
# coding:utf8
import re import re
import subprocess import subprocess
from syncplay.players.mplayer import MplayerPlayer from syncplay.players.mplayer import MplayerPlayer
@ -121,15 +122,15 @@ class NewMpvPlayer(OldMpvPlayer):
if not self._client._config["chatOutputEnabled"]: if not self._client._config["chatOutputEnabled"]:
super(self.__class__, self).displayMessage(message=message,duration=duration,OSDType=OSDType,mood=mood) super(self.__class__, self).displayMessage(message=message,duration=duration,OSDType=OSDType,mood=mood)
return return
messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("<NEWLINE>", "\\n") messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("\\\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER).replace("<NEWLINE>", "\\n")
self._listener.sendLine(u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType, mood, messageString)) self._listener.sendLine(u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType, mood, messageString))
def displayChatMessage(self, username, message): def displayChatMessage(self, username, message):
if not self._client._config["chatOutputEnabled"]: if not self._client._config["chatOutputEnabled"]:
super(self.__class__, self).displayChatMessage(username,message) super(self.__class__, self).displayChatMessage(username,message)
return return
username = self._sanitizeText(username) username = self._sanitizeText(username.replace("\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER))
message = self._sanitizeText(message) message = self._sanitizeText(message.replace("\\",constants.MPV_INPUT_BACKSLASH_SUBSTITUTE_CHARACTER))
messageString = u"<{}> {}".format(username, message) messageString = u"<{}> {}".format(username, message)
self._listener.sendLine(u'script-message-to syncplayintf chat "{}"'.format(messageString)) self._listener.sendLine(u'script-message-to syncplayintf chat "{}"'.format(messageString))