From 455d8faf737cd94195ebff10343bab033dd7de7c Mon Sep 17 00:00:00 2001 From: AmarnathCJD Date: Mon, 5 Aug 2024 12:53:00 +0530 Subject: [PATCH] fix bug on video dimensions parsing. --- telegram/helpers.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/telegram/helpers.go b/telegram/helpers.go index 8ef1b6bf..1f88b0f3 100644 --- a/telegram/helpers.go +++ b/telegram/helpers.go @@ -596,13 +596,17 @@ func gatherVideoMetadata(path string, attrs []DocumentAttribute) ([]DocumentAttr } lines := strings.Split(strings.TrimSpace(string(out)), "\n") - for i, line := range lines { - if i == 0 { - width, _ = strconv.ParseInt(strings.TrimSpace(line), 10, 32) - } else if i == 1 { - height, _ = strconv.ParseInt(strings.TrimSpace(line), 10, 32) - } else if i == len(lines)-1 { - dur, _ = strconv.ParseFloat(strings.TrimSpace(line), 64) + dur, _ = strconv.ParseFloat(strings.TrimSpace(lines[len(lines)-1]), 64) + + for _, line := range lines { + line = strings.TrimSpace(line) + if w, err := strconv.ParseInt(line, 10, 32); err == nil { + if width == 0 { + width = w + } else if height == 0 { + height = w + break + } } }