summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2022-05-01 07:29:32 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-03-21 03:20:14 +0100
commitd6610a5b2f34e398e2ceba2a4da2b79e556b1c9e (patch)
treecb5d6e8777179a4383067e05c52467d198096912 /player/command.c
parent520849dd48e34e68be09b5f4849fea1d5212fb44 (diff)
downloadmpv-d6610a5b2f34e398e2ceba2a4da2b79e556b1c9e.tar.bz2
mpv-d6610a5b2f34e398e2ceba2a4da2b79e556b1c9e.tar.xz
command: add escape-ass
This adds a command to escape ASS tags to remove code duplication between sub/osd_libass.c, console.lua, osc.lua, stats.lua and any user script that calls mp.create_osd_overlay(). A command is used instead of scripting functions so that all clients can use this and not just use Lua and JS ones. osd_mangle_ass() also interprets osd-sym-cc and osd-ass-cc/{0,1}, but since they use invalid UTF-8 characters there is no risk of escape-ass users using them by accident, like with any OSD message. Always replacing \n with \\N in mangle_ass() even when it is not called by escape-ass doesn't seem to cause any issue, but I made it conditional anyway to avoid changing how all OSD messages are treated unnecessarily.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 27fadf91b1..ce7d6d5541 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5582,6 +5582,19 @@ static void cmd_expand_path(void *p)
};
}
+static void cmd_escape_ass(void *p)
+{
+ struct mp_cmd_ctx *cmd = p;
+ bstr dst = {0};
+
+ osd_mangle_ass(&dst, cmd->args[0].v.s, true);
+
+ cmd->result = (mpv_node){
+ .format = MPV_FORMAT_STRING,
+ .u.string = dst.len ? (char *)dst.start : talloc_strdup(NULL, ""),
+ };
+}
+
static struct load_action get_load_action(struct MPContext *mpctx, int action_flag)
{
switch (action_flag) {
@@ -6679,6 +6692,8 @@ const struct mp_cmd_def mp_cmds[] = {
.is_noisy = true },
{ "expand-path", cmd_expand_path, { {"text", OPT_STRING(v.s)} },
.is_noisy = true },
+ { "escape-ass", cmd_escape_ass, { {"text", OPT_STRING(v.s)} },
+ .is_noisy = true },
{ "show-progress", cmd_show_progress, .allow_auto_repeat = true,
.is_noisy = true },