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.
This commit is contained in:
wm4 2020-01-19 19:25:54 +01:00
parent ee7be62dbc
commit 00cdda2ae8
4 changed files with 19 additions and 10 deletions

View File

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

View File

@ -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);

View File

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

View File

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