mirror of https://github.com/mpv-player/mpv
find_subfiles: mp_msg conversions
This commit is contained in:
parent
15ae64d369
commit
92f9b51426
|
@ -693,7 +693,7 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
|
||||||
if (stream_control(mpctx->stream, STREAM_CTRL_GET_BASE_FILENAME,
|
if (stream_control(mpctx->stream, STREAM_CTRL_GET_BASE_FILENAME,
|
||||||
&stream_filename) > 0)
|
&stream_filename) > 0)
|
||||||
base_filename = talloc_steal(tmp, stream_filename);
|
base_filename = talloc_steal(tmp, stream_filename);
|
||||||
struct subfn *list = find_text_subtitles(mpctx->opts, base_filename);
|
struct subfn *list = find_text_subtitles(mpctx->global, base_filename);
|
||||||
talloc_steal(tmp, list);
|
talloc_steal(tmp, list);
|
||||||
for (int i = 0; list && list[i].fname; i++) {
|
for (int i = 0; list && list[i].fname; i++) {
|
||||||
char *filename = list[i].fname;
|
char *filename = list[i].fname;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "osdep/io.h"
|
#include "osdep/io.h"
|
||||||
|
|
||||||
|
#include "common/global.h"
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
#include "options/options.h"
|
#include "options/options.h"
|
||||||
#include "options/path.h"
|
#include "options/path.h"
|
||||||
|
@ -89,12 +90,14 @@ static struct bstr guess_lang_from_filename(struct bstr name)
|
||||||
* @param fname Subtitle filename (pattern)
|
* @param fname Subtitle filename (pattern)
|
||||||
* @param limit_fuzziness Ignore flag when sub_fuziness == 2
|
* @param limit_fuzziness Ignore flag when sub_fuziness == 2
|
||||||
*/
|
*/
|
||||||
static void append_dir_subtitles(struct MPOpts *opts,
|
static void append_dir_subtitles(struct mpv_global *global,
|
||||||
struct subfn **slist, int *nsub,
|
struct subfn **slist, int *nsub,
|
||||||
struct bstr path, const char *fname,
|
struct bstr path, const char *fname,
|
||||||
int limit_fuzziness)
|
int limit_fuzziness)
|
||||||
{
|
{
|
||||||
void *tmpmem = talloc_new(NULL);
|
void *tmpmem = talloc_new(NULL);
|
||||||
|
struct MPOpts *opts = global->opts;
|
||||||
|
struct mp_log *log = mp_log_new(tmpmem, global->log, "find_subfiles");
|
||||||
|
|
||||||
if (mp_is_url(bstr0(fname)))
|
if (mp_is_url(bstr0(fname)))
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -112,7 +115,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
|
||||||
DIR *d = opendir(path0);
|
DIR *d = opendir(path0);
|
||||||
if (!d)
|
if (!d)
|
||||||
goto out;
|
goto out;
|
||||||
mp_msg(MSGT_SUBREADER, MSGL_V, "Load subtitles in %.*s\n", BSTR_P(path));
|
mp_verbose(log, "Load subtitles in %.*s\n", BSTR_P(path));
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
while ((de = readdir(d))) {
|
while ((de = readdir(d))) {
|
||||||
struct bstr dename = bstr0(de->d_name);
|
struct bstr dename = bstr0(de->d_name);
|
||||||
|
@ -158,8 +161,7 @@ static void append_dir_subtitles(struct MPOpts *opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_msg(MSGT_SUBREADER, MSGL_DBG2, "Potential sub file: "
|
mp_dbg(log, "Potential sub file: \"%s\" Priority: %d\n", de->d_name, prio);
|
||||||
"\"%s\" Priority: %d\n", de->d_name, prio);
|
|
||||||
if (prio) {
|
if (prio) {
|
||||||
prio += prio;
|
prio += prio;
|
||||||
char *subpath = mp_path_join(*slist, path, dename);
|
char *subpath = mp_path_join(*slist, path, dename);
|
||||||
|
@ -216,27 +218,28 @@ static void filter_subidx(struct subfn **slist, int *nsub)
|
||||||
|
|
||||||
// Return a list of subtitles found, sorted by priority.
|
// Return a list of subtitles found, sorted by priority.
|
||||||
// Last element is terminated with a fname==NULL entry.
|
// Last element is terminated with a fname==NULL entry.
|
||||||
struct subfn *find_text_subtitles(struct MPOpts *opts, const char *fname)
|
struct subfn *find_text_subtitles(struct mpv_global *global, const char *fname)
|
||||||
{
|
{
|
||||||
|
struct MPOpts *opts = global->opts;
|
||||||
struct subfn *slist = talloc_array_ptrtype(NULL, slist, 1);
|
struct subfn *slist = talloc_array_ptrtype(NULL, slist, 1);
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
// Load subtitles from current media directory
|
// Load subtitles from current media directory
|
||||||
append_dir_subtitles(opts, &slist, &n, mp_dirname(fname), fname, 0);
|
append_dir_subtitles(global, &slist, &n, mp_dirname(fname), fname, 0);
|
||||||
|
|
||||||
// Load subtitles in dirs specified by sub-paths option
|
// Load subtitles in dirs specified by sub-paths option
|
||||||
if (opts->sub_paths) {
|
if (opts->sub_paths) {
|
||||||
for (int i = 0; opts->sub_paths[i]; i++) {
|
for (int i = 0; opts->sub_paths[i]; i++) {
|
||||||
char *path = mp_path_join(slist, mp_dirname(fname),
|
char *path = mp_path_join(slist, mp_dirname(fname),
|
||||||
bstr0(opts->sub_paths[i]));
|
bstr0(opts->sub_paths[i]));
|
||||||
append_dir_subtitles(opts, &slist, &n, bstr0(path), fname, 0);
|
append_dir_subtitles(global, &slist, &n, bstr0(path), fname, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load subtitles in ~/.mpv/sub limiting sub fuzziness
|
// Load subtitles in ~/.mpv/sub limiting sub fuzziness
|
||||||
char *mp_subdir = mp_find_user_config_file("sub/");
|
char *mp_subdir = mp_find_user_config_file("sub/");
|
||||||
if (mp_subdir)
|
if (mp_subdir)
|
||||||
append_dir_subtitles(opts, &slist, &n, bstr0(mp_subdir), fname, 1);
|
append_dir_subtitles(global, &slist, &n, bstr0(mp_subdir), fname, 1);
|
||||||
talloc_free(mp_subdir);
|
talloc_free(mp_subdir);
|
||||||
|
|
||||||
// Sort by name for filter_subidx()
|
// Sort by name for filter_subidx()
|
||||||
|
|
|
@ -19,14 +19,13 @@
|
||||||
#ifndef MPLAYER_FIND_SUBFILES_H
|
#ifndef MPLAYER_FIND_SUBFILES_H
|
||||||
#define MPLAYER_FIND_SUBFILES_H
|
#define MPLAYER_FIND_SUBFILES_H
|
||||||
|
|
||||||
struct MPOpts;
|
|
||||||
|
|
||||||
struct subfn {
|
struct subfn {
|
||||||
int priority;
|
int priority;
|
||||||
char *fname;
|
char *fname;
|
||||||
char *lang;
|
char *lang;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct subfn *find_text_subtitles(struct MPOpts *opts, const char *fname);
|
struct mpv_global;
|
||||||
|
struct subfn *find_text_subtitles(struct mpv_global *global, const char *fname);
|
||||||
|
|
||||||
#endif /* MPLAYER_FINDFILES_H */
|
#endif /* MPLAYER_FINDFILES_H */
|
||||||
|
|
Loading…
Reference in New Issue