From 06427b39debe64c58ec12b7f745771a31eff627d Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Fri, 17 Feb 2023 02:50:18 +0300 Subject: [PATCH] add ffprobe path lookup --- server/web/api/ffprobe.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/server/web/api/ffprobe.go b/server/web/api/ffprobe.go index 045f0e0..1ca2894 100644 --- a/server/web/api/ffprobe.go +++ b/server/web/api/ffprobe.go @@ -4,14 +4,21 @@ import ( "context" "errors" "fmt" - "github.com/gin-gonic/gin" - "gopkg.in/vansante/go-ffprobe.v2" "net/http" "os" + "os/exec" "path/filepath" "server/utils" + + "github.com/gin-gonic/gin" + "gopkg.in/vansante/go-ffprobe.v2" ) +func commandExists(cmd string) bool { + _, err := exec.LookPath(cmd) + return err == nil +} + func ffp(c *gin.Context) { hash := c.Param("hash") indexStr := c.Param("id") @@ -22,13 +29,22 @@ func ffp(c *gin.Context) { } host := utils.GetScheme(c) + "://" + c.Request.Host + "/stream?link=" + hash + "&index=" + indexStr + "&play" - fmt.Println(host) + // log.Println("ffprobe", host) ctx, cancelFn := context.WithCancel(context.Background()) defer cancelFn() - if _, err := os.Stat("ffprobe"); os.IsNotExist(err) { - ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe") + // path lookup + path, err := exec.LookPath("ffprobe") + if err == nil { + // log.Println("ffprobe found in", path) + ffprobe.SetFFProbeBinPath(path) + } else { + // log.Println("ffprobe not found in $PATH") + // working dir + if _, err := os.Stat("ffprobe"); os.IsNotExist(err) { + ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe") + } } data, err := ffprobe.ProbeURL(ctx, host)