musikr: fix various loading bugs
This commit is contained in:
parent
2592aca4bf
commit
df1faa11e4
8 changed files with 39 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -25,10 +25,10 @@ import kotlinx.coroutines.Job
|
|||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.yield
|
||||
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
|
||||
import org.oxycblt.musikr.Musikr
|
||||
import org.oxycblt.musikr.IndexingProgress
|
||||
import org.oxycblt.musikr.Library
|
||||
import org.oxycblt.musikr.Music
|
||||
import org.oxycblt.musikr.Musikr
|
||||
import org.oxycblt.musikr.MutableLibrary
|
||||
import org.oxycblt.musikr.Playlist
|
||||
import org.oxycblt.musikr.Song
|
||||
|
|
|
@ -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
|
||||
|
||||
import org.oxycblt.musikr.fs.Path
|
||||
|
||||
|
||||
interface Library {
|
||||
val songs: Collection<Song>
|
||||
val albums: Collection<Album>
|
||||
|
|
|
@ -63,13 +63,13 @@ constructor(
|
|||
onProgress: suspend (IndexingProgress) -> Unit
|
||||
) = coroutineScope {
|
||||
var exploredCount = 0
|
||||
var extractedCount = 0
|
||||
val explored =
|
||||
exploreStep
|
||||
.explore(locations)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onStart { onProgress(IndexingProgress.Songs(0, 0)) }
|
||||
.onEach { onProgress(IndexingProgress.Songs(0, ++exploredCount)) }
|
||||
var extractedCount = 0
|
||||
.onEach { onProgress(IndexingProgress.Songs(extractedCount, ++exploredCount)) }
|
||||
val extracted =
|
||||
extractStep
|
||||
.extract(explored)
|
||||
|
|
|
@ -38,7 +38,7 @@ sealed interface Cover {
|
|||
}
|
||||
|
||||
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())
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
|
|||
// Link all songs and albums from the irrelevant artist to the relevant artist.
|
||||
dst.songVertices.addAll(src.songVertices)
|
||||
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 {
|
||||
val index = it.artistVertices.indexOf(src)
|
||||
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" }
|
||||
it.artistVertices[index] = dst
|
||||
}
|
||||
src.genreVertices.forEach {
|
||||
it.artistVertices.remove(src)
|
||||
it.artistVertices.add(dst)
|
||||
}
|
||||
|
||||
// Remove the irrelevant artist from the graph.
|
||||
artistVertices.remove(src.preArtist)
|
||||
}
|
||||
|
|
|
@ -70,10 +70,18 @@ constructor(
|
|||
.flowOn(Dispatchers.IO)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
}
|
||||
val writtenSongs =
|
||||
merge(*extractedSongs)
|
||||
.map {
|
||||
tagCache.write(it.file, it.tags)
|
||||
it
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
return merge<ExtractedMusic>(
|
||||
cachedSongs,
|
||||
split.cold,
|
||||
*extractedSongs,
|
||||
writtenSongs,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ inline fun <T, R> Flow<T>.mapPartition(crossinline predicate: (T) -> R?): HotCol
|
|||
emit(it)
|
||||
}
|
||||
}
|
||||
passChannel.close()
|
||||
}
|
||||
return HotCold(passFlow, failFlow)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue