musikr: separate silo and covers
This commit is contained in:
parent
d964df4616
commit
d3f4ed5dd4
2 changed files with 44 additions and 24 deletions
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue