player: load cover art with the media filename

Closes #8666.
This commit is contained in:
Guido Cella 2021-03-22 10:21:52 +01:00 committed by Dudemanguy
parent 89684976ac
commit 029ff1049b
3 changed files with 28 additions and 19 deletions

View File

@ -6695,12 +6695,15 @@ Miscellaneous
option will add a new external file.
``--cover-art-auto=<no|fuzzy>``
Whether to load _external_ cover art automatically (default: fuzzy). Similar
to ``--sub-auto`` and ``--audio-file-auto``. However, it's currently limited
to picking up a whitelist of "album art" filenames (such as ``cover.jpg``),
so currently only the ``fuzzy`` choice is available. In addition, if a video
already has tracks (which are not marked as cover art), external cover art
will not be loaded.
Whether to load _external_ cover art automatically. Similar to
``--sub-auto`` and ``--audio-file-auto``. If a video already has tracks
(which are not marked as cover art), external cover art will not be loaded.
:no: Don't automatically load cover art.
:exact: Load the media filename with an image file extension.
:fuzzy: Load cover art with a filename included in an internal whitelist,
such as ``cover.jpg``.
:all: Union of exact and fuzzy (default).
See ``--cover-art-files`` for details about what constitutes cover art.

View File

@ -594,7 +594,7 @@ static const m_option_t mp_opts[] = {
{"audio-file-auto", OPT_CHOICE(audiofile_auto,
{"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})},
{"cover-art-auto", OPT_CHOICE(coverart_auto,
{"no", -1}, {"fuzzy", 1})},
{"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})},
{"", OPT_SUBSTRUCT(subs_rend, mp_subtitle_sub_opts)},
{"", OPT_SUBSTRUCT(subs_filt, mp_sub_filter_opts)},
@ -1016,7 +1016,7 @@ static const struct MPOpts mp_default_opts = {
.pitch_correction = 1,
.sub_auto = 0,
.audiofile_auto = -1,
.coverart_auto = 1,
.coverart_auto = 2,
.osd_bar_visible = 1,
.screenshot_template = "mpv-shot%n",
.play_dir = 1,

View File

@ -42,6 +42,10 @@ static const char *const audio_exts[] = {"mp3", "aac", "mka", "dts", "flac",
"wv",
NULL};
static const char *const image_exts[] = {"jpg", "jpeg", "png", "gif", "bmp",
"webp",
NULL};
// Stolen from: vlc/-/blob/master/modules/meta_engine/folder.c#L40
// sorted by priority (descending)
static const char *const cover_files[] = {
@ -79,18 +83,19 @@ static int test_ext(bstr ext)
return STREAM_SUB;
if (test_ext_list(ext, audio_exts))
return STREAM_AUDIO;
if (test_ext_list(ext, image_exts))
return STREAM_VIDEO;
return -1;
}
static int test_cover_filename(bstr fname, int *priority)
static int test_cover_filename(bstr fname)
{
for (int n = 0; cover_files[n]; n++) {
if (bstrcasecmp(bstr0(cover_files[n]), fname) == 0) {
*priority = MP_ARRAY_SIZE(cover_files) - n;
return STREAM_VIDEO;
return MP_ARRAY_SIZE(cover_files) - n;
}
}
return -1;
return 0;
}
bool mp_might_be_subtitle_file(const char *filename)
@ -191,10 +196,7 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
talloc_steal(tmpmem2, dename.start);
// check what it is (most likely)
int cover_prio = 0;
int type = test_ext(tmp_fname_ext);
if (type < 0)
type = test_cover_filename(dename, &cover_prio);
char **langs = NULL;
int fuzz = -1;
switch (type) {
@ -218,9 +220,13 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
// higher prio -> auto-selection may prefer it (0 = not loaded)
int prio = 0;
if (bstrcmp(tmp_fname_trim, f_fname_trim) == 0)
if (bstrcmp(tmp_fname_trim, f_fname_trim) == 0 &&
(type != STREAM_VIDEO || (fuzz != 1 && bstrcmp(dename, f_fname) != 0)))
prio |= 32; // exact movie name match
if (type == STREAM_VIDEO)
goto cover_art;
bstr lang = {0};
if (bstr_startswith(tmp_fname_trim, f_fname_trim)) {
int start = 0;
@ -249,9 +255,9 @@ 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 = cover_prio;
cover_art:
if (type == STREAM_VIDEO && fuzz >= 1 && prio == 0)
prio = test_cover_filename(dename);
mp_dbg(log, "Potential external file: \"%s\" Priority: %d\n",
de->d_name, prio);