summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-25 13:17:11 +0100
committerwm4 <wm4@nowhere>2015-12-25 13:17:11 +0100
commit0710ced0792f3ec83c337d1b4f48ff13950f7f33 (patch)
treed370c75f08f11d4aa661aaae55e56f353a3bfe93
parent6d9cb89333782c1c7043f58cc4b0c713c2e871d6 (diff)
downloadmpv-0710ced0792f3ec83c337d1b4f48ff13950f7f33.tar.bz2
mpv-0710ced0792f3ec83c337d1b4f48ff13950f7f33.tar.xz
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.
-rw-r--r--DOCS/man/options.rst6
-rw-r--r--options/options.c1
-rw-r--r--options/options.h1
-rw-r--r--player/external_files.c37
4 files changed, 29 insertions, 16 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 8324f6a18b..e5b8499520 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -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
diff --git a/options/options.c b/options/options.c
index 058265ae69..b001712349 100644
--- a/options/options.c
+++ b/options/options.c
@@ -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),
diff --git a/options/options.h b/options/options.h
index 53b8cc4564..ea3ee00b30 100644
--- a/options/options.h
+++ b/options/options.h
@@ -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;
diff --git a/player/external_files.c b/player/external_files.c
index 486b492dd2..5dedfc920f 100644
--- a/player/external_files.c
+++ b/player/external_files.c
@@ -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);