musikr: fix various loading bugs

This commit is contained in:
Alexander Capehart 2024-12-09 13:06:25 -07:00
parent 2592aca4bf
commit df1faa11e4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
8 changed files with 39 additions and 8 deletions

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2024 Auxio Project * Copyright (c) 2024 Auxio Project
* MusikrModule.kt is part of Auxio. * StackModule.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -25,10 +25,10 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield import kotlinx.coroutines.yield
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
import org.oxycblt.musikr.Musikr
import org.oxycblt.musikr.IndexingProgress import org.oxycblt.musikr.IndexingProgress
import org.oxycblt.musikr.Library import org.oxycblt.musikr.Library
import org.oxycblt.musikr.Music import org.oxycblt.musikr.Music
import org.oxycblt.musikr.Musikr
import org.oxycblt.musikr.MutableLibrary import org.oxycblt.musikr.MutableLibrary
import org.oxycblt.musikr.Playlist import org.oxycblt.musikr.Playlist
import org.oxycblt.musikr.Song import org.oxycblt.musikr.Song

View file

@ -1,8 +1,25 @@
/*
* Copyright (c) 2024 Auxio Project
* Library.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 <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.musikr package org.oxycblt.musikr
import org.oxycblt.musikr.fs.Path import org.oxycblt.musikr.fs.Path
interface Library { interface Library {
val songs: Collection<Song> val songs: Collection<Song>
val albums: Collection<Album> val albums: Collection<Album>

View file

@ -63,13 +63,13 @@ constructor(
onProgress: suspend (IndexingProgress) -> Unit onProgress: suspend (IndexingProgress) -> Unit
) = coroutineScope { ) = coroutineScope {
var exploredCount = 0 var exploredCount = 0
var extractedCount = 0
val explored = val explored =
exploreStep exploreStep
.explore(locations) .explore(locations)
.buffer(Channel.UNLIMITED) .buffer(Channel.UNLIMITED)
.onStart { onProgress(IndexingProgress.Songs(0, 0)) } .onStart { onProgress(IndexingProgress.Songs(0, 0)) }
.onEach { onProgress(IndexingProgress.Songs(0, ++exploredCount)) } .onEach { onProgress(IndexingProgress.Songs(extractedCount, ++exploredCount)) }
var extractedCount = 0
val extracted = val extracted =
extractStep extractStep
.extract(explored) .extract(explored)

View file

@ -38,7 +38,7 @@ sealed interface Cover {
} }
companion object { companion object {
private val FALLBACK_SORT = Sort(Sort.Mode.ByAlbum, Sort.Direction.ASCENDING) private val FALLBACK_SORT = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING)
fun nil() = Multi(listOf()) fun nil() = Multi(listOf())

View file

@ -211,7 +211,7 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
// Link all songs and albums from the irrelevant artist to the relevant artist. // Link all songs and albums from the irrelevant artist to the relevant artist.
dst.songVertices.addAll(src.songVertices) dst.songVertices.addAll(src.songVertices)
dst.albumVertices.addAll(src.albumVertices) dst.albumVertices.addAll(src.albumVertices)
// Update all songs and albums to point to the relevant artist. // Update all songs, albums, and genres to point to the relevant artist.
src.songVertices.forEach { src.songVertices.forEach {
val index = it.artistVertices.indexOf(src) val index = it.artistVertices.indexOf(src)
check(index >= 0) { "Illegal state: directed edge between artist and song" } check(index >= 0) { "Illegal state: directed edge between artist and song" }
@ -222,6 +222,11 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
check(index >= 0) { "Illegal state: directed edge between artist and album" } check(index >= 0) { "Illegal state: directed edge between artist and album" }
it.artistVertices[index] = dst it.artistVertices[index] = dst
} }
src.genreVertices.forEach {
it.artistVertices.remove(src)
it.artistVertices.add(dst)
}
// Remove the irrelevant artist from the graph. // Remove the irrelevant artist from the graph.
artistVertices.remove(src.preArtist) artistVertices.remove(src.preArtist)
} }

View file

@ -70,10 +70,18 @@ constructor(
.flowOn(Dispatchers.IO) .flowOn(Dispatchers.IO)
.buffer(Channel.UNLIMITED) .buffer(Channel.UNLIMITED)
} }
val writtenSongs =
merge(*extractedSongs)
.map {
tagCache.write(it.file, it.tags)
it
}
.flowOn(Dispatchers.IO)
.buffer(Channel.UNLIMITED)
return merge<ExtractedMusic>( return merge<ExtractedMusic>(
cachedSongs, cachedSongs,
split.cold, split.cold,
*extractedSongs, writtenSongs,
) )
} }

View file

@ -40,6 +40,7 @@ inline fun <T, R> Flow<T>.mapPartition(crossinline predicate: (T) -> R?): HotCol
emit(it) emit(it)
} }
} }
passChannel.close()
} }
return HotCold(passFlow, failFlow) return HotCold(passFlow, failFlow)
} }