From d7428683e4e32b8077dc21917d4a63c5775db13e Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Mon, 9 Jun 2025 23:25:13 +0500 Subject: [PATCH] Add `GetFFprobeVersion` method to retrieve FFprobe version details Extended `FFprobeContract` with `GetVersion` to fetch FFprobe version. Implemented version extraction in `utilities` and `ffprobe` to support version retrieval functionality. --- internal/ffmpeg/ffprobe.go | 13 +++++++++++++ internal/ffmpeg/utilities.go | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/ffmpeg/ffprobe.go b/internal/ffmpeg/ffprobe.go index ac8c2f9..e56299d 100644 --- a/internal/ffmpeg/ffprobe.go +++ b/internal/ffmpeg/ffprobe.go @@ -5,6 +5,7 @@ import ( "fyne.io/fyne/v2/lang" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils" "os/exec" + "regexp" "strconv" "strings" "unicode" @@ -12,6 +13,7 @@ import ( type FFprobeContract interface { GetPath() string + GetVersion() (string, error) GetTotalDuration(file *File) (float64, error) } @@ -41,6 +43,17 @@ func (f *ffprobe) GetPath() string { return f.path } +func (f *ffprobe) GetVersion() (string, error) { + cmd := exec.Command(f.path, "-version") + utils.PrepareBackgroundCommand(cmd) + out, err := cmd.CombinedOutput() + if err != nil { + return "", err + } + text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1) + return text[0], nil +} + func (f *ffprobe) GetTotalDuration(file *File) (duration float64, err error) { args := []string{"-v", "error", "-select_streams", "v:0", "-count_packets", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", file.Path} cmd := exec.Command(f.path, args...) diff --git a/internal/ffmpeg/utilities.go b/internal/ffmpeg/utilities.go index b0802b7..c6fcfc1 100644 --- a/internal/ffmpeg/utilities.go +++ b/internal/ffmpeg/utilities.go @@ -29,6 +29,7 @@ type UtilitiesContract interface { ChangeFFmpeg(path string) error GetFFprobe() (FFprobeContract, error) + GetFFprobeVersion() string GetFFprobePath() string ChangeFFprobe(path string) error @@ -132,6 +133,19 @@ func (u *utilities) GetFFprobe() (FFprobeContract, error) { return u.ffprobe, nil } +func (u *utilities) GetFFprobeVersion() string { + ffprobeService, err := u.GetFFprobe() + if err != nil { + return lang.L("errorFFprobeVersion") + } + + ffprobeVersion, err := ffprobeService.GetVersion() + if err != nil { + return lang.L("errorFFprobeVersion") + } + return ffprobeVersion +} + func (u *utilities) GetFFprobePath() string { ffprobeService, err := u.GetFFprobe() if err != nil {