vo: dropping subtitle files on the VO window adds them as subtitle files

Note that we don't try to be clever about detecting the files as
subtitles: we just check the file extension. We could go all the way and
check the files by opening them with a demuxer, but that would probably
do more bad than good.
This commit is contained in:
wm4 2014-01-04 01:27:06 +01:00
parent 6a1b12158d
commit 7041d8cd37
3 changed files with 35 additions and 10 deletions

View File

@ -42,6 +42,11 @@ static struct bstr get_ext(struct bstr s)
return bstr_splice(s, dotpos + 1, s.len);
}
bool mp_might_be_subtitle_file(const char *filename)
{
return is_sub_ext(get_ext(bstr0(filename)));
}
static int compare_sub_filename(const void *a, const void *b)
{
const struct subfn *s1 = a;

View File

@ -19,6 +19,8 @@
#ifndef MPLAYER_FIND_SUBFILES_H
#define MPLAYER_FIND_SUBFILES_H
#include <stdbool.h>
struct subfn {
int priority;
char *fname;
@ -28,4 +30,6 @@ struct subfn {
struct mpv_global;
struct subfn *find_text_subtitles(struct mpv_global *global, const char *fname);
bool mp_might_be_subtitle_file(const char *filename);
#endif /* MPLAYER_FINDFILES_H */

View File

@ -43,6 +43,7 @@
#include "video/mp_image.h"
#include "video/vfcap.h"
#include "sub/osd.h"
#include "sub/find_subfiles.h"
//
// Externally visible list of all vo drivers
@ -631,16 +632,31 @@ static void run_cmd(struct vo *vo, const char **cmd)
// Handle drag & drop event of a list of files on the VO window.
void vo_drop_files(struct vo *vo, int num_files, char **files)
{
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"loadfile",
files[i],
/* Start playing the dropped files right away */
(i == 0) ? "replace" : "append",
NULL
};
bool all_sub = true;
for (int i = 0; i < num_files; i++)
all_sub &= mp_might_be_subtitle_file(files[i]);
MP_VERBOSE(vo, "received dropped file: %s\n", files[i]);
run_cmd(vo, cmd);
if (all_sub) {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"sub_add",
files[i],
NULL
};
run_cmd(vo, cmd);
}
} else {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"loadfile",
files[i],
/* Start playing the dropped files right away */
(i == 0) ? "replace" : "append",
NULL
};
MP_VERBOSE(vo, "received dropped file: %s\n", files[i]);
run_cmd(vo, cmd);
}
}
}