summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-22 20:43:33 +0200
committerwm4 <wm4@nowhere>2016-09-22 20:57:06 +0200
commit2ac74977c5f6561e33ad37c68b9da47739c7fd6c (patch)
tree9c1ec9fc83be8ca0583d06692a36fa170232ae61
parent01e95468f96ac14fead2ffe2d53ed11acfbe8a39 (diff)
downloadmpv-2ac74977c5f6561e33ad37c68b9da47739c7fd6c.tar.bz2
mpv-2ac74977c5f6561e33ad37c68b9da47739c7fd6c.tar.xz
command: add a load-script command
The intention is to give libmpv users as much flexibility to load scripts as using mpv from CLI, but without restricting libmpv users from having to decide everything on creation time, or having to go through hacks like recreating the libmpv context to update state.
-rw-r--r--DOCS/man/input.rst3
-rw-r--r--input/cmd_list.c2
-rw-r--r--input/cmd_list.h2
-rw-r--r--player/command.c7
-rw-r--r--player/core.h1
-rw-r--r--player/scripting.c10
6 files changed, 20 insertions, 5 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 50832ccd30..8e61c22daa 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -699,6 +699,9 @@ Input Commands that are Possibly Subject to Change
There is no such thing as "unapplying" a profile - applying a profile
merely sets all option values listed within the profile.
+``load-script "<path>"``
+ Load a script, similar to the ``--script`` option.
+
Undocumented commands: ``tv-last-channel`` (TV/DVB only),
``ao-reload`` (experimental/internal).
diff --git a/input/cmd_list.c b/input/cmd_list.c
index f6db9cbba8..53cc375b3a 100644
--- a/input/cmd_list.c
+++ b/input/cmd_list.c
@@ -226,6 +226,8 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_APPLY_PROFILE, "apply-profile", {ARG_STRING } },
+ { MP_CMD_LOAD_SCRIPT, "load-script", {ARG_STRING} },
+
{0}
};
diff --git a/input/cmd_list.h b/input/cmd_list.h
index e0fd8fa2de..1c2330b589 100644
--- a/input/cmd_list.h
+++ b/input/cmd_list.h
@@ -116,6 +116,8 @@ enum mp_command_type {
MP_CMD_APPLY_PROFILE,
+ MP_CMD_LOAD_SCRIPT,
+
// Internal
MP_CMD_COMMAND_LIST, // list of sub-commands in args[0].v.p
};
diff --git a/player/command.c b/player/command.c
index 2296c97f7b..d49b844caf 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5472,6 +5472,13 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
break;
}
+ case MP_CMD_LOAD_SCRIPT: {
+ char *script = cmd->args[0].v.s;
+ if (mp_load_script(mpctx, script) < 0)
+ return -1;
+ break;
+ }
+
default:
MP_VERBOSE(mpctx, "Received unknown cmd %s\n", cmd->name);
return -1;
diff --git a/player/core.h b/player/core.h
index d67a9d62ad..53e6e6f99c 100644
--- a/player/core.h
+++ b/player/core.h
@@ -550,6 +550,7 @@ struct mp_scripting {
};
void mp_load_scripts(struct MPContext *mpctx);
void mp_load_builtin_scripts(struct MPContext *mpctx);
+int mp_load_script(struct MPContext *mpctx, const char *fname);
// sub.c
void reset_subtitle_state(struct MPContext *mpctx);
diff --git a/player/scripting.c b/player/scripting.c
index b6ba69ac07..76395c6ad6 100644
--- a/player/scripting.c
+++ b/player/scripting.c
@@ -100,7 +100,7 @@ static void wait_loaded(struct MPContext *mpctx)
mp_wakeup_core(mpctx); // avoid lost wakeups during waiting
}
-static void mp_load_script(struct MPContext *mpctx, const char *fname)
+int mp_load_script(struct MPContext *mpctx, const char *fname)
{
char *ext = mp_splitext(fname, NULL);
const struct mp_scripting *backend = NULL;
@@ -114,7 +114,7 @@ static void mp_load_script(struct MPContext *mpctx, const char *fname)
if (!backend) {
MP_VERBOSE(mpctx, "Can't load unknown script: %s\n", fname);
- return;
+ return -1;
}
struct thread_arg *arg = talloc_ptrtype(NULL, arg);
@@ -129,7 +129,7 @@ static void mp_load_script(struct MPContext *mpctx, const char *fname)
};
if (!arg->client) {
talloc_free(arg);
- return;
+ return -1;
}
arg->log = mp_client_get_log(arg->client);
@@ -139,13 +139,13 @@ static void mp_load_script(struct MPContext *mpctx, const char *fname)
if (pthread_create(&thread, NULL, script_thread, arg)) {
mpv_detach_destroy(arg->client);
talloc_free(arg);
- return;
+ return -1;
}
wait_loaded(mpctx);
MP_VERBOSE(mpctx, "Done loading %s.\n", fname);
- return;
+ return 0;
}
static int compare_filename(const void *pa, const void *pb)