From 1c6995d76cfb26a1a87dd4d23a6260e9cf7ecb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Thu, 3 Mar 2011 11:31:12 +0100 Subject: subs: options: add -sub-paths --- DOCS/man/en/mplayer.1 | 35 ++++++++++++++++++++++++++--------- cfg-common.h | 1 + mplayer.c | 4 ++-- options.h | 1 + sub/find_subfiles.c | 28 +++++++++++++++++++++++++--- sub/find_subfiles.h | 6 ++++-- 6 files changed, 59 insertions(+), 16 deletions(-) diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 82d53b5d6d..ea237fd84e 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -2423,7 +2423,7 @@ exact match .IPs 1 Load all subs containing movie name. .IPs 2 -Load all subs in the current directory. +Load all subs in the current and \-sub\-paths directories. .RE .PD 1 . @@ -2490,6 +2490,31 @@ Guess the encoding for Polish, fall back on cp1250. .PD 1 . .TP +.B \-sub\-paths +Specify extra directories where to search for subtitles matching the video. +Multiple directories can be separated by ":" (";" on Windows). +Paths can be relative or absolute. +Relative paths are interpreted relative to video file directory. + +.sp 1 +.I EXAMPLE: +Assuming that /path/\:to/\:movie/\:movie.avi is played and \-sub\-paths +sub:subtitles:/tmp/subs is specified, MPlayer searches for subtitle files in +these directories: +.RSs +/path/\:to/\:movie/ +.br +/path/\:to/\:movie/\:sub/ +.br +/path/\:to/\:movie/\:subtitles/ +.br +/tmp/\:subs/ +.br +~/.mplayer/\:sub/ +.RE +.PD 1 +. +.TP .B \-subdelay Delays subtitles by seconds. Can be negative. @@ -7632,14 +7657,6 @@ font directory (There must be a font.desc file and files with .RAW extension.) .TP ~/.mplayer/\:DVDkeys/ cached CSS keys -. -.TP -Assuming that /path/\:to/\:movie.avi is played, MPlayer searches for sub files -in this order: -.RS -/path/\:to/\:movie.sub -.br -~/.mplayer/\:sub/\:movie.sub .RE .PD 1 . diff --git a/cfg-common.h b/cfg-common.h index b2df2ade0d..ad3a775b2c 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -629,6 +629,7 @@ const m_option_t common_opts[] = { // ------------------------- subtitles options -------------------- OPT_STRINGLIST("sub", sub_name, 0), + OPT_PATHLIST("sub-paths", sub_paths, 0), #ifdef CONFIG_FRIBIDI {"fribidi-charset", &fribidi_charset, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"flip-hebrew", &flip_hebrew, CONF_TYPE_FLAG, 0, 0, 1, NULL}, diff --git a/mplayer.c b/mplayer.c index 9462bf2a52..b801999762 100644 --- a/mplayer.c +++ b/mplayer.c @@ -4174,7 +4174,7 @@ if (edl_output_filename) { mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"Cannot load subtitles: %s\n", filename_recode(opts->vobsub_name)); } else if (opts->sub_auto && mpctx->filename){ - char **vob = find_vob_subtitles(mpctx->filename); + char **vob = find_vob_subtitles(opts, mpctx->filename); for (int i = 0; i < MP_TALLOC_ELEMS(vob); i++) { vo_vobsub = vobsub_open(vob[i], spudec_ifo, 0, &vo_spudec); if (vo_vobsub) @@ -4555,7 +4555,7 @@ if(vo_spudec==NULL && add_subtitles(mpctx, opts->sub_name[i], sub_fps, 0); } if(opts->sub_auto) { // auto load sub file ... - char **tmp = find_text_subtitles(mpctx->filename); + char **tmp = find_text_subtitles(opts, mpctx->filename); int nsub = MP_TALLOC_ELEMS(tmp); for (int i = 0; i < nsub; i++) add_subtitles(mpctx, tmp[i], sub_fps, 1); diff --git a/options.h b/options.h index 459f64fb49..d5cc82c462 100644 --- a/options.h +++ b/options.h @@ -88,6 +88,7 @@ typedef struct MPOpts { int flip; int vd_use_slices; char **sub_name; + char **sub_paths; int sub_auto; int ass_enabled; struct lavc_param { diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index a5834ab733..85ea47b0c2 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -4,6 +4,7 @@ #include #include "mp_msg.h" +#include "options.h" #include "path.h" #include "mpcommon.h" #include "sub/find_subfiles.h" @@ -241,14 +242,24 @@ static void append_dir_subtitles(struct subfn **slist, int *nsub, free(tmpresult); } -char **find_text_subtitles(const char *fname) +char **find_text_subtitles(struct MPOpts *opts, const char *fname) { + char **subnames = NULL; struct subfn *slist = talloc_array_ptrtype(NULL, slist, 1); int n = 0; // Load subtitles from current media directory append_dir_subtitles(&slist, &n, mp_dirname(fname), fname, 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(slist, mp_dirname(fname), + BSTR(opts->sub_paths[i])); + append_dir_subtitles(&slist, &n, BSTR(path), fname, 0); + } + } + // Load subtitles in ~/.mplayer/sub limiting sub fuzziness char *mp_subdir = get_path("sub/"); if (mp_subdir) @@ -258,7 +269,7 @@ char **find_text_subtitles(const char *fname) // Sort subs by priority and append them qsort(slist, n, sizeof(*slist), compare_sub_priority); - char **subnames = talloc_array_ptrtype(NULL, subnames, n); + subnames = talloc_array_ptrtype(NULL, subnames, n); for (int i = 0; i < n; i++) subnames[i] = talloc_strdup(subnames, slist[i].fname); @@ -266,7 +277,7 @@ char **find_text_subtitles(const char *fname) return subnames; } -char **find_vob_subtitles(const char *fname) +char **find_vob_subtitles(struct MPOpts *opts, const char *fname) { char **vobs = talloc_array_ptrtype(NULL, vobs, 1); int n = 0; @@ -278,6 +289,17 @@ char **find_vob_subtitles(const char *fname) bname.len = pdot; vobs[n++] = mp_path_join(vobs, mp_dirname(fname), bname); + // Potential vobsubs in directories specified by sub-paths option + if (opts->sub_paths) { + for (int i = 0; opts->sub_paths[i]; i++) { + char *path = mp_path_join(NULL, mp_dirname(fname), + BSTR(opts->sub_paths[i])); + MP_GROW_ARRAY(vobs, n); + vobs[n++] = mp_path_join(vobs, BSTR(path), bname); + talloc_free(path); + } + } + // Potential vobsub in ~/.mplayer/sub char *mp_subdir = get_path("sub/"); if (mp_subdir) { diff --git a/sub/find_subfiles.h b/sub/find_subfiles.h index c0391277ee..c93164c6f8 100644 --- a/sub/find_subfiles.h +++ b/sub/find_subfiles.h @@ -21,7 +21,9 @@ #define MAX_SUBTITLE_FILES 128 -char **find_text_subtitles(const char *fname); -char **find_vob_subtitles(const char *fname); +struct MPOpts; + +char **find_text_subtitles(struct MPOpts *opts, const char *fname); +char **find_vob_subtitles(struct MPOpts *opts, const char *fname); #endif /* MPLAYER_FINDFILES_H */ -- cgit v1.2.3