From 90282f0f746f14461bfa3aa0f3a016cd7e4ee355 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 17 Mar 2025 06:49:56 -0600 Subject: [PATCH] musikr: clean up data translation --- .../oxycblt/musikr/pipeline/ExploreStep.kt | 28 ++++++--------- .../oxycblt/musikr/pipeline/ExtractStep.kt | 34 ++++++++----------- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExploreStep.kt b/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExploreStep.kt index 8f9f4deb7..0bede6678 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExploreStep.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExploreStep.kt @@ -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) } diff --git a/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExtractStep.kt b/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExtractStep.kt index 8ca2fa5ad..12e17e03e 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExtractStep.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/pipeline/ExtractStep.kt @@ -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) }