2023-04-14 22:42:44 -04:00
|
|
|
package ytdl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2023-04-27 13:42:46 -04:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2023-04-14 22:42:44 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
version string
|
|
|
|
versionOnce sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetVersion() string {
|
|
|
|
var err error
|
|
|
|
versionOnce.Do(func() {
|
|
|
|
cmd := exec.Command(
|
2023-04-27 13:42:46 -04:00
|
|
|
viper.GetString("ytdlp_path"),
|
2023-04-14 22:42:44 -04:00
|
|
|
"--version",
|
|
|
|
)
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
version = strings.TrimSpace(out.String())
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return "Error getting version"
|
|
|
|
}
|
|
|
|
|
|
|
|
return version
|
|
|
|
}
|