This commit is contained in:
Brage 2024-01-18 12:48:49 +01:00
parent f3d42c06d2
commit fd468520d5
3 changed files with 16 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import com.github.pgreze.process.process
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mu.KotlinLogging
import no.iktdev.exfl.coroutines.Coroutines
import no.iktdev.exfl.using
import no.iktdev.mediaprocessing.processer.ProcesserEnv
@ -15,6 +16,8 @@ class FfmpegWorker(val referenceId: String, val eventId: String, val info: Ffmpe
val scope = Coroutines.io()
val decoder = FfmpegProgressDecoder()
private val outputCache = mutableListOf<String>()
private val log = KotlinLogging.logger {}
val logFile = logDir.using("$eventId-=-${File(info.outFile).nameWithoutExtension}.log")
val getOutputCache = outputCache.toList()
@ -62,17 +65,12 @@ class FfmpegWorker(val referenceId: String, val eventId: String, val info: Ffmpe
stdout = Redirect.CAPTURE,
stderr = Redirect.CAPTURE,
consumer = {
//log.info { it }
onOutputChanged(it)
},
destroyForcibly = true)
val result = processOp
println(Gson().toJson(result))
if (outputCache.isEmpty()) {
result.output.forEach {
onOutputChanged(it)
}
}
onOutputChanged("Received exit code: ${result.resultCode}")
if (result.resultCode != 0) {
listener.onError(info, result.output.joinToString("\n"))
@ -90,7 +88,7 @@ class FfmpegWorker(val referenceId: String, val eventId: String, val info: Ffmpe
fun writeToLog(line: String) {
logFile.printWriter().use {
it.println(line)
it.appendLine(line)
}
}

View File

@ -38,10 +38,12 @@ class Preference {
if (!prefFile.exists()) {
log.info("Preference file: ${prefFile.absolutePath} does not exists...")
log.info("Using default configuration")
silentTry {
val gson = GsonBuilder().setPrettyPrinting().create()
SharedConfig.preference.printWriter().use { out ->
out.print(gson.toJson(PreferenceDto()))
}
}
return null
}
else {

View File

@ -65,3 +65,9 @@ fun getComputername(): String {
return (envs + netHostname).firstOrNull() ?: "UNKNOWN_SYSTEM"
}
fun silentTry(code: () -> Unit) {
try {
code.invoke()
} catch (_: Exception) {}
}