musikr: clean up data translation
This commit is contained in:
parent
63227a1f1f
commit
90282f0f74
2 changed files with 24 additions and 38 deletions
|
@ -84,24 +84,13 @@ private class ExploreStepImpl(
|
|||
when (it) {
|
||||
is Finalized -> it
|
||||
is NeedsCover -> {
|
||||
when (val coverResult = it.song.coverId?.let { covers.obtain(it) }) {
|
||||
when (val coverResult =
|
||||
it.cachedSong.coverId?.let { id -> covers.obtain(id) }) {
|
||||
is CoverResult.Hit ->
|
||||
Finalized(
|
||||
RawSong(
|
||||
it.song.file,
|
||||
it.song.properties,
|
||||
it.song.tags,
|
||||
coverResult.cover,
|
||||
it.song.addedMs))
|
||||
null ->
|
||||
Finalized(
|
||||
RawSong(
|
||||
it.song.file,
|
||||
it.song.properties,
|
||||
it.song.tags,
|
||||
null,
|
||||
it.song.addedMs))
|
||||
else -> Finalized(NewSong(it.song.file, it.song.addedMs))
|
||||
Finalized(it.cachedSong.toRawSong(coverResult.cover))
|
||||
null -> Finalized(it.cachedSong.toRawSong(null))
|
||||
else ->
|
||||
Finalized(NewSong(it.cachedSong.file, it.cachedSong.addedMs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +106,10 @@ private class ExploreStepImpl(
|
|||
|
||||
private sealed interface InternalExploreItem
|
||||
|
||||
private data class NeedsCover(val song: CachedSong) : InternalExploreItem
|
||||
private data class NeedsCover(val cachedSong: CachedSong) : InternalExploreItem
|
||||
|
||||
private data class Finalized(val explored: Explored) : InternalExploreItem
|
||||
|
||||
private fun CachedSong.toRawSong(cover: Cover?) =
|
||||
RawSong(file, properties, tags, cover, addedMs)
|
||||
}
|
||||
|
|
|
@ -75,13 +75,17 @@ private class ExtractStepImpl(
|
|||
is NeedsParsing -> {
|
||||
val tags = tagParser.parse(it.metadata)
|
||||
val cover =
|
||||
when (val result = covers.create(it.song.file, it.metadata)) {
|
||||
when (val result = covers.create(it.newSong.file, it.metadata)) {
|
||||
is CoverResult.Hit -> result.cover
|
||||
else -> null
|
||||
}
|
||||
NeedsCaching(
|
||||
RawSong(
|
||||
it.song.file, it.metadata.properties, tags, cover, it.song.addedMs))
|
||||
it.newSong.file,
|
||||
it.metadata.properties,
|
||||
tags,
|
||||
cover,
|
||||
it.newSong.addedMs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,27 +95,14 @@ private class ExtractStepImpl(
|
|||
when (it) {
|
||||
is Finalized -> it
|
||||
is NeedsCaching -> {
|
||||
val cachedSong =
|
||||
CachedSong(
|
||||
it.song.file,
|
||||
it.song.properties,
|
||||
it.song.tags,
|
||||
it.song.cover?.id,
|
||||
it.song.addedMs)
|
||||
cache.write(cachedSong)
|
||||
Finalized(it.song)
|
||||
cache.write(it.rawSong.toCachedSong())
|
||||
Finalized(it.rawSong)
|
||||
}
|
||||
}
|
||||
}
|
||||
.map {
|
||||
if (it.extracted is RawSong) {
|
||||
exclude.add(
|
||||
CachedSong(
|
||||
it.extracted.file,
|
||||
it.extracted.properties,
|
||||
it.extracted.tags,
|
||||
it.extracted.cover?.id,
|
||||
it.extracted.addedMs))
|
||||
exclude.add(it.extracted.toCachedSong())
|
||||
}
|
||||
it.extracted
|
||||
}
|
||||
|
@ -122,11 +113,14 @@ private class ExtractStepImpl(
|
|||
|
||||
private sealed interface ParsedExtractItem
|
||||
|
||||
private data class NeedsParsing(val song: NewSong, val metadata: Metadata) : ParsedExtractItem
|
||||
private data class NeedsParsing(val newSong: NewSong, val metadata: Metadata) :
|
||||
ParsedExtractItem
|
||||
|
||||
private sealed interface ParsedCachingItem
|
||||
|
||||
private data class NeedsCaching(val song: RawSong) : ParsedCachingItem
|
||||
private data class NeedsCaching(val rawSong: RawSong) : ParsedCachingItem
|
||||
|
||||
private data class Finalized(val extracted: Extracted) : ParsedExtractItem, ParsedCachingItem
|
||||
|
||||
private fun RawSong.toCachedSong() = CachedSong(file, properties, tags, cover?.id, addedMs)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue