changeset 32773:06b75ec1b9c9

Add sub-paths option. This option allows specifying extra subtitles (relative and absolute) paths to track.
author cboesch
date Sat, 05 Feb 2011 20:38:02 +0000
parents 87a44fc0f23d
children dfeea3d3b2d0
files DOCS/man/en/mplayer.1 cfg-common.h mencoder.c mpcommon.h mplayer.c sub/subreader.c
diffstat 6 files changed, 66 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Sat Feb 05 20:05:38 2011 +0000
+++ b/DOCS/man/en/mplayer.1	Sat Feb 05 20:38:02 2011 +0000
@@ -2557,7 +2557,7 @@
 .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 @@
 .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.
@@ -11741,14 +11762,6 @@
 .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
 .
--- a/cfg-common.h	Sat Feb 05 20:05:38 2011 +0000
+++ b/cfg-common.h	Sat Feb 05 20:38:02 2011 +0000
@@ -562,6 +562,7 @@
 // ------------------------- 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},
--- a/mencoder.c	Sat Feb 05 20:05:38 2011 +0000
+++ b/mencoder.c	Sat Feb 05 20:38:02 2011 +0000
@@ -179,6 +179,7 @@
 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;
--- a/mpcommon.h	Sat Feb 05 20:05:38 2011 +0000
+++ b/mpcommon.h	Sat Feb 05 20:38:02 2011 +0000
@@ -37,6 +37,7 @@
 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;
--- a/mplayer.c	Sat Feb 05 20:05:38 2011 +0000
+++ b/mplayer.c	Sat Feb 05 20:38:02 2011 +0000
@@ -290,6 +290,7 @@
 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;
--- a/sub/subreader.c	Sat Feb 05 20:05:38 2011 +0000
+++ b/sub/subreader.c	Sat Feb 05 20:38:02 2011 +0000
@@ -2088,6 +2088,19 @@
     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_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 @@
         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 @@
         add_f(psub, ifo, 0, spu);
         free(psub);
     }
+
+out:
     free(mp_subdir);
     free(name);
 }