(mpv chat) Integrate OSD and chat display [initial]
This commit is contained in:
parent
327fe86ea8
commit
cfa3579631
@ -33,6 +33,14 @@ function clear_chat()
|
|||||||
chat_log = {}
|
chat_log = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local secondary_osd = ""
|
||||||
|
local last_secondary_osd_time = nil
|
||||||
|
|
||||||
|
function set_secondary_osd(osd_message)
|
||||||
|
secondary_osd = osd_message
|
||||||
|
last_secondary_osd_time = mp.get_time()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function add_chat(chat_message)
|
function add_chat(chat_message)
|
||||||
last_chat_time = mp.get_time()
|
last_chat_time = mp.get_time()
|
||||||
@ -61,6 +69,15 @@ function chat_update()
|
|||||||
if timedelta >= 7 then
|
if timedelta >= 7 then
|
||||||
clear_chat()
|
clear_chat()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if secondary_osd ~= "" then
|
||||||
|
if mp.get_time() - last_secondary_osd_time < 5 and last_secondary_osd_time ~= nil then
|
||||||
|
local xpos = opts['chatLeftMargin']
|
||||||
|
local ypos = opts['chatTopMargin']+(0*opts['chatOutputFontSize'])
|
||||||
|
local messageString = '('..secondary_osd..')'
|
||||||
|
messageString = '{\\1c&H0000FF}'..messageString
|
||||||
|
chat_ass = format_chatroom(xpos,ypos,messageString)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if #chat_log > 0 then
|
if #chat_log > 0 then
|
||||||
for i = 1, #chat_log do
|
for i = 1, #chat_log do
|
||||||
@ -142,6 +159,14 @@ mp.register_script_message('chat', function(e)
|
|||||||
add_chat(e)
|
add_chat(e)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
mp.register_script_message('primary-osd', function(e)
|
||||||
|
add_chat(e)
|
||||||
|
end)
|
||||||
|
|
||||||
|
mp.register_script_message('secondary-osd', function(e)
|
||||||
|
set_secondary_osd(e)
|
||||||
|
end)
|
||||||
|
|
||||||
mp.register_script_message('set_syncplayintf_options', function(e)
|
mp.register_script_message('set_syncplayintf_options', function(e)
|
||||||
set_syncplayintf_options(e)
|
set_syncplayintf_options(e)
|
||||||
end)
|
end)
|
||||||
@ -188,7 +213,7 @@ opts = {
|
|||||||
['chatOutputMode'] = "Chatroom",
|
['chatOutputMode'] = "Chatroom",
|
||||||
-- Can be "Chatroom", "Subtitle" or "Scrolling" style
|
-- Can be "Chatroom", "Subtitle" or "Scrolling" style
|
||||||
['chatMaxLines'] = 7,
|
['chatMaxLines'] = 7,
|
||||||
['chatTopMargin'] = 125,
|
['chatTopMargin'] = 25,
|
||||||
['chatLeftMargin'] = 20,
|
['chatLeftMargin'] = 20,
|
||||||
['chatBottomMargin'] = 30
|
['chatBottomMargin'] = 30
|
||||||
}
|
}
|
||||||
@ -274,6 +299,7 @@ function input_ass()
|
|||||||
'{\\p0}'
|
'{\\p0}'
|
||||||
local before_cur = ass_escape(line:sub(1, cursor - 1))
|
local before_cur = ass_escape(line:sub(1, cursor - 1))
|
||||||
local after_cur = ass_escape(line:sub(cursor))
|
local after_cur = ass_escape(line:sub(cursor))
|
||||||
|
local secondary_pos = "10,"..tostring(10+opts['chatInputFontSize'])
|
||||||
|
|
||||||
local alignment = 7
|
local alignment = 7
|
||||||
local position = "5,5"
|
local position = "5,5"
|
||||||
@ -281,14 +307,17 @@ function input_ass()
|
|||||||
if opts['chatInputPosition'] == "Middle" then
|
if opts['chatInputPosition'] == "Middle" then
|
||||||
alignment = 5
|
alignment = 5
|
||||||
position = tostring(CANVAS_WIDTH/2)..","..tostring(CANVAS_HEIGHT/2)
|
position = tostring(CANVAS_WIDTH/2)..","..tostring(CANVAS_HEIGHT/2)
|
||||||
|
secondary_pos = tostring(CANVAS_WIDTH/2)..","..tostring((CANVAS_HEIGHT/2)+10+opts['chatInputFontSize'])
|
||||||
end_marker = "{\\u0}".." <"
|
end_marker = "{\\u0}".." <"
|
||||||
elseif opts['chatInputPosition'] == "Bottom" then
|
elseif opts['chatInputPosition'] == "Bottom" then
|
||||||
alignment = 1
|
alignment = 1
|
||||||
position = tostring(5)..","..tostring(CANVAS_HEIGHT-5)
|
position = tostring(5)..","..tostring(CANVAS_HEIGHT-5)
|
||||||
|
secondary_pos = "10,"..tostring(CANVAS_HEIGHT-(20+opts['chatInputFontSize']))
|
||||||
end
|
end
|
||||||
|
|
||||||
--mp.osd_message("",0)
|
-- TODO: local osd_help_message = "[TAB] to toggle access to alphabet row key shortcuts. [ENTER] to send message. [ESC] to escape chat mode. Send /hint in chat to disable this hint."
|
||||||
return "{\\an"..alignment.."}{\\pos("..position..")}"..style..'> '..after_style..before_cur..cglyph..style..after_style..after_cur..end_marker
|
-- TODO: local help_prompt = '\n{\\an'..alignment..'\\pos('..secondary_pos..')\\fn' .. opts['chatInputFontFamily'] .. '\\fs' .. (opts['chatInputFontSize']/2) .. '}' .. osd_help_message
|
||||||
|
return "{\\an"..alignment.."}{\\pos("..position..")}"..style..'> '..after_style..before_cur..cglyph..style..after_style..after_cur..end_marker -- TODO: ..help_prompt
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -583,7 +612,7 @@ function add_repl_alpharow_bindings(bindings)
|
|||||||
name .. '\n'
|
name .. '\n'
|
||||||
end
|
end
|
||||||
mp.commandv('define-section', 'repl-alpha-input', cfg, 'force')
|
mp.commandv('define-section', 'repl-alpha-input', cfg, 'force')
|
||||||
mp.enable_key_bindings('repl-input', 'allow-hide-cursor+allow-vo-dragging')
|
mp.enable_key_bindings('repl-alpha-input')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Mapping from characters to mpv key names
|
-- Mapping from characters to mpv key names
|
||||||
|
|||||||
@ -10,7 +10,8 @@ import os, sys
|
|||||||
class MplayerPlayer(BasePlayer):
|
class MplayerPlayer(BasePlayer):
|
||||||
speedSupported = True
|
speedSupported = True
|
||||||
customOpenDialog = False
|
customOpenDialog = False
|
||||||
secondaryOSDSupported = False
|
#secondaryOSDSupported = False # TODO: Make conditional
|
||||||
|
secondaryOSDSupported = True
|
||||||
chatOSDSupported = False
|
chatOSDSupported = False
|
||||||
osdMessageSeparator = "; "
|
osdMessageSeparator = "; "
|
||||||
|
|
||||||
@ -89,8 +90,17 @@ class MplayerPlayer(BasePlayer):
|
|||||||
self._listener.sendLine("get_property {}".format(property_))
|
self._listener.sendLine("get_property {}".format(property_))
|
||||||
|
|
||||||
def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), secondaryOSD=False):
|
def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), secondaryOSD=False):
|
||||||
|
if not secondaryOSD and self._client.chatIsEnabled(): # TODO: Add check to ensure it is in 'chatroom' mode
|
||||||
|
max_message_length = 3+constants.MAX_USERNAME_LENGTH+constants.MAX_CHAT_MESSAGE_LENGTH
|
||||||
|
messageStrings = utils.splitText(message,max_message_length)
|
||||||
|
for messageString in messageStrings:
|
||||||
|
self._listener.sendLine(u'script-message-to syncplayintf primary-osd "{}"'.format(messageString))
|
||||||
|
return
|
||||||
|
if secondaryOSD:
|
||||||
|
messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("<NEWLINE>", "\\n")
|
||||||
|
self._listener.sendLine(u'script-message-to syncplayintf secondary-osd "{}"'.format(messageString))
|
||||||
message = self._sanitizeText(message.replace("\\n","<NEWLINE>")).replace("<NEWLINE>","\\n")
|
message = self._sanitizeText(message.replace("\\n","<NEWLINE>")).replace("<NEWLINE>","\\n")
|
||||||
self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8'))
|
#self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8'))
|
||||||
|
|
||||||
def displayChatMessage(self, username, message):
|
def displayChatMessage(self, username, message):
|
||||||
username = self._sanitizeText(username)
|
username = self._sanitizeText(username)
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import os, sys, time
|
|||||||
class MpvPlayer(MplayerPlayer):
|
class MpvPlayer(MplayerPlayer):
|
||||||
RE_VERSION = re.compile('.*mpv (\d+)\.(\d+)\.\d+.*')
|
RE_VERSION = re.compile('.*mpv (\d+)\.(\d+)\.\d+.*')
|
||||||
osdMessageSeparator = "\\n"
|
osdMessageSeparator = "\\n"
|
||||||
|
osdMessageSeparator = "; " # TODO: Make conditional
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(client, playerPath, filePath, args):
|
def run(client, playerPath, filePath, args):
|
||||||
|
|||||||
@ -189,6 +189,19 @@ def truncateText(unicodeText, maxLength):
|
|||||||
pass
|
pass
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def splitText(unicodeText, maxLength):
|
||||||
|
try:
|
||||||
|
unicodeText = unicodeText.decode('utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
unicodeText = unicode(unicodeText.encode("utf-8"), "utf-8", errors="ignore")
|
||||||
|
unicodeArray = [unicodeText[i:i + maxLength] for i in range(0, len(unicodeText), maxLength)]
|
||||||
|
return(unicodeArray)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return [""]
|
||||||
|
|
||||||
# Relate to file hashing / difference checking:
|
# Relate to file hashing / difference checking:
|
||||||
|
|
||||||
def stripfilename(filename, stripURL):
|
def stripfilename(filename, stripURL):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user