mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-20 05:56:10 +05:00
Merge branch 'master' into old-engine
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//Action: get
|
||||
// Action: get
|
||||
type cacheReqJS struct {
|
||||
requestI
|
||||
Hash string `json:"hash,omitempty"`
|
||||
|
||||
@@ -4,14 +4,22 @@ 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 +30,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)
|
||||
|
||||
@@ -100,10 +100,10 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
|
||||
fn = f.Path
|
||||
}
|
||||
m3u += "#EXTINF:0," + fn + "\n"
|
||||
fileNamesakes := findFileNamesakes(tor.FileStats, f) //find external media with same name (audio/subtiles tracks)
|
||||
fileNamesakes := findFileNamesakes(tor.FileStats, f) // find external media with same name (audio/subtiles tracks)
|
||||
if fileNamesakes != nil {
|
||||
m3u += "#EXTVLCOPT:input-slave=" //include VLC option for external media
|
||||
for _, namesake := range fileNamesakes { //include play-links to external media, with # splitter
|
||||
m3u += "#EXTVLCOPT:input-slave=" // include VLC option for external media
|
||||
for _, namesake := range fileNamesakes { // include play-links to external media, with # splitter
|
||||
sname := filepath.Base(namesake.Path)
|
||||
m3u += host + "/stream/" + url.PathEscape(sname) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(namesake.Id) + "&play#"
|
||||
}
|
||||
@@ -118,12 +118,12 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
|
||||
}
|
||||
|
||||
func findFileNamesakes(files []*state.TorrentFileStat, file *state.TorrentFileStat) []*state.TorrentFileStat {
|
||||
//find files with the same name in torrent
|
||||
// find files with the same name in torrent
|
||||
name := filepath.Base(strings.TrimSuffix(file.Path, filepath.Ext(file.Path)))
|
||||
var namesakes []*state.TorrentFileStat
|
||||
for _, f := range files {
|
||||
if strings.Contains(f.Path, name) { //external tracks always include name of videofile
|
||||
if f != file { //exclude itself
|
||||
if strings.Contains(f.Path, name) { // external tracks always include name of videofile
|
||||
if f != file { // exclude itself
|
||||
namesakes = append(namesakes, f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"server/rutor"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -211,5 +211,4 @@ func streamNoAuth(c *gin.Context) {
|
||||
}
|
||||
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//Action: add, get, set, rem, list, drop
|
||||
// Action: add, get, set, rem, list, drop
|
||||
type torrReqJS struct {
|
||||
requestI
|
||||
Link string `json:"link,omitempty"`
|
||||
|
||||
@@ -68,7 +68,7 @@ func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
|
||||
// Return the range the given IP is in. Returns nil if no range is found.
|
||||
func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
|
||||
var rng Range
|
||||
var ok = false
|
||||
ok := false
|
||||
for _, r := range ipl.ranges {
|
||||
ok = bytes.Compare(r.First, ip) <= 0 && bytes.Compare(ip, r.Last) <= 0
|
||||
if ok {
|
||||
|
||||
Binary file not shown.
BIN
server/web/msx/assets/tizen.js.gz
Normal file
BIN
server/web/msx/assets/tizen.js.gz
Normal file
Binary file not shown.
BIN
server/web/msx/assets/torrent.js.gz
Normal file
BIN
server/web/msx/assets/torrent.js.gz
Normal file
Binary file not shown.
BIN
server/web/msx/assets/torrents.js.gz
Normal file
BIN
server/web/msx/assets/torrents.js.gz
Normal file
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@ package msx
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
|
||||
"server/version"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,9 +11,11 @@ import (
|
||||
var (
|
||||
//go:embed assets/tvx.js.gz
|
||||
tvx []byte
|
||||
//go:embed assets/tizen.html.gz
|
||||
//go:embed assets/tizen.js.gz
|
||||
tzn []byte
|
||||
//go:embed assets/torrents.min.html.gz
|
||||
//go:embed assets/torrents.js.gz
|
||||
trs []byte
|
||||
//go:embed assets/torrent.js.gz
|
||||
trn []byte
|
||||
//go:embed assets/html5x.html.gz
|
||||
h5x []byte
|
||||
@@ -21,24 +23,46 @@ var (
|
||||
rus []byte
|
||||
)
|
||||
|
||||
func ass(b []byte, t string) func(*gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
c.Header("Content-Encoding", "gzip")
|
||||
c.Data(200, t+"; charset=UTF-8", b)
|
||||
}
|
||||
func ass(c *gin.Context, b []byte, t string) {
|
||||
c.Header("Content-Encoding", "gzip")
|
||||
c.Data(200, t+"; charset=UTF-8", b)
|
||||
}
|
||||
|
||||
func SetupRoute(r *gin.RouterGroup) {
|
||||
r.GET("/msx/start.json", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"name": "TorrServer",
|
||||
"version": version.Version,
|
||||
"parameter": "content:request:interaction:init@{PREFIX}{SERVER}/msx/torrents",
|
||||
})
|
||||
r.GET("/msx/:pth", func(c *gin.Context) {
|
||||
s := []string{"tvx", "tizen"}
|
||||
switch p := c.Param("pth"); p {
|
||||
case "start.json":
|
||||
c.JSON(200, gin.H{
|
||||
"name": "TorrServer",
|
||||
"version": version.Version,
|
||||
"parameter": "content:request:interaction:init@{PREFIX}{SERVER}/msx/torrents",
|
||||
})
|
||||
case "russian.json":
|
||||
ass(c, rus, "application.json")
|
||||
case "html5x":
|
||||
ass(c, h5x, "text/html")
|
||||
case "tvx.js":
|
||||
ass(c, tvx, "text/javascript")
|
||||
case "tizen.js":
|
||||
ass(c, tzn, "text/javascript")
|
||||
case "torrents.js":
|
||||
ass(c, trs, "text/javascript")
|
||||
case "torrent.js":
|
||||
ass(c, trn, "text/javascript")
|
||||
case "torrents":
|
||||
s = append(s, p)
|
||||
p = "torrent"
|
||||
fallthrough
|
||||
case "torrent":
|
||||
s = append(s, p)
|
||||
b := []byte("<!DOCTYPE html>\n<html>\n<head>\n<title>TorrServer Interaction Plugin</title>\n<meta charset='UTF-8' />\n")
|
||||
for _, j := range s {
|
||||
b = append(b, "<script type='text/javascript' src='"+j+".js'></script>\n"...)
|
||||
}
|
||||
c.Data(200, "text/html", append(b, "</head>\n<body></body>\n</html>"...))
|
||||
default:
|
||||
c.AbortWithStatus(404)
|
||||
}
|
||||
})
|
||||
r.GET("/msx/russian.json", ass(rus, "application/json"))
|
||||
r.GET("/msx/tvx.js", ass(tvx, "text/javascript"))
|
||||
r.GET("/msx/torrents", ass(trn, "text/html"))
|
||||
r.GET("/msx/tizen", ass(tzn, "text/html"))
|
||||
r.GET("/msx/html5x", ass(h5x, "text/html"))
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package web
|
||||
|
||||
import (
|
||||
"net"
|
||||
"server/rutor"
|
||||
"sort"
|
||||
|
||||
"server/rutor"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/location"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -42,11 +43,11 @@ func Start(port string) {
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
//corsCfg := cors.DefaultConfig()
|
||||
//corsCfg.AllowAllOrigins = true
|
||||
//corsCfg.AllowHeaders = []string{"*"}
|
||||
//corsCfg.AllowMethods = []string{"*"}
|
||||
//corsCfg.AllowPrivateNetwork = true
|
||||
// corsCfg := cors.DefaultConfig()
|
||||
// corsCfg.AllowAllOrigins = true
|
||||
// corsCfg.AllowHeaders = []string{"*"}
|
||||
// corsCfg.AllowMethods = []string{"*"}
|
||||
// corsCfg.AllowPrivateNetwork = true
|
||||
corsCfg := cors.DefaultConfig()
|
||||
corsCfg.AllowAllOrigins = true
|
||||
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
|
||||
|
||||
Reference in New Issue
Block a user