Updated decoder

This commit is contained in:
Brage 2023-07-30 03:17:26 +02:00
parent f97791deeb
commit e368b8d255
2 changed files with 10 additions and 2 deletions

View File

@ -4,5 +4,8 @@ data class Progress(
val workId: String, val workId: String,
val outFileName: String, val outFileName: String,
val progress: Int = -1, val progress: Int = -1,
val time: String,
val duration: String,
val speed: String,
val estimatedCompletion: String = "Unknown", val estimatedCompletion: String = "Unknown",
) )

View File

@ -28,6 +28,7 @@ class ProgressDecoder(val workBase: WorkBase) {
if (field == null || field == 0) if (field == null || field == 0)
field = value field = value
} }
var durationTime: String = "NA"
fun parseVideoProgress(lines: List<String>): DecodedProgressData? { fun parseVideoProgress(lines: List<String>): DecodedProgressData? {
var frame: Int? = null var frame: Int? = null
var progress: String? = null var progress: String? = null
@ -66,6 +67,7 @@ class ProgressDecoder(val workBase: WorkBase) {
} }
fun setDuration(value: String) { fun setDuration(value: String) {
val results = Regex("Duration:\\s*([^,]+),").find(value)?.groupValues?.firstOrNull() val results = Regex("Duration:\\s*([^,]+),").find(value)?.groupValues?.firstOrNull()
durationTime = Regex("[0-9]+:[0-9]+:[0-9]+.[0-9]+").find(results.toString())?.value ?: "NA"
duration = timeSpanToSeconds(results) duration = timeSpanToSeconds(results)
} }
@ -81,7 +83,7 @@ class ProgressDecoder(val workBase: WorkBase) {
fun getProgress(decoded: DecodedProgressData): Progress { fun getProgress(decoded: DecodedProgressData): Progress {
if (duration == null) if (duration == null)
return Progress(workId = workBase.workId, outFileName = File(workBase.outFile).name) return Progress(workId = workBase.workId, outFileName = File(workBase.outFile).name, duration = durationTime, time = "NA", speed = "NA")
val progressTime = timeSpanToSeconds(decoded.out_time) ?: 0 val progressTime = timeSpanToSeconds(decoded.out_time) ?: 0
val diff = floor(progressTime.toDouble() / duration!!.toDouble()) val diff = floor(progressTime.toDouble() / duration!!.toDouble())
val progress = floor(diff*100).toInt() val progress = floor(diff*100).toInt()
@ -91,7 +93,10 @@ class ProgressDecoder(val workBase: WorkBase) {
return Progress( return Progress(
workId = workBase.workId, outFileName = File(workBase.outFile).name, workId = workBase.workId, outFileName = File(workBase.outFile).name,
progress = progress, progress = progress,
estimatedCompletion = getETA(ect) estimatedCompletion = getETA(ect),
duration = durationTime,
time = decoded.out_time ?: "NA",
speed = decoded.speed?.toString() ?: "NA"
) )
} }