musikr: reformat

This commit is contained in:
Alexander Capehart 2025-02-25 16:13:55 -07:00
parent 584af83a07
commit b388474655
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -114,35 +114,32 @@ private class ExtractStepImpl(
flow flow
.mapNotNull { file -> .mapNotNull { file ->
wrap(file) { f -> wrap(file) { f ->
// Open file descriptor withContext(Dispatchers.IO) {
val fd = withContext(Dispatchers.IO) { context.contentResolver.openFileDescriptor(f.uri, "r")
context.contentResolver.openFileDescriptor(f.uri, "r") }
} ?: return@wrap null ?.use {
val extractedMetadata = metadataExtractor.extract(f, fd)
try {
// Extract metadata if (extractedMetadata != null) {
val extractedMetadata = metadataExtractor.extract(f, fd) val tags = tagParser.parse(extractedMetadata)
val cover =
if (extractedMetadata != null) { extractedMetadata.cover?.let {
// Parse tags storedCovers.write(it)
val tags = tagParser.parse(extractedMetadata) }
val rawSong =
// Store cover if present RawSong(
val cover = extractedMetadata.cover?.let { f,
storedCovers.write(it) extractedMetadata.properties,
} tags,
cover,
// Create and write the raw song to cache addingMs)
val rawSong = RawSong(f, extractedMetadata.properties, tags, cover, addingMs) cache.write(rawSong)
wrap(rawSong, cache::write)
ExtractedMusic.Valid.Song(rawSong)
ExtractedMusic.Valid.Song(rawSong) } else {
} else { ExtractedMusic.Invalid
ExtractedMusic.Invalid }
} }
} finally {
withContext(Dispatchers.IO) { fd.close() }
}
} }
} }
.flowOn(Dispatchers.IO) .flowOn(Dispatchers.IO)
@ -152,13 +149,14 @@ private class ExtractStepImpl(
.buffer(Channel.UNLIMITED) .buffer(Channel.UNLIMITED)
// Separate valid processed songs from invalid ones // Separate valid processed songs from invalid ones
val processedFlow = processedSongs.divert { val processedFlow =
when (it) { processedSongs.divert {
is ExtractedMusic.Valid.Song -> Divert.Left(it) when (it) {
is ExtractedMusic.Invalid -> Divert.Right(it) is ExtractedMusic.Valid.Song -> Divert.Left(it)
else -> Divert.Right(ExtractedMusic.Invalid) is ExtractedMusic.Invalid -> Divert.Right(it)
else -> Divert.Right(ExtractedMusic.Invalid)
}
} }
}
val processedValidSongs = processedFlow.left val processedValidSongs = processedFlow.left
val invalidSongs = processedFlow.right val invalidSongs = processedFlow.right