mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add ffprobe
This commit is contained in:
41
server/web/api/ffprobe.go
Normal file
41
server/web/api/ffprobe.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gopkg.in/vansante/go-ffprobe.v2"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"server/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ffp(c *gin.Context) {
|
||||||
|
hash := c.Param("hash")
|
||||||
|
indexStr := c.Param("id")
|
||||||
|
|
||||||
|
if hash == "" || indexStr == "" {
|
||||||
|
c.AbortWithError(http.StatusNotFound, errors.New("link should not be empty"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
host := utils.GetScheme(c) + "://" + c.Request.Host + "/stream?link=" + hash + "&index=" + indexStr + "&play"
|
||||||
|
fmt.Println(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")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := ffprobe.ProbeURL(ctx, host)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("error getting data: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, data)
|
||||||
|
}
|
||||||
@@ -39,7 +39,10 @@ func SetupRoute(route *gin.RouterGroup) {
|
|||||||
route.GET("/playlist/*fname", playList)
|
route.GET("/playlist/*fname", playList)
|
||||||
|
|
||||||
route.GET("/download/:size", download)
|
route.GET("/download/:size", download)
|
||||||
|
|
||||||
route.GET("/search/*query", rutorSearch)
|
route.GET("/search/*query", rutorSearch)
|
||||||
|
|
||||||
|
route.GET("/ffp/:hash/:id", ffp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shutdown(c *gin.Context) {
|
func shutdown(c *gin.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user