1
mirror of https://github.com/mpv-player/mpv synced 2024-09-09 01:16:56 +02:00

subs: move text sub loading logic down to find_subfiles.c

Move path handling for loading external subtitle files from mplayer.c
to find_subfiles.c. Now the remaining code in mplayer.c only gets a
list of potential filenames and tries opening those.
This commit is contained in:
Clément Bœsch 2011-02-26 20:59:16 +01:00 committed by Uoti Urpala
parent 9bcfbe4d4f
commit 7221e28fe3
3 changed files with 17 additions and 11 deletions

View File

@ -4569,15 +4569,12 @@ if(vo_spudec==NULL &&
add_subtitles(mpctx, opts->sub_name[i], sub_fps, 0);
}
if(opts->sub_auto) { // auto load sub file ...
char *psub = get_path( "sub/" );
char **tmp = sub_filenames((psub ? psub : ""), mpctx->filename);
int i = 0;
free(psub); // release the buffer created by get_path() above
while (tmp[i]) {
add_subtitles(mpctx, tmp[i], sub_fps, 1);
free(tmp[i++]);
}
free(tmp);
char **tmp = find_text_subtitles(mpctx->filename);
for (int i = 0; tmp[i]; i++) {
add_subtitles(mpctx, tmp[i], sub_fps, 1);
free(tmp[i]);
}
free(tmp);
}
if (mpctx->set_of_sub_size > 0)
mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size;

View File

@ -4,6 +4,7 @@
#include <ctype.h>
#include "mp_msg.h"
#include "path.h"
#include "sub/find_subfiles.h"
#include "sub/sub.h"
@ -85,7 +86,7 @@ static int compare_sub_priority(const void *a, const void *b)
}
}
char **sub_filenames(const char *path, char *fname)
static char **sub_filenames(const char *path, const char *fname)
{
char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id;
char *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult;
@ -269,3 +270,11 @@ char **sub_filenames(const char *path, char *fname)
return result2;
}
char **find_text_subtitles(const char *fname)
{
char *psub = get_path("sub/");
char **tmp = sub_filenames(psub ? psub : "", fname);
free(psub);
return tmp;
}

View File

@ -21,6 +21,6 @@
#define MAX_SUBTITLE_FILES 128
char **sub_filenames(const char *path, char *fname);
char **find_text_subtitles(const char *fname);
#endif /* MPLAYER_FINDFILES_H */