musikr: separate silo and covers

This commit is contained in:
Alexander Capehart 2024-12-27 15:50:53 -05:00
parent d964df4616
commit d3f4ed5dd4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 44 additions and 24 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Auxio Project
* CoverSilo.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.covers
import java.util.UUID
import org.oxycblt.musikr.cover.CoverParams
data class CoverSilo(val revision: UUID, val params: CoverParams) {
override fun toString() = "${revision}.${params.resolution}.${params.quality}"
companion object {
fun parse(silo: String): CoverSilo? {
val parts = silo.split('.')
if (parts.size != 3) return null
val revision = parts[0].toUuidOrNull() ?: return null
val resolution = parts[1].toIntOrNull() ?: return null
val quality = parts[2].toIntOrNull() ?: return null
return CoverSilo(revision, CoverParams.of(resolution, quality))
}
}
}
private fun String.toUuidOrNull(): UUID? =
try {
UUID.fromString(this)
} catch (e: IllegalArgumentException) {
null
}

View file

@ -20,13 +20,11 @@ package org.oxycblt.auxio.music.covers
import android.content.Context
import java.io.File
import java.util.UUID
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.oxycblt.musikr.cover.Cover
import org.oxycblt.musikr.cover.CoverFiles
import org.oxycblt.musikr.cover.CoverFormat
import org.oxycblt.musikr.cover.CoverParams
import org.oxycblt.musikr.cover.Covers
import org.oxycblt.musikr.cover.MutableCovers
import org.oxycblt.musikr.cover.ObtainResult
@ -72,21 +70,6 @@ class SiloedCovers(
}
}
data class CoverSilo(val revision: UUID, val params: CoverParams) {
override fun toString() = "${revision}.${params.resolution}.${params.quality}"
companion object {
fun parse(silo: String): CoverSilo? {
val parts = silo.split('.')
if (parts.size != 3) return null
val revision = parts[0].toUuidOrNull() ?: return null
val resolution = parts[1].toIntOrNull() ?: return null
val quality = parts[2].toIntOrNull() ?: return null
return CoverSilo(revision, CoverParams.of(resolution, quality))
}
}
}
class SiloedCover(silo: CoverSilo, val innerCover: Cover) : Cover by innerCover {
private val innerId = SiloedCoverId(silo, innerCover.id)
override val id = innerId.toString()
@ -104,10 +87,3 @@ data class SiloedCoverId(val silo: CoverSilo, val id: String) {
}
}
}
private fun String.toUuidOrNull(): UUID? =
try {
UUID.fromString(this)
} catch (e: IllegalArgumentException) {
null
}