summaryrefslogtreecommitdiffstats
path: root/player/external_files.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-09-28 00:12:52 +0200
committerwm4 <wm4@nowhere>2020-09-28 00:12:52 +0200
commit55d7f9ded197d82d172b7baf74b1a07640361ae8 (patch)
tree1b471a403226672006655a1a4212b14c49d38c4b /player/external_files.c
parent102a4a8b0654396de7a6355adcf2292a277b6595 (diff)
downloadmpv-55d7f9ded197d82d172b7baf74b1a07640361ae8.tar.bz2
mpv-55d7f9ded197d82d172b7baf74b1a07640361ae8.tar.xz
player: add automatic loading of external cover art files
Picks up files like "cover.jpg". It's made part of normal external file loading, so I'm adding 3 new options that are direct equivalents for the options that control loading of external subtitle and audio files. Even though I bet nobody wants them and they just increase confusion... I guess the world is actually hell, so this outcome should be fine. It prefers non-specific external files like "cover.jpg" over embedded cover art. Not sure if that's wanted or unwanted. There's some pain over explicitly marking such files as external pictures. This is basically an optimization: in most cases, a heuristic would treat an image file loaded with --external-file the same (it's a heuristic because ffmpeg can't tell us whether something is an image or a video). However, even with this heuristic, it would decode the cover art picture again on each seek, which would essentially slow down seeking in audio files. This bothered me greatly, which is why I'm adding these additional options at all, and bothered with the previous commit. Fixes: #3056
Diffstat (limited to 'player/external_files.c')
-rw-r--r--player/external_files.c37
1 files changed, 37 insertions, 0 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);