From 2fd4fd751f1c876eadb708a217b8ccbca9d1beea Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 22 Jan 2025 12:32:17 -0700 Subject: [PATCH] musikr: reformat --- .../org/oxycblt/musikr/graph/PlaylistGraph.kt | 3 +++ .../org/oxycblt/musikr/graph/SongGraph.kt | 8 ++++--- .../oxycblt/musikr/tag/interpret/ID3Genre.kt | 21 +++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/musikr/src/main/java/org/oxycblt/musikr/graph/PlaylistGraph.kt b/musikr/src/main/java/org/oxycblt/musikr/graph/PlaylistGraph.kt index 44641ae02..cf2132d17 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/graph/PlaylistGraph.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/graph/PlaylistGraph.kt @@ -27,14 +27,17 @@ internal class PlaylistGraph { fun link(vertex: PlaylistVertex) { for ((pointer, songVertex) in pointerMap) { + // Link the vertices we are already aware of to this vertex. vertex.pointerMap[pointer]?.forEach { index -> vertex.songVertices[index] = songVertex } } + vertices.add(vertex) } fun link(vertex: SongVertex) { val pointer = SongPointer.UID(vertex.preSong.uid) pointerMap[pointer] = vertex for (playlistVertex in vertices) { + // Retroactively update previously known playlists to add the new vertex. playlistVertex.pointerMap[pointer]?.forEach { index -> playlistVertex.songVertices[index] = vertex } diff --git a/musikr/src/main/java/org/oxycblt/musikr/graph/SongGraph.kt b/musikr/src/main/java/org/oxycblt/musikr/graph/SongGraph.kt index 3f2834009..0e58dd0a4 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/graph/SongGraph.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/graph/SongGraph.kt @@ -30,14 +30,16 @@ internal class SongGraph( private val vertices = mutableMapOf() fun link(vertex: SongVertex): Boolean { - val preSong = vertex.preSong - val uid = preSong.uid + val uid = vertex.preSong.uid if (vertices.containsKey(uid)) { + // Discard songs with duplicate ID's, they wreck the entire + // music model and they're pretty much always the same file. return false } + // Link the vertex to the rest of the graph now. + albumGraph.link(vertex) artistGraph.link(vertex) genreGraph.link(vertex) - albumGraph.link(vertex) playlistGraph.link(vertex) vertices[uid] = vertex return true diff --git a/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/ID3Genre.kt b/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/ID3Genre.kt index e7049f7fe..628f968ab 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/ID3Genre.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/tag/interpret/ID3Genre.kt @@ -1,6 +1,23 @@ +/* + * Copyright (c) 2025 Auxio Project + * ID3Genre.kt is part of Auxio. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.oxycblt.musikr.tag.interpret - /** * Parse a multi-value genre name using ID3 rules. This will convert any ID3v1 integer * representations of genre fields into their named counterparts, and split up singular ID3v2-style @@ -36,7 +53,7 @@ private fun String.parseId3v1Genre(): String? { // try to index the genre table with such. val numeric = toIntOrNull() - // Not a numeric value, try some other fixed values. + // Not a numeric value, try some other fixed values. ?: return when (this) { // CR and RX are not technically ID3v1, but are formatted similarly to a plain // number.