From 00cdda2ae80f2f3c5b6fc4302d7edaf14755d037 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 19 Jan 2020 19:25:54 +0100 Subject: scripting: make player error when attempting to load unknown scripts It's ridiculous that --script=something.dumb does not cause an error. Make it error, and extend this behavior to the scripts/ sub-dir in the mpv config dir. --- DOCS/man/mpv.rst | 7 ++++--- player/core.h | 2 +- player/main.c | 3 ++- player/scripting.c | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst index 676cd1897f..9cc0726639 100644 --- a/DOCS/man/mpv.rst +++ b/DOCS/man/mpv.rst @@ -1242,9 +1242,10 @@ For Windows-specifics, see `FILES ON WINDOWS`_ section. ``~/.config/mpv/scripts/`` All files in this directory are loaded as if they were passed to the - ``--script`` option. They are loaded in alphabetical order, and sub-directories - and files with no ``.lua`` extension are ignored. The ``--load-scripts=no`` - option disables loading these files. + ``--script`` option. They are loaded in alphabetical order. Directory entries + other than files are ignored. Files with unknown extension lead to an + initialization error. Files with ``.disable`` extension are ignored. The + ``--load-scripts=no`` option disables loading these files. ``~/.config/mpv/watch_later/`` Contains temporary config files needed for resuming playback of files with diff --git a/player/core.h b/player/core.h index c300c82df9..acb57ddbe2 100644 --- a/player/core.h +++ b/player/core.h @@ -624,7 +624,7 @@ struct mp_scripting { const char *file_ext; // e.g. "lua" int (*load)(struct mpv_handle *client, const char *filename); }; -void mp_load_scripts(struct MPContext *mpctx); +bool mp_load_scripts(struct MPContext *mpctx); void mp_load_builtin_scripts(struct MPContext *mpctx); int mp_load_user_script(struct MPContext *mpctx, const char *fname); diff --git a/player/main.c b/player/main.c index 6cb56ef601..83ded7469a 100644 --- a/player/main.c +++ b/player/main.c @@ -433,7 +433,8 @@ int mp_initialize(struct MPContext *mpctx, char **options) MP_WARN(mpctx, "There will be no OSD and no text subtitles.\n"); #endif - mp_load_scripts(mpctx); + if (!mp_load_scripts(mpctx)) + return -1; if (opts->force_vo == 2 && handle_force_window(mpctx, false) < 0) return -1; diff --git a/player/scripting.c b/player/scripting.c index c37f3af9ce..5f1ae5ce96 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -103,6 +103,9 @@ static void *script_thread(void *p) static int mp_load_script(struct MPContext *mpctx, const char *fname) { char *ext = mp_splitext(fname, NULL); + if (ext && strcasecmp(ext, "disable") == 0) + return 0; + const struct mp_scripting *backend = NULL; for (int n = 0; scripting_backends[n]; n++) { const struct mp_scripting *b = scripting_backends[n]; @@ -113,7 +116,7 @@ static int mp_load_script(struct MPContext *mpctx, const char *fname) } if (!backend) { - MP_VERBOSE(mpctx, "Can't load unknown script: %s\n", fname); + MP_ERR(mpctx, "Can't load unknown script: %s\n", fname); return -1; } @@ -211,16 +214,18 @@ void mp_load_builtin_scripts(struct MPContext *mpctx) load_builtin_script(mpctx, mpctx->opts->lua_load_console, "@console.lua"); } -void mp_load_scripts(struct MPContext *mpctx) +bool mp_load_scripts(struct MPContext *mpctx) { + bool ok = true; + // Load scripts from options char **files = mpctx->opts->script_files; for (int n = 0; files && files[n]; n++) { if (files[n][0]) - mp_load_user_script(mpctx, files[n]); + ok &= mp_load_user_script(mpctx, files[n]) >= 0; } if (!mpctx->opts->auto_load_scripts) - return; + return ok; // Load all scripts void *tmp = talloc_new(NULL); @@ -228,9 +233,11 @@ void mp_load_scripts(struct MPContext *mpctx) for (int i = 0; scriptsdir && scriptsdir[i]; i++) { files = list_script_files(tmp, scriptsdir[i]); for (int n = 0; files && files[n]; n++) - mp_load_script(mpctx, files[n]); + ok &= mp_load_script(mpctx, files[n]) >= 0; } talloc_free(tmp); + + return ok; } #if HAVE_CPLUGINS -- cgit v1.2.3