musikr: reformat
This commit is contained in:
parent
584af83a07
commit
b388474655
1 changed files with 39 additions and 41 deletions
|
@ -114,34 +114,31 @@ 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 {
|
||||||
try {
|
|
||||||
// Extract metadata
|
|
||||||
val extractedMetadata = metadataExtractor.extract(f, fd)
|
val extractedMetadata = metadataExtractor.extract(f, fd)
|
||||||
|
|
||||||
if (extractedMetadata != null) {
|
if (extractedMetadata != null) {
|
||||||
// Parse tags
|
|
||||||
val tags = tagParser.parse(extractedMetadata)
|
val tags = tagParser.parse(extractedMetadata)
|
||||||
|
val cover =
|
||||||
// Store cover if present
|
extractedMetadata.cover?.let {
|
||||||
val cover = extractedMetadata.cover?.let {
|
|
||||||
storedCovers.write(it)
|
storedCovers.write(it)
|
||||||
}
|
}
|
||||||
|
val rawSong =
|
||||||
// Create and write the raw song to cache
|
RawSong(
|
||||||
val rawSong = RawSong(f, extractedMetadata.properties, tags, cover, addingMs)
|
f,
|
||||||
wrap(rawSong, cache::write)
|
extractedMetadata.properties,
|
||||||
|
tags,
|
||||||
|
cover,
|
||||||
|
addingMs)
|
||||||
|
cache.write(rawSong)
|
||||||
|
|
||||||
ExtractedMusic.Valid.Song(rawSong)
|
ExtractedMusic.Valid.Song(rawSong)
|
||||||
} else {
|
} else {
|
||||||
ExtractedMusic.Invalid
|
ExtractedMusic.Invalid
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
withContext(Dispatchers.IO) { fd.close() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +149,8 @@ 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 =
|
||||||
|
processedSongs.divert {
|
||||||
when (it) {
|
when (it) {
|
||||||
is ExtractedMusic.Valid.Song -> Divert.Left(it)
|
is ExtractedMusic.Valid.Song -> Divert.Left(it)
|
||||||
is ExtractedMusic.Invalid -> Divert.Right(it)
|
is ExtractedMusic.Invalid -> Divert.Right(it)
|
||||||
|
|
Loading…
Reference in a new issue