mirror of https://github.com/mpv-player/mpv
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:
parent
6a1b12158d
commit
7041d8cd37
|
@ -42,6 +42,11 @@ static struct bstr get_ext(struct bstr s)
|
||||||
return bstr_splice(s, dotpos + 1, s.len);
|
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)
|
static int compare_sub_filename(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const struct subfn *s1 = a;
|
const struct subfn *s1 = a;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#ifndef MPLAYER_FIND_SUBFILES_H
|
#ifndef MPLAYER_FIND_SUBFILES_H
|
||||||
#define MPLAYER_FIND_SUBFILES_H
|
#define MPLAYER_FIND_SUBFILES_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct subfn {
|
struct subfn {
|
||||||
int priority;
|
int priority;
|
||||||
char *fname;
|
char *fname;
|
||||||
|
@ -28,4 +30,6 @@ struct subfn {
|
||||||
struct mpv_global;
|
struct mpv_global;
|
||||||
struct subfn *find_text_subtitles(struct mpv_global *global, const char *fname);
|
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 */
|
#endif /* MPLAYER_FINDFILES_H */
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "video/mp_image.h"
|
#include "video/mp_image.h"
|
||||||
#include "video/vfcap.h"
|
#include "video/vfcap.h"
|
||||||
#include "sub/osd.h"
|
#include "sub/osd.h"
|
||||||
|
#include "sub/find_subfiles.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Externally visible list of all vo drivers
|
// 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.
|
// 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)
|
void vo_drop_files(struct vo *vo, int num_files, char **files)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num_files; i++) {
|
bool all_sub = true;
|
||||||
const char *cmd[] = {
|
for (int i = 0; i < num_files; i++)
|
||||||
"loadfile",
|
all_sub &= mp_might_be_subtitle_file(files[i]);
|
||||||
files[i],
|
|
||||||
/* Start playing the dropped files right away */
|
|
||||||
(i == 0) ? "replace" : "append",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
MP_VERBOSE(vo, "received dropped file: %s\n", files[i]);
|
if (all_sub) {
|
||||||
run_cmd(vo, cmd);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue