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,
['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

View File

@ -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']

View File

@ -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 = "; "

View File

@ -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", "<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))
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))