Skip to content

Commit

Permalink
Fix aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
jsixface committed Jan 20, 2025
1 parent aaedb7d commit 8666e05
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, VideoFile>
) {
data class SavedData(val settings: Settings) {

fun save() {
val dataStr = json.encodeToString(this)
Expand All @@ -29,7 +25,7 @@ data class SavedData(
return if (dataStr.isNotBlank())
json.decodeFromString(dataStr)
else
SavedData(Settings(), mutableMapOf())
SavedData(Settings())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -58,24 +55,7 @@ data class VideoFile(
val audios: List<MediaTrack> = listOf(),
val videos: List<MediaTrack> = listOf(),
val subtitles: List<MediaTrack> = 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(
Expand Down

0 comments on commit 8666e05

Please sign in to comment.