From 6f6a3d8d31ea97c2e3e10a69c51758a46b10dfdf Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sun, 25 Jun 2023 16:46:21 -0600 Subject: [PATCH] music: handle duplicate artist/genre values Remove functionally duplicate artist/genre values that were read from a file. This caused a indexer crash in 3.1.2 due to the switch to music sets, which no longer made duplicate values group the song twice. This then cascaded to a failure in song finalization, as it expects there to be the same amount of artists/genres as raw artists/genres. --- .../org/oxycblt/auxio/music/device/DeviceMusicImpl.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt index d2a614be7..9654cb187 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt @@ -152,6 +152,7 @@ class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Son rawArtists = rawAlbumArtists .ifEmpty { rawIndividualArtists } + .distinctBy { it.key } .ifEmpty { listOf(RawArtist(null, null)) }) /** @@ -160,7 +161,10 @@ class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Son * [RawArtist]. This can be used to group up [Song]s into an [Artist]. */ val rawArtists = - rawIndividualArtists.ifEmpty { rawAlbumArtists }.ifEmpty { listOf(RawArtist()) } + rawIndividualArtists + .ifEmpty { rawAlbumArtists } + .distinctBy { it.key } + .ifEmpty { listOf(RawArtist()) } /** * The [RawGenre] instances collated by the [Song]. This can be used to group up [Song]s into a @@ -170,6 +174,7 @@ class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Son rawSong.genreNames .parseId3GenreNames(musicSettings) .map { RawGenre(it) } + .distinctBy { it.key } .ifEmpty { listOf(RawGenre()) } /** @@ -208,6 +213,7 @@ class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Son checkNotNull(_album) { "Malformed song: No album" } check(_artists.isNotEmpty()) { "Malformed song: No artists" } + check(_artists.size == rawArtists.size) { "Malformed song: Artist grouping mismatch" } for (i in _artists.indices) { // Non-destructively reorder the linked artists so that they align with // the artist ordering within the song metadata. @@ -218,7 +224,7 @@ class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Son } check(_genres.isNotEmpty()) { "Malformed song: No genres" } - logD("$this $rawGenres $_genres]") + check(_genres.size == rawGenres.size) { "Malformed song: Genre grouping mismatch"} for (i in _genres.indices) { // Non-destructively reorder the linked genres so that they align with // the genre ordering within the song metadata. @@ -336,6 +342,7 @@ class AlbumImpl( fun finalize(): Album { check(songs.isNotEmpty()) { "Malformed album: Empty" } check(_artists.isNotEmpty()) { "Malformed album: No artists" } + check(_artists.size == rawArtists.size) { "Malformed song: Artist grouping mismatch" } for (i in _artists.indices) { // Non-destructively reorder the linked artists so that they align with // the artist ordering within the song metadata.