From db0682a469cbf6303bbb96e770a7b6fd1a485d05 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 25 May 2021 22:37:26 +0200
Subject: [PATCH 1/8] db/update/Walk: move code to LoadExcludeList()

---
 src/db/update/Walk.cxx | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index 6391ed445..1c01934d6 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -312,6 +312,29 @@ UpdateWalk::SkipSymlink(const Directory *directory,
 #endif
 }
 
+static void
+LoadExcludeListOrThrow(const Storage &storage, const Directory &directory,
+		       ExcludeList &exclude_list)
+{
+	Mutex mutex;
+	auto is = InputStream::OpenReady(storage.MapUTF8(PathTraitsUTF8::Build(directory.GetPath(),
+									       ".mpdignore")).c_str(),
+					 mutex);
+	exclude_list.Load(std::move(is));
+}
+
+static void
+LoadExcludeListOrLog(const Storage &storage, const Directory &directory,
+		     ExcludeList &exclude_list) noexcept
+{
+	try {
+		LoadExcludeListOrThrow(storage, directory, exclude_list);
+	} catch (...) {
+		if (!IsFileNotFound(std::current_exception()))
+			LogError(std::current_exception());
+	}
+}
+
 bool
 UpdateWalk::UpdateDirectory(Directory &directory,
 			    const ExcludeList &exclude_list,
@@ -331,17 +354,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
 	}
 
 	ExcludeList child_exclude_list(exclude_list);
-
-	try {
-		Mutex mutex;
-		auto is = InputStream::OpenReady(storage.MapUTF8(PathTraitsUTF8::Build(directory.GetPath(),
-										       ".mpdignore")).c_str(),
-						 mutex);
-		child_exclude_list.Load(std::move(is));
-	} catch (...) {
-		if (!IsFileNotFound(std::current_exception()))
-			LogError(std::current_exception());
-	}
+	LoadExcludeListOrLog(storage, directory, child_exclude_list);
 
 	if (!child_exclude_list.IsEmpty())
 		RemoveExcludedFromDirectory(directory, child_exclude_list);

From 363d9f0180a9a3e201e1ce354f9a484b1a431215 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 25 May 2021 22:35:18 +0200
Subject: [PATCH 2/8] db/update/Walk: load all .mpdignore files of all parent
 directories

When updating everything, this did work, but if updating only a
subdirectory, the ".mpdignore" in the parents were not used.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1172
---
 NEWS                   |  2 ++
 src/db/update/Walk.cxx | 27 ++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 9883f913b..b3972e557 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.22.9 (not yet released)
+* database
+  - simple: load all .mpdignore files of all parent directories
 * Windows
   - fix build failure with SQLite
 
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index 1c01934d6..b1fb675e6 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -458,6 +458,28 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root,
 	return directory;
 }
 
+static void
+LoadExcludeLists(std::forward_list<ExcludeList> &lists,
+		 const Storage &storage, const Directory &directory) noexcept
+{
+	assert(!lists.empty());
+
+	if (!directory.IsRoot())
+		LoadExcludeLists(lists, storage, *directory.parent);
+
+	lists.emplace_front();
+	LoadExcludeListOrLog(storage, directory, lists.front());
+}
+
+static auto
+LoadExcludeLists(const Storage &storage, const Directory &directory) noexcept
+{
+	std::forward_list<ExcludeList> lists;
+	lists.emplace_front();
+	LoadExcludeLists(lists, storage, directory);
+	return lists;
+}
+
 inline void
 UpdateWalk::UpdateUri(Directory &root, const char *uri) noexcept
 try {
@@ -478,9 +500,8 @@ try {
 		return;
 	}
 
-	ExcludeList exclude_list;
-
-	UpdateDirectoryChild(*parent, exclude_list, name, info);
+	const auto exclude_lists = LoadExcludeLists(storage, *parent);
+	UpdateDirectoryChild(*parent, exclude_lists.front(), name, info);
 } catch (...) {
 	LogError(std::current_exception());
 }

From 6d567bcd357ffe0bc99f128f09480610914680e7 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 12:41:53 +0200
Subject: [PATCH 3/8] decoder/ffmpeg: fix ArtistSort and AlbumArtistSort
 mapping

These were added 11 years ago in commit 766b9fd453a, but I cannot find
any evidence in the FFmpeg repository that these names were ever
supported.  This commit adds the tags as they are currently present in
libavformat/mov.c.
---
 src/decoder/plugins/FfmpegMetaData.cxx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 4ca45afb8..0d1456016 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -32,9 +32,9 @@ extern "C" {
 
 static constexpr struct tag_table ffmpeg_tags[] = {
 	{ "year", TAG_DATE },
-	{ "author-sort", TAG_ARTIST_SORT },
 	{ "album_artist", TAG_ALBUM_ARTIST },
-	{ "album_artist-sort", TAG_ALBUM_ARTIST_SORT },
+	{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
+	{ "sort_artist", TAG_ARTIST_SORT },
 
 	/* sentinel */
 	{ nullptr, TAG_NUM_OF_ITEM_TYPES }

From 4ec4bab3a96963a5c3c2e75dc23d325b972ab508 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 12:56:50 +0200
Subject: [PATCH 4/8] decoder/ffmpeg: remove "year" tag

This mapping was added 11 years ago in commit 766b9fd453a, but FFmpeg
doesn't appear to support it.
---
 src/decoder/plugins/FfmpegMetaData.cxx | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 0d1456016..75c06c282 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -31,7 +31,6 @@ extern "C" {
 }
 
 static constexpr struct tag_table ffmpeg_tags[] = {
-	{ "year", TAG_DATE },
 	{ "album_artist", TAG_ALBUM_ARTIST },
 	{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
 	{ "sort_artist", TAG_ARTIST_SORT },

From 8f3341cefb496cd82c71b370884434f49efd93b7 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 12:57:24 +0200
Subject: [PATCH 5/8] decoder/ffmpeg: add comment

---
 src/decoder/plugins/FfmpegMetaData.cxx | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 75c06c282..316c85481 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -30,8 +30,15 @@ extern "C" {
 #include <libavutil/dict.h>
 }
 
+/**
+ * FFmpeg specific tag name mappings, as supported by
+ * libavformat/id3v2.c, libavformat/mov.c and others.
+ */
 static constexpr struct tag_table ffmpeg_tags[] = {
+	/* from libavformat/id3v2.c, libavformat/mov.c */
 	{ "album_artist", TAG_ALBUM_ARTIST },
+
+	/* from libavformat/mov.c */
 	{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
 	{ "sort_artist", TAG_ARTIST_SORT },
 

From fbaedf2262f1d68f1aa35f27291893ffeb90f487 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 12:41:41 +0200
Subject: [PATCH 6/8] decoder/ffmpeg: support the "sort_album" tag

From libavformat/mov.c.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1173
---
 NEWS                                   | 2 ++
 src/decoder/plugins/FfmpegMetaData.cxx | 1 +
 2 files changed, 3 insertions(+)

diff --git a/NEWS b/NEWS
index b3972e557..39aea4111 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 ver 0.22.9 (not yet released)
 * database
   - simple: load all .mpdignore files of all parent directories
+* decoder
+  - ffmpeg: support the "sort_album" tag
 * Windows
   - fix build failure with SQLite
 
diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 316c85481..1c30c467b 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -40,6 +40,7 @@ static constexpr struct tag_table ffmpeg_tags[] = {
 
 	/* from libavformat/mov.c */
 	{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
+	{ "sort_album", TAG_ALBUM_SORT },
 	{ "sort_artist", TAG_ARTIST_SORT },
 
 	/* sentinel */

From 38e24208f61b37bb5e6edd89ee9f4ad0ea778a09 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 13:04:45 +0200
Subject: [PATCH 7/8] decoder/ffmpeg: support the tags "album-sort",
 "artist-sort"

---
 src/decoder/plugins/FfmpegMetaData.cxx | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/decoder/plugins/FfmpegMetaData.cxx b/src/decoder/plugins/FfmpegMetaData.cxx
index 1c30c467b..54fef3136 100644
--- a/src/decoder/plugins/FfmpegMetaData.cxx
+++ b/src/decoder/plugins/FfmpegMetaData.cxx
@@ -38,6 +38,10 @@ static constexpr struct tag_table ffmpeg_tags[] = {
 	/* from libavformat/id3v2.c, libavformat/mov.c */
 	{ "album_artist", TAG_ALBUM_ARTIST },
 
+	/* from libavformat/id3v2.c */
+	{ "album-sort", TAG_ALBUM_SORT },
+	{ "artist-sort", TAG_ARTIST_SORT },
+
 	/* from libavformat/mov.c */
 	{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
 	{ "sort_album", TAG_ALBUM_SORT },

From 3775766605b4caa2c2d087d6545bcee4411aa7b0 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 26 May 2021 13:07:01 +0200
Subject: [PATCH 8/8] NEWS: mention new FFmpeg/ID3v2 tags

---
 NEWS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 39aea4111..47947cc16 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@ ver 0.22.9 (not yet released)
 * database
   - simple: load all .mpdignore files of all parent directories
 * decoder
-  - ffmpeg: support the "sort_album" tag
+  - ffmpeg: support the tags "sort_album", "album-sort", "artist-sort"
 * Windows
   - fix build failure with SQLite