From e6db5909378aab1822d4aefb348739ec1bf4975c Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Mon, 9 Jun 2025 23:28:25 +0500 Subject: [PATCH] Add `GetFFplayVersion` method to retrieve FFplay version details Extended `FFplayContract` with `GetVersion` to fetch FFplay version. Implemented version extraction in `utilities` and `ffplay` to support version retrieval functionality. --- internal/ffmpeg/ffplay.go | 13 +++++++++++++ internal/ffmpeg/utilities.go | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/ffmpeg/ffplay.go b/internal/ffmpeg/ffplay.go index c888842..bb6454d 100644 --- a/internal/ffmpeg/ffplay.go +++ b/internal/ffmpeg/ffplay.go @@ -5,11 +5,13 @@ import ( "fyne.io/fyne/v2/lang" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils" "os/exec" + "regexp" "strings" ) type FFplayContract interface { GetPath() string + GetVersion() (string, error) Play(file *File) error } @@ -39,6 +41,17 @@ func (f *ffplay) GetPath() string { return f.path } +func (f *ffplay) 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 *ffplay) Play(file *File) error { args := []string{file.Path} cmd := exec.Command(f.GetPath(), args...) diff --git a/internal/ffmpeg/utilities.go b/internal/ffmpeg/utilities.go index c6fcfc1..06dae49 100644 --- a/internal/ffmpeg/utilities.go +++ b/internal/ffmpeg/utilities.go @@ -34,6 +34,7 @@ type UtilitiesContract interface { ChangeFFprobe(path string) error GetFFplay() (FFplayContract, error) + GetFFplayVersion() string GetFFplayPath() string ChangeFFplay(path string) error } @@ -182,6 +183,19 @@ func (u *utilities) GetFFplay() (FFplayContract, error) { return u.ffplay, nil } +func (u *utilities) GetFFplayVersion() string { + ffplayService, err := u.GetFFplay() + if err != nil { + return lang.L("errorFFplayVersion") + } + + ffplayVersion, err := ffplayService.GetVersion() + if err != nil { + return lang.L("errorFFplayVersion") + } + return ffplayVersion +} + func (u *utilities) GetFFplayPath() string { ffplayService, err := u.GetFFplay() if err != nil {