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