From 6b61262f44362b0fd331611239e3363f3de94b7a Mon Sep 17 00:00:00 2001 From: Martyn Date: Fri, 25 Sep 2020 20:53:31 +0200 Subject: [PATCH] Include duration in the download status --- dlserver/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dlserver/main.go b/dlserver/main.go index bd29ed7..1575f36 100644 --- a/dlserver/main.go +++ b/dlserver/main.go @@ -26,6 +26,7 @@ func limitLength(s string, length int) string { // globals, huh, faster than channels and oddly more appropriate, we care less about races than feedback. var lastPercentage float64 var lastFilename string +var lastDurationSeconds float64 func convertFile(sourceFileName string, destinationFilename string) error { launch := "./ffmpeg" @@ -71,9 +72,9 @@ func convertFile(sourceFileName string, destinationFilename string) error { mins, _ := strconv.ParseFloat(durations[0][2], 64) secs, _ := strconv.ParseFloat(durations[0][3], 64) aaand, _ := strconv.ParseFloat("0."+durations[0][4], 64) - total := (hrs * 60 * 60) + (mins * 60) + secs + aaand - finalFramesValue = total * FPSValue - fmt.Printf("%0f:%0f:%0f%0.4f * %0.2f = %0.2f seconds = %0.2f frames\n", hrs, mins, secs, aaand, FPSValue, total, finalFramesValue) + lastDurationSeconds = (hrs * 60 * 60) + (mins * 60) + secs + aaand + finalFramesValue = lastDurationSeconds * FPSValue + fmt.Printf("%0f:%0f:%0f%0.4f * %0.2f = %0.2f seconds = %0.2f frames\n", hrs, mins, secs, aaand, FPSValue, lastDurationSeconds, finalFramesValue) } } currentFrames := FrameRe.FindAllStringSubmatch(line, 1) @@ -201,7 +202,7 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) { lastFilename = <-n } */ fmt.Printf("Returning %0.2f for %s\n", lastPercentage, lastFilename) - fmt.Fprintf(w, `{"filename": "%s","percentage":%0.2f}`+"\n", lastFilename, lastPercentage) + fmt.Fprintf(w, `{"filename": "%s","percentage":%0.2f,"duration_seconds":%0.6f}`+"\n", lastFilename, lastPercentage, lastDurationSeconds) } func main() {