From bdfdece245b5aa863b4c57996c38b5638d7797d0 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 9 Apr 2011 05:14:55 +0300 Subject: subs: move vobsub loading logic down to find_subfiles.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Analogously to the previous commit, move path handling logic for loading external vobsub files from mplayer.c to find_subfiles.c. Based on a commit from Clément Bœsch but fixed and simplified. --- sub/find_subfiles.c | 25 +++++++++++++++++++++++++ sub/find_subfiles.h | 1 + 2 files changed, 26 insertions(+) (limited to 'sub') diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index 19ee0f065b..862afe53c6 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -5,6 +5,7 @@ #include "mp_msg.h" #include "path.h" +#include "mpcommon.h" #include "sub/find_subfiles.h" #include "sub/sub.h" @@ -278,3 +279,27 @@ char **find_text_subtitles(const char *fname) free(psub); return tmp; } + +char **find_vob_subtitles(const char *fname) +{ + char **vobs = talloc_array_ptrtype(NULL, vobs, 1); + int n = 0; + + // Potential vobsub in the media directory + struct bstr bname = BSTR(mp_basename(fname)); + int pdot = bstrrchr(bname, '.'); + if (pdot >= 0) + bname.len = pdot; + vobs[n++] = mp_path_join(vobs, mp_dirname(fname), bname); + + // Potential vobsub in ~/.mplayer/sub + char *mp_subdir = get_path("sub/"); + if (mp_subdir) { + MP_GROW_ARRAY(vobs, n); + vobs[n++] = mp_path_join(vobs, BSTR(mp_subdir), bname); + } + + free(mp_subdir); + MP_RESIZE_ARRAY(NULL, vobs, n); + return vobs; +} diff --git a/sub/find_subfiles.h b/sub/find_subfiles.h index c9b0c9137e..c0391277ee 100644 --- a/sub/find_subfiles.h +++ b/sub/find_subfiles.h @@ -22,5 +22,6 @@ #define MAX_SUBTITLE_FILES 128 char **find_text_subtitles(const char *fname); +char **find_vob_subtitles(const char *fname); #endif /* MPLAYER_FINDFILES_H */ -- cgit v1.2.3