add ffprobe path lookup

This commit is contained in:
nikk gitanes
2023-02-17 02:50:18 +03:00
parent 6b7ab254db
commit 06427b39de

View File

@@ -4,14 +4,21 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/gin-gonic/gin"
"gopkg.in/vansante/go-ffprobe.v2"
"net/http" "net/http"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"server/utils" "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) { func ffp(c *gin.Context) {
hash := c.Param("hash") hash := c.Param("hash")
indexStr := c.Param("id") indexStr := c.Param("id")
@@ -22,14 +29,23 @@ func ffp(c *gin.Context) {
} }
host := utils.GetScheme(c) + "://" + c.Request.Host + "/stream?link=" + hash + "&index=" + indexStr + "&play" 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()) ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn() defer cancelFn()
// 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) { if _, err := os.Stat("ffprobe"); os.IsNotExist(err) {
ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe") ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe")
} }
}
data, err := ffprobe.ProbeURL(ctx, host) data, err := ffprobe.ProbeURL(ctx, host)
if err != nil { if err != nil {