mirror of https://github.com/mpv-player/mpv
command: add rescan_external_files
Requested. Hopefully will be useful for things that download and add external subtitles on demand. Or something. Closes #1586.
This commit is contained in:
parent
37183532ae
commit
d26ba961d0
|
@ -400,6 +400,21 @@ List of Input Commands
|
|||
``audio_reload [<id>]``
|
||||
Reload the given audio tracks. See ``sub_reload`` command.
|
||||
|
||||
``rescan_external_files [<mode>]``
|
||||
Rescan external files according to the current ``--sub-auto`` and
|
||||
``--audio-file-auto`` settings. This can be used to auto-load external
|
||||
files *after* the file was loaded.
|
||||
|
||||
The ``mode`` argument is one of the following:
|
||||
|
||||
<keep-selection> (default)
|
||||
Do not change current track selections.
|
||||
|
||||
<reselect>
|
||||
Select the default audio and video streams, which typically selects
|
||||
external files with highest preference. (The implementation is not
|
||||
perfect, and could be improved on request.)
|
||||
|
||||
|
||||
Input Commands that are Possibly Subject to Change
|
||||
--------------------------------------------------
|
||||
|
|
|
@ -199,6 +199,11 @@ const struct mp_cmd_def mp_cmds[] = {
|
|||
{ MP_CMD_AUDIO_REMOVE, "audio_remove", { OARG_INT(-1) } },
|
||||
{ MP_CMD_AUDIO_RELOAD, "audio_reload", { OARG_INT(-1) } },
|
||||
|
||||
{ MP_CMD_RESCAN_EXTERNAL_FILES, "rescan_external_files", {
|
||||
OARG_CHOICE(0, ({"keep-selection", 0},
|
||||
{"reselect", 1})),
|
||||
}},
|
||||
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -111,6 +111,8 @@ enum mp_command_type {
|
|||
MP_CMD_HOOK_ADD,
|
||||
MP_CMD_HOOK_ACK,
|
||||
|
||||
MP_CMD_RESCAN_EXTERNAL_FILES,
|
||||
|
||||
// Internal
|
||||
MP_CMD_COMMAND_LIST, // list of sub-commands in args[0].v.p
|
||||
};
|
||||
|
|
|
@ -4636,6 +4636,24 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
case MP_CMD_RESCAN_EXTERNAL_FILES: {
|
||||
if (!mpctx->playing)
|
||||
return -1;
|
||||
autoload_external_files(mpctx);
|
||||
if (cmd->args[0].v.i) {
|
||||
// somewhat fuzzy and not ideal
|
||||
struct track *a = select_track(mpctx, STREAM_AUDIO, opts->audio_id,
|
||||
opts->audio_id_ff, opts->audio_lang);
|
||||
if (a && a->is_external)
|
||||
mp_switch_track(mpctx, STREAM_AUDIO, a);
|
||||
struct track *s = select_track(mpctx, STREAM_SUB, opts->sub_id,
|
||||
opts->sub_id_ff, opts->sub_lang);
|
||||
if (s && s->is_external)
|
||||
mp_switch_track(mpctx, STREAM_SUB, s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MP_CMD_SCREENSHOT:
|
||||
screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i, msg_osd);
|
||||
break;
|
||||
|
|
|
@ -394,6 +394,9 @@ void mp_play_files(struct MPContext *mpctx);
|
|||
void update_demuxer_properties(struct MPContext *mpctx);
|
||||
void reselect_demux_streams(struct MPContext *mpctx);
|
||||
void prepare_playlist(struct MPContext *mpctx, struct playlist *pl);
|
||||
void autoload_external_files(struct MPContext *mpctx);
|
||||
struct track *select_track(struct MPContext *mpctx, enum stream_type type,
|
||||
int tid, int ffid, char **langs);
|
||||
|
||||
// main.c
|
||||
int mpv_main(int argc, char *argv[]);
|
||||
|
|
|
@ -441,9 +441,8 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs,
|
|||
}
|
||||
return t1->user_tid <= t2->user_tid;
|
||||
}
|
||||
static struct track *select_track(struct MPContext *mpctx,
|
||||
enum stream_type type, int tid, int ffid,
|
||||
char **langs)
|
||||
struct track *select_track(struct MPContext *mpctx, enum stream_type type,
|
||||
int tid, int ffid, char **langs)
|
||||
{
|
||||
if (ffid != -1)
|
||||
tid = -1; // prefer selecting ffid
|
||||
|
@ -727,7 +726,7 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
|
|||
mp_add_external_file(mpctx, opts->sub_name[i], STREAM_SUB);
|
||||
}
|
||||
|
||||
static void autoload_external_files(struct MPContext *mpctx)
|
||||
void autoload_external_files(struct MPContext *mpctx)
|
||||
{
|
||||
if (mpctx->opts->sub_auto < 0 && mpctx->opts->audiofile_auto < 0)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue