From 8666e054030fec70bfaffd3665362ab75dc25ad7 Mon Sep 17 00:00:00 2001 From: Arumugam J Date: Sun, 19 Jan 2025 20:47:38 -0800 Subject: [PATCH] Fix aspect ratio --- .../jsixface/codexvert/api/SavedData.kt | 10 +++------ .../jsixface/codexvert/utils/AspectRatio.kt | 5 ++--- .../codexvert/utils/TypeConverters.kt | 2 +- .../io/github/jsixface/common/MediaModels.kt | 22 +------------------ 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/api/SavedData.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/api/SavedData.kt index 742931f..2673558 100644 --- a/server/src/main/kotlin/io/github/jsixface/codexvert/api/SavedData.kt +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/api/SavedData.kt @@ -1,17 +1,13 @@ package io.github.jsixface.codexvert.api import io.github.jsixface.common.Settings -import io.github.jsixface.common.VideoFile -import java.io.File import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import java.io.File @Serializable -data class SavedData( - val settings: Settings, - val details: MutableMap -) { +data class SavedData(val settings: Settings) { fun save() { val dataStr = json.encodeToString(this) @@ -29,7 +25,7 @@ data class SavedData( return if (dataStr.isNotBlank()) json.decodeFromString(dataStr) else - SavedData(Settings(), mutableMapOf()) + SavedData(Settings()) } } } diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/utils/AspectRatio.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/utils/AspectRatio.kt index 7b59829..dc0a2d1 100644 --- a/server/src/main/kotlin/io/github/jsixface/codexvert/utils/AspectRatio.kt +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/utils/AspectRatio.kt @@ -12,10 +12,9 @@ class AspectRatio(private val w: Float, private val h: Float) { } companion object { - operator fun invoke(ratio: String): AspectRatio { + fun from(ratio: String): AspectRatio? { val measures = ratio.split(":").mapNotNull { it.toFloatOrNull() } - assert(measures.size == 2) { "Should be in the format 'w:h" } - return AspectRatio(measures[0], measures[1]) + return if (measures.size == 2) AspectRatio(measures[0], measures[1]) else null } } } \ No newline at end of file diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/utils/TypeConverters.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/utils/TypeConverters.kt index ab6ab7a..d168b8d 100644 --- a/server/src/main/kotlin/io/github/jsixface/codexvert/utils/TypeConverters.kt +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/utils/TypeConverters.kt @@ -17,7 +17,7 @@ fun VideoEntity.updateInfo(stream: ProbeStream) { profile = stream.profile pixelFormat = stream.pixelFormat resolution = "${stream.width}x${stream.height}" - aspectRatio = AspectRatio(stream.aspectRatio).toString() + aspectRatio = AspectRatio.from(stream.aspectRatio)?.toString() ?: "" frameRate = stream.frameRate.let { if (it.contains('/').not()) it.toFloatOrNull() else { val (f, s) = it.split("/").mapNotNull { x -> x.toFloatOrNull() } diff --git a/shared/src/commonMain/kotlin/io/github/jsixface/common/MediaModels.kt b/shared/src/commonMain/kotlin/io/github/jsixface/common/MediaModels.kt index 99cf744..7c552fc 100644 --- a/shared/src/commonMain/kotlin/io/github/jsixface/common/MediaModels.kt +++ b/shared/src/commonMain/kotlin/io/github/jsixface/common/MediaModels.kt @@ -1,8 +1,5 @@ package io.github.jsixface.common -import kotlinx.datetime.Instant -import kotlinx.datetime.TimeZone -import kotlinx.datetime.toLocalDateTime import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -58,24 +55,7 @@ data class VideoFile( val audios: List = listOf(), val videos: List = listOf(), val subtitles: List = listOf() -) { - val videoInfo: String - get() = videos.joinToString { it.codec } - - val audioInfo: String - get() = audios.joinToString { it.codec } - - val subtitleInfo: String - get() = subtitles.joinToString { it.codec } - - val modified: String - get() { - val dateTime = Instant.fromEpochMilliseconds(modifiedTime) - .toLocalDateTime(TimeZone.currentSystemDefault()) - return "${dateTime.date} ${dateTime.time}" - } - -} +) @Serializable data class MediaStream(