Merge branch 'master' into old-engine

This commit is contained in:
nikk gitanes
2023-03-02 05:02:55 +03:00
93 changed files with 170 additions and 119 deletions

View File

@@ -1,25 +1,15 @@
package api
import (
"context"
"errors"
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"server/utils"
"server/ffprobe"
settings2 "server/settings"
"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")
@@ -29,26 +19,9 @@ func ffp(c *gin.Context) {
return
}
host := utils.GetScheme(c) + "://" + c.Request.Host + "/stream?link=" + hash + "&index=" + indexStr + "&play"
// log.Println("ffprobe", host)
host := "http://127.0.0.1:" + settings2.Port + "/stream?link=" + hash + "&index=" + indexStr + "&play"
ctx, cancelFn := context.WithCancel(context.Background())
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) {
ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe")
}
}
data, err := ffprobe.ProbeURL(ctx, host)
data, err := ffprobe.ProbeUrl(host)
if err != nil {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("error getting data: %v", err))
return