[MPlayer-dev-eng] [PATCH 3/3] Add subdirs option.
Clément Bœsch
ubitux at gmail.com
Sun Jan 23 20:46:28 CET 2011
---
DOCS/man/en/mplayer.1 | 31 ++++++++++++++++++++++---------
cfg-common.h | 1 +
mencoder.c | 1 +
mpcommon.h | 1 +
mplayer.c | 1 +
sub/subreader.c | 41 ++++++++++++++++++++++++++++++++++++++++-
6 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index a2cac19..a4a93e7 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -2557,7 +2557,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
.
@@ -2624,6 +2624,27 @@ Guess the encoding for Polish, fall back on cp1250.
.PD 1
.
.TP
+.B \-sub-paths <path1,path2,...>
+Specify extra subtitle paths to track in the media 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 <sec>
Delays subtitles by <sec> seconds.
Can be negative.
@@ -11739,14 +11760,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 c6dfef0..cbfa4cf 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -562,6 +562,7 @@ const m_option_t common_opts[] = {
// ------------------------- subtitles options --------------------
{"sub", &sub_name, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
+ {"sub-paths", &sub_paths, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
#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/mencoder.c b/mencoder.c
index 58c3848..5c35756 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -179,6 +179,7 @@ char *font_name=NULL;
char *sub_font_name=NULL;
float font_factor=0.75;
char **sub_name=NULL;
+char **sub_paths = NULL;
float sub_delay=0;
float sub_fps=0;
int sub_auto = 0;
diff --git a/mpcommon.h b/mpcommon.h
index b821730..a75f2e0 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -37,6 +37,7 @@ extern int sub_auto;
extern float sub_delay;
extern float sub_fps;
extern char **sub_name;
+extern char **sub_paths;
extern char *font_name;
extern char *sub_font_name;
extern char *audio_lang;
diff --git a/mplayer.c b/mplayer.c
index cc2f0a9..09e3b5a 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -290,6 +290,7 @@ char *font_name=NULL;
char *sub_font_name=NULL;
float font_factor=0.75;
char **sub_name=NULL;
+char **sub_paths = NULL;
float sub_delay=0;
float sub_fps=0;
int sub_auto = 1;
diff --git a/sub/subreader.c b/sub/subreader.c
index bf100c3..be5bd03 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -2088,6 +2088,19 @@ void load_subtitles(const char *fname, int fps, open_sub_func add_f)
append_dir_subtitles(&slist, path, fname, 0);
free(path);
+ // Load subtitles in dirs specified by sub-paths option
+ if (sub_paths) {
+ for (i = 0; sub_paths[i]; i++) {
+ path = mp_path_join(fname, sub_paths[i]);
+ if (!path) {
+ free(slist.subs);
+ return;
+ }
+ append_dir_subtitles(&slist, path, fname, 0);
+ free(path);
+ }
+ }
+
// Load subtitles in ~/.mplayer/sub limiting sub fuzziness
mp_subdir = get_path("sub/");
if (mp_subdir)
@@ -2115,7 +2128,7 @@ void load_subtitles(const char *fname, int fps, open_sub_func add_f)
void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
open_vob_func add_f)
{
- char *name, *mp_subdir;
+ char *name = NULL, *mp_subdir = NULL;
// Load subtitles specified by vobsub option
if (vobsub_name) {
@@ -2137,6 +2150,30 @@ void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
return;
}
+ // Try looking at the dirs specified by sub-paths option
+ if (sub_paths) {
+ int i;
+
+ for (i = 0; sub_paths[i]; i++) {
+ char *path, *psub;
+
+ path = mp_path_join(fname, sub_paths[i]);
+ if (!path)
+ goto out;
+
+ psub = mp_dir_join(path, mp_basename(name));
+ free(path);
+ if (!psub)
+ goto out;
+
+ if (add_f(psub, ifo, 0, spu)) {
+ free(psub);
+ goto out;
+ }
+ free(psub);
+ }
+ }
+
// If still no VOB found, try loading it from ~/.mplayer/sub
mp_subdir = get_path("sub/");
if (mp_subdir) {
@@ -2144,6 +2181,8 @@ void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
add_f(psub, ifo, 0, spu);
free(psub);
}
+
+out:
free(mp_subdir);
free(name);
}
--
1.7.3.5
More information about the MPlayer-dev-eng
mailing list