diff options
Diffstat (limited to 'player')
-rw-r--r-- | player/external_files.c | 37 | ||||
-rw-r--r-- | player/external_files.h | 2 | ||||
-rw-r--r-- | player/loadfile.c | 16 |
3 files changed, 50 insertions, 5 deletions
diff --git a/player/external_files.c b/player/external_files.c index 69610642d2..40fad916ef 100644 --- a/player/external_files.c +++ b/player/external_files.c @@ -42,6 +42,25 @@ static const char *const audio_exts[] = {"mp3", "aac", "mka", "dts", "flac", "wv", NULL}; +// Stolen from: vlc/-/blob/master/modules/meta_engine/folder.c#L40 +static const char *const cover_files[] = { + "Folder.jpg", + "Folder.png", + "AlbumArtSmall.jpg", + "AlbumArt.jpg", + "Album.jpg", + ".folder.png", + "cover.jpg", + "cover.png", + "cover.gif", + "front.jpg", + "front.png", + "front.gif", + "front.bmp", + "thumb.jpg", + NULL +}; + static bool test_ext_list(bstr ext, const char *const *list) { for (int n = 0; list[n]; n++) { @@ -60,6 +79,15 @@ static int test_ext(bstr ext) return -1; } +static int test_filename(bstr fname) +{ + for (int n = 0; cover_files[n]; n++) { + if (bstrcasecmp(bstr0(cover_files[n]), fname) == 0) + return STREAM_VIDEO; + } + return -1; +} + bool mp_might_be_subtitle_file(const char *filename) { return test_ext(bstr_get_ext(bstr0(filename))) == STREAM_SUB; @@ -159,6 +187,8 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts, // check what it is (most likely) int type = test_ext(tmp_fname_ext); + if (type < 0) + type = test_filename(dename); char **langs = NULL; int fuzz = -1; switch (type) { @@ -170,6 +200,9 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts, langs = opts->stream_lang[type]; fuzz = opts->audiofile_auto; break; + case STREAM_VIDEO: + fuzz = opts->coverart_auto; + break; } if (fuzz < 0 || (limit_type >= 0 && limit_type != type)) @@ -210,6 +243,10 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts, if (!limit_fuzziness && fuzz >= 2) prio |= 1; + // cover art: just accept it + if (type == STREAM_VIDEO && fuzz >= 1) + prio |= 1; + mp_dbg(log, "Potential external file: \"%s\" Priority: %d\n", de->d_name, prio); diff --git a/player/external_files.h b/player/external_files.h index d2de60ee5e..e64f249c6d 100644 --- a/player/external_files.h +++ b/player/external_files.h @@ -21,7 +21,7 @@ #include <stdbool.h> struct subfn { - int type; // STREAM_SUB/STREAM_AUDIO + int type; // STREAM_SUB/STREAM_AUDIO/STREAM_VIDEO(coverart) int priority; char *fname; char *lang; diff --git a/player/loadfile.c b/player/loadfile.c index b5ae9c0212..cb6c1060d7 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -827,6 +827,8 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename, t->external_filename = talloc_strdup(t, filename); t->no_default = sh->type != filter; t->no_auto_select = t->no_default; + // filter==STREAM_VIDEO always means cover art. + t->attached_picture = t->type == STREAM_VIDEO && filter == STREAM_VIDEO; if (first_num < 0 && (filter == STREAM_TYPE_COUNT || sh->type == filter)) first_num = mpctx->num_tracks - 1; } @@ -859,14 +861,15 @@ static void open_external_files(struct MPContext *mpctx, char **files, // See mp_add_external_file() for meaning of cancel parameter. void autoload_external_files(struct MPContext *mpctx, struct mp_cancel *cancel) { - if (mpctx->opts->sub_auto < 0 && mpctx->opts->audiofile_auto < 0) + struct MPOpts *opts = mpctx->opts; + + if (opts->sub_auto < 0 && opts->audiofile_auto < 0 && opts->coverart_auto < 0) return; - if (!mpctx->opts->autoload_files || strcmp(mpctx->filename, "-") == 0) + if (!opts->autoload_files || strcmp(mpctx->filename, "-") == 0) return; void *tmp = talloc_new(NULL); - struct subfn *list = find_external_files(mpctx->global, mpctx->filename, - mpctx->opts); + struct subfn *list = find_external_files(mpctx->global, mpctx->filename, opts); talloc_steal(tmp, list); int sc[STREAM_TYPE_COUNT] = {0}; @@ -887,6 +890,8 @@ void autoload_external_files(struct MPContext *mpctx, struct mp_cancel *cancel) goto skip; if (list[i].type == STREAM_AUDIO && !sc[STREAM_VIDEO]) goto skip; + if (list[i].type == STREAM_VIDEO && (sc[STREAM_VIDEO] || !sc[STREAM_AUDIO])) + goto skip; int first = mp_add_external_file(mpctx, filename, list[i].type, cancel); if (first < 0) goto skip; @@ -894,6 +899,8 @@ void autoload_external_files(struct MPContext *mpctx, struct mp_cancel *cancel) for (int n = first; n < mpctx->num_tracks; n++) { struct track *t = mpctx->tracks[n]; t->auto_loaded = true; + t->attached_picture = + t->type == STREAM_VIDEO && list[i].type == STREAM_VIDEO; if (!t->lang) t->lang = talloc_strdup(t, lang); } @@ -1364,6 +1371,7 @@ static void load_external_opts_thread(void *p) load_chapters(mpctx); open_external_files(mpctx, mpctx->opts->audio_files, STREAM_AUDIO); open_external_files(mpctx, mpctx->opts->sub_name, STREAM_SUB); + open_external_files(mpctx, mpctx->opts->coverart_files, STREAM_VIDEO); open_external_files(mpctx, mpctx->opts->external_files, STREAM_TYPE_COUNT); autoload_external_files(mpctx, mpctx->playback_abort); |