options: add --audio-file-paths

Requested. It works like --sub-paths. This will also load audio files
from a "audio" sub directory in the config file (because the same code
as for subtitles is used, and it also had such a feature).

Fixes #2632.
This commit is contained in:
wm4 2015-12-25 13:17:11 +01:00
parent 6d9cb89333
commit 0710ced079
4 changed files with 29 additions and 16 deletions

View File

@ -1204,7 +1204,11 @@ Audio
:no: Don't automatically load external audio files.
:exact: Load the media filename with audio file extension (default).
:fuzzy: Load all audio files containing media filename.
:all: Load all audio files in the current directory.
:all: Load all aufio files in the current and ``--audio-file-paths``
directories.
``--audio-file-paths=<path1:path2:...>``
Equivalent to ``--sub-paths`` option, but for auto-loaded audio files.
``--audio-client-name=<name>``
The application name the player reports to the audio API. Can be useful

View File

@ -332,6 +332,7 @@ const m_option_t mp_opts[] = {
OPT_STRING_APPEND_LIST("sub-file", sub_name, M_OPT_FILE),
OPT_PATHLIST("sub-paths", sub_paths, 0),
OPT_PATHLIST("audio-file-paths", audiofile_paths, 0),
OPT_STRING("sub-codepage", sub_cp, 0),
OPT_FLOAT("sub-delay", sub_delay, 0),
OPT_FLOAT("sub-fps", sub_fps, 0),

View File

@ -237,6 +237,7 @@ typedef struct MPOpts {
int field_dominance;
char **sub_name;
char **sub_paths;
char **audiofile_paths;
int sub_auto;
int audiofile_auto;
int osd_bar_visible;

View File

@ -226,6 +226,23 @@ static void filter_subidx(struct subfn **slist, int *nsub)
}
}
static void load_paths(struct mpv_global *global, struct subfn **slist,
int *nsubs, const char *fname, char **paths,
char *cfg_path)
{
for (int i = 0; paths && paths[i]; i++) {
char *path = mp_path_join_bstr(*slist, mp_dirname(fname),
bstr0(paths[i]));
append_dir_subtitles(global, slist, nsubs, bstr0(path), fname, 0);
}
// Load subtitles in ~/.mpv/sub (or similar) limiting sub fuzziness
char *mp_subdir = mp_find_config_file(NULL, global, cfg_path);
if (mp_subdir)
append_dir_subtitles(global, slist, nsubs, bstr0(mp_subdir), fname, 1);
talloc_free(mp_subdir);
}
// Return a list of subtitles and audio files found, sorted by priority.
// Last element is terminated with a fname==NULL entry.
struct subfn *find_external_files(struct mpv_global *global, const char *fname)
@ -237,22 +254,12 @@ struct subfn *find_external_files(struct mpv_global *global, const char *fname)
// Load subtitles from current media directory
append_dir_subtitles(global, &slist, &n, mp_dirname(fname), fname, 0);
if (opts->sub_auto >= 0) {
// Load subtitles in dirs specified by sub-paths option
if (opts->sub_paths) {
for (int i = 0; opts->sub_paths[i]; i++) {
char *path = mp_path_join_bstr(slist, mp_dirname(fname),
bstr0(opts->sub_paths[i]));
append_dir_subtitles(global, &slist, &n, bstr0(path), fname, 0);
}
}
// Load subtitles in dirs specified by sub-paths option
if (opts->sub_auto >= 0)
load_paths(global, &slist, &n, fname, opts->sub_paths, "sub/");
// Load subtitles in ~/.mpv/sub limiting sub fuzziness
char *mp_subdir = mp_find_config_file(NULL, global, "sub/");
if (mp_subdir)
append_dir_subtitles(global, &slist, &n, bstr0(mp_subdir), fname, 1);
talloc_free(mp_subdir);
}
if (opts->audiofile_auto >= 0)
load_paths(global, &slist, &n, fname, opts->audiofile_paths, "audio/");
// Sort by name for filter_subidx()
qsort(slist, n, sizeof(*slist), compare_sub_filename);