mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
player: make --osc/--ytdl settable during playback
Setting the osc or ytdl properties will now load/unload the associated scripts. (For ytdl this does not mean the currently played URL will be reloaded.) Also add a changelog entry for this, which also covers the preceding work for --terminal.
This commit is contained in:
parent
bf5c97a6c3
commit
fb67db8b72
@ -86,6 +86,10 @@ Interface changes
|
||||
has been added to the manpage describing some conflicting behavior
|
||||
between options and properties)
|
||||
- implement changing sub-speed during playback
|
||||
- make many previously fixed options changeable at runtime (for example
|
||||
--terminal, --osc, --ytdl, can all be enable/disabled after
|
||||
mpv_initialize() - this can be extended to other still fixed options
|
||||
on user requests)
|
||||
--- mpv 0.20.0 ---
|
||||
- add --image-display-duration option - this also means that image duration
|
||||
is not influenced by --mf-fps anymore in the general case (this is an
|
||||
|
@ -385,7 +385,8 @@ struct m_option {
|
||||
#define UPDATE_RENDERER (1 << 15) // mainly vo_opengl options
|
||||
#define UPDATE_VIDEOPOS (1 << 16) // video position (panscan etc.)
|
||||
#define UPDATE_OSD (1 << 17) // related to OSD rendering
|
||||
#define UPDATE_OPT_LAST (1 << 17)
|
||||
#define UPDATE_BUILTIN_SCRIPTS (1 << 18) // osc/ytdl
|
||||
#define UPDATE_OPT_LAST (1 << 18)
|
||||
|
||||
// All bits between _FIRST and _LAST (inclusive)
|
||||
#define UPDATE_OPTS_MASK \
|
||||
|
@ -282,8 +282,8 @@ const m_option_t mp_opts[] = {
|
||||
#if HAVE_LUA
|
||||
OPT_STRINGLIST("script", script_files, CONF_GLOBAL | M_OPT_FILE),
|
||||
OPT_KEYVALUELIST("script-opts", script_opts, 0),
|
||||
OPT_FLAG("osc", lua_load_osc, CONF_GLOBAL),
|
||||
OPT_FLAG("ytdl", lua_load_ytdl, CONF_GLOBAL),
|
||||
OPT_FLAG("osc", lua_load_osc, UPDATE_BUILTIN_SCRIPTS),
|
||||
OPT_FLAG("ytdl", lua_load_ytdl, UPDATE_BUILTIN_SCRIPTS),
|
||||
OPT_STRING("ytdl-format", lua_ytdl_format, 0),
|
||||
OPT_KEYVALUELIST("ytdl-raw-options", lua_ytdl_raw_options, 0),
|
||||
OPT_FLAG("load-scripts", auto_load_scripts, CONF_GLOBAL),
|
||||
|
@ -5603,6 +5603,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags)
|
||||
osd_changed(mpctx->osd);
|
||||
mp_wakeup_core(mpctx);
|
||||
}
|
||||
|
||||
if (flags & UPDATE_BUILTIN_SCRIPTS)
|
||||
mp_load_builtin_scripts(mpctx);
|
||||
}
|
||||
|
||||
void mp_notify_property(struct MPContext *mpctx, const char *property)
|
||||
|
@ -549,6 +549,7 @@ struct mp_scripting {
|
||||
int (*load)(struct mpv_handle *client, const char *filename);
|
||||
};
|
||||
void mp_load_scripts(struct MPContext *mpctx);
|
||||
void mp_load_builtin_scripts(struct MPContext *mpctx);
|
||||
|
||||
// sub.c
|
||||
void reset_subtitle_state(struct MPContext *mpctx);
|
||||
|
@ -176,13 +176,41 @@ static char **list_script_files(void *talloc_ctx, char *path)
|
||||
return files;
|
||||
}
|
||||
|
||||
static void load_builtin_script(struct MPContext *mpctx, bool enable,
|
||||
const char *fname)
|
||||
{
|
||||
void *tmp = talloc_new(NULL);
|
||||
// (The name doesn't have to match if there were conflicts with other
|
||||
// scripts, so this is on best-effort basis.)
|
||||
char *name = script_name_from_filename(tmp, fname);
|
||||
if (enable != mp_client_exists(mpctx, name)) {
|
||||
if (enable) {
|
||||
mp_load_script(mpctx, fname);
|
||||
} else {
|
||||
// Try to unload it by sending a shutdown event. Wait until it has
|
||||
// terminated, or re-enabling the script could be racy (because it'd
|
||||
// recognize a still-terminating script as "loaded").
|
||||
while (mp_client_exists(mpctx, name)) {
|
||||
if (mp_client_send_event(mpctx, name, MPV_EVENT_SHUTDOWN, NULL) < 0)
|
||||
break;
|
||||
mp_idle(mpctx);
|
||||
}
|
||||
mp_wakeup_core(mpctx); // avoid lost wakeups during waiting
|
||||
}
|
||||
}
|
||||
talloc_free(tmp);
|
||||
}
|
||||
|
||||
void mp_load_builtin_scripts(struct MPContext *mpctx)
|
||||
{
|
||||
load_builtin_script(mpctx, mpctx->opts->lua_load_osc, "@osc.lua");
|
||||
load_builtin_script(mpctx, mpctx->opts->lua_load_ytdl, "@ytdl_hook.lua");
|
||||
}
|
||||
|
||||
void mp_load_scripts(struct MPContext *mpctx)
|
||||
{
|
||||
// Load scripts from options
|
||||
if (mpctx->opts->lua_load_osc)
|
||||
mp_load_script(mpctx, "@osc.lua");
|
||||
if (mpctx->opts->lua_load_ytdl)
|
||||
mp_load_script(mpctx, "@ytdl_hook.lua");
|
||||
mp_load_builtin_scripts(mpctx);
|
||||
char **files = mpctx->opts->script_files;
|
||||
for (int n = 0; files && files[n]; n++) {
|
||||
if (files[n][0])
|
||||
|
Loading…
Reference in New Issue
Block a user