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) {
|
when (it) {
|
||||||
is Finalized -> it
|
is Finalized -> it
|
||||||
is NeedsCover -> {
|
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 ->
|
is CoverResult.Hit ->
|
||||||
Finalized(
|
Finalized(it.cachedSong.toRawSong(coverResult.cover))
|
||||||
RawSong(
|
null -> Finalized(it.cachedSong.toRawSong(null))
|
||||||
it.song.file,
|
else ->
|
||||||
it.song.properties,
|
Finalized(NewSong(it.cachedSong.file, it.cachedSong.addedMs))
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +106,10 @@ private class ExploreStepImpl(
|
||||||
|
|
||||||
private sealed interface InternalExploreItem
|
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 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 -> {
|
is NeedsParsing -> {
|
||||||
val tags = tagParser.parse(it.metadata)
|
val tags = tagParser.parse(it.metadata)
|
||||||
val cover =
|
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
|
is CoverResult.Hit -> result.cover
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
NeedsCaching(
|
NeedsCaching(
|
||||||
RawSong(
|
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) {
|
when (it) {
|
||||||
is Finalized -> it
|
is Finalized -> it
|
||||||
is NeedsCaching -> {
|
is NeedsCaching -> {
|
||||||
val cachedSong =
|
cache.write(it.rawSong.toCachedSong())
|
||||||
CachedSong(
|
Finalized(it.rawSong)
|
||||||
it.song.file,
|
|
||||||
it.song.properties,
|
|
||||||
it.song.tags,
|
|
||||||
it.song.cover?.id,
|
|
||||||
it.song.addedMs)
|
|
||||||
cache.write(cachedSong)
|
|
||||||
Finalized(it.song)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map {
|
.map {
|
||||||
if (it.extracted is RawSong) {
|
if (it.extracted is RawSong) {
|
||||||
exclude.add(
|
exclude.add(it.extracted.toCachedSong())
|
||||||
CachedSong(
|
|
||||||
it.extracted.file,
|
|
||||||
it.extracted.properties,
|
|
||||||
it.extracted.tags,
|
|
||||||
it.extracted.cover?.id,
|
|
||||||
it.extracted.addedMs))
|
|
||||||
}
|
}
|
||||||
it.extracted
|
it.extracted
|
||||||
}
|
}
|
||||||
|
@ -122,11 +113,14 @@ private class ExtractStepImpl(
|
||||||
|
|
||||||
private sealed interface ParsedExtractItem
|
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 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 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