music: connect stored playlists to loader

This commit is contained in:
Alexander Capehart 2024-11-25 10:19:04 -07:00
parent c4f4797028
commit 73ff7e2c7f
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 16 additions and 6 deletions

View file

@ -48,7 +48,9 @@ constructor(
uris: List<Uri>,
interpretation: Interpretation
) = coroutineScope {
val audioFiles = explorer.explore(uris).flowOn(Dispatchers.Main).buffer()
interpreter.interpret(audioFiles, emptyFlow(), interpretation)
val files = explorer.explore(uris)
val audioFiles = files.audios.flowOn(Dispatchers.IO).buffer()
val playlistFiles = files.playlists.flowOn(Dispatchers.IO).buffer()
interpreter.interpret(audioFiles, playlistFiles, interpretation)
}
}

View file

@ -19,25 +19,33 @@ import org.oxycblt.auxio.music.stack.explore.cache.TagCache
import org.oxycblt.auxio.music.stack.explore.extractor.ExoPlayerTagExtractor
import org.oxycblt.auxio.music.stack.explore.extractor.TagResult
import org.oxycblt.auxio.music.stack.explore.fs.DeviceFiles
import org.oxycblt.auxio.music.stack.explore.playlists.StoredPlaylists
import javax.inject.Inject
interface Explorer {
fun explore(uris: List<Uri>): Flow<AudioFile>
fun explore(uris: List<Uri>): Files
}
data class Files(
val audios: Flow<AudioFile>,
val playlists: Flow<PlaylistFile>
)
class ExplorerImpl @Inject constructor(
private val deviceFiles: DeviceFiles,
private val tagCache: TagCache,
private val tagExtractor: ExoPlayerTagExtractor
private val tagExtractor: ExoPlayerTagExtractor,
private val storedPlaylists: StoredPlaylists
) : Explorer {
override fun explore(uris: List<Uri>): Flow<AudioFile> {
override fun explore(uris: List<Uri>): Files {
val deviceFiles = deviceFiles.explore(uris.asFlow()).flowOn(Dispatchers.IO).buffer()
val tagRead = tagCache.read(deviceFiles).flowOn(Dispatchers.IO).buffer()
val (cacheFiles, cacheSongs) = tagRead.results()
val tagExtractor = tagExtractor.process(cacheFiles).flowOn(Dispatchers.IO).buffer()
val (_, extractorSongs) = tagExtractor.results()
val writtenExtractorSongs = tagCache.write(extractorSongs).flowOn(Dispatchers.IO).buffer()
return merge(cacheSongs, writtenExtractorSongs)
val playlistFiles = storedPlaylists.read()
return Files(merge(cacheSongs, writtenExtractorSongs), playlistFiles)
}
private fun Flow<TagResult>.results(): Pair<Flow<DeviceFile>, Flow<AudioFile>> {