Leonid Nikitin e6db590937
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.
2025-06-09 23:28:25 +05:00

74 lines
1.4 KiB
Go

package ffmpeg
import (
"errors"
"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
}
type ffplay struct {
path string
}
func newFFplay(path string) (FFplayContract, error) {
if path == "" {
return nil, errors.New(lang.L("errorFFplay"))
}
isCheck, err := checkFFplayPath(path)
if err != nil {
return nil, err
}
if isCheck == false {
return nil, errors.New(lang.L("errorFFplay"))
}
return &ffplay{
path: path,
}, nil
}
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...)
return cmd.Run()
}
func checkFFplayPath(path string) (bool, error) {
cmd := exec.Command(path, "-version")
utils.PrepareBackgroundCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
return false, err
}
if strings.Contains(strings.TrimSpace(string(out)), "ffplay") == false {
return false, nil
}
return true, nil
}