diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index e5577c3912..5efbd20476 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -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; diff --git a/sub/find_subfiles.h b/sub/find_subfiles.h index d11c02627b..85b491f1f9 100644 --- a/sub/find_subfiles.h +++ b/sub/find_subfiles.h @@ -19,6 +19,8 @@ #ifndef MPLAYER_FIND_SUBFILES_H #define MPLAYER_FIND_SUBFILES_H +#include + 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 */ diff --git a/video/out/vo.c b/video/out/vo.c index 689b6b6da1..68fb7d0ee7 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -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); + } } }