summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2021-03-22 10:21:52 +0100
committerDudemanguy <random342@airmail.cc>2021-05-27 18:19:16 +0000
commit029ff1049b4f82d2a0ac9caec7b1314e25049971 (patch)
treeb07a66704b7cd426f83870495b26315dcc940af0
parent89684976acdfae7fdcec9a1b1819ab7f19012332 (diff)
downloadmpv-029ff1049b4f82d2a0ac9caec7b1314e25049971.tar.bz2
mpv-029ff1049b4f82d2a0ac9caec7b1314e25049971.tar.xz
player: load cover art with the media filename
Closes #8666.
-rw-r--r--DOCS/man/options.rst15
-rw-r--r--options/options.c4
-rw-r--r--player/external_files.c28
3 files changed, 28 insertions, 19 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index f8f20d6e32..c153dcd924 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -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.
diff --git a/options/options.c b/options/options.c
index bc903e655a..f54c7bd16c 100644
--- a/options/options.c
+++ b/options/options.c
@@ -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,
diff --git a/player/external_files.c b/player/external_files.c
index 06585bf18f..449e62d623 100644
--- a/player/external_files.c
+++ b/player/external_files.c
@@ -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);