mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
Merge branch 'master' of https://github.com/damiva/TorrServer
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,68 +1,97 @@
|
||||
package msx
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
"server/version"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed assets/tvx.js.gz
|
||||
tvx []byte
|
||||
//go:embed assets/tizen.js.gz
|
||||
tzn []byte
|
||||
//go:embed assets/torrents.js.gz
|
||||
trs []byte
|
||||
//go:embed assets/torrent.js.gz
|
||||
trn []byte
|
||||
//go:embed assets/html5x.html.gz
|
||||
h5x []byte
|
||||
//go:embed assets/russian.json.gz
|
||||
//go:embed russian.min.gz
|
||||
rus []byte
|
||||
//go:embed torrents.min.gz
|
||||
trs []byte
|
||||
//go:embed torrent.min.gz
|
||||
trn []byte
|
||||
//go:embed ts.min.gz
|
||||
its []byte
|
||||
|
||||
idb = new(sync.Mutex)
|
||||
ids = make(map[string]string)
|
||||
)
|
||||
|
||||
func ass(c *gin.Context, b []byte, t string) {
|
||||
func asset(c *gin.Context, t string, d []byte) {
|
||||
c.Header("Content-Encoding", "gzip")
|
||||
c.Data(200, t+"; charset=UTF-8", b)
|
||||
c.Data(200, t+"; charset=UTF-8", d)
|
||||
}
|
||||
|
||||
func SetupRoute(r *gin.RouterGroup) {
|
||||
r.GET("/msx/:pth", func(c *gin.Context) {
|
||||
s := []string{"tvx", "tizen"}
|
||||
js := []string{"http://msx.benzac.de/js/tvx-plugin.min.js"}
|
||||
switch p := c.Param("pth"); p {
|
||||
case "start.json":
|
||||
c.JSON(200, gin.H{
|
||||
c.JSON(200, map[string]string{
|
||||
"name": "TorrServer",
|
||||
"version": version.Version,
|
||||
"parameter": "content:request:interaction:init@{PREFIX}{SERVER}/msx/torrents",
|
||||
"parameter": "menu:request:interaction:init@{PREFIX}{SERVER}/msx/ts",
|
||||
})
|
||||
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")
|
||||
asset(c, "application/json", rus)
|
||||
case "torrents.js":
|
||||
ass(c, trs, "text/javascript")
|
||||
asset(c, "text/javascript", trs)
|
||||
case "torrent.js":
|
||||
ass(c, trn, "text/javascript")
|
||||
asset(c, "text/javascript", trn)
|
||||
case "ts.js":
|
||||
asset(c, "text/javascript", its)
|
||||
case "torrents":
|
||||
s = append(s, p)
|
||||
js = append(js, p+".js")
|
||||
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"...)
|
||||
if c.Query("platform") == "tizen" {
|
||||
js = append(js, "http://msx.benzac.de/interaction/js/tizen-player.js")
|
||||
}
|
||||
c.Data(200, "text/html", append(b, "</head>\n<body></body>\n</html>"...))
|
||||
fallthrough
|
||||
case "ts":
|
||||
b := []byte("<!DOCTYPE html>\n<html>\n<head>\n<title>TorrServer Plugin</title>\n<meta charset='UTF-8'>\n")
|
||||
for _, j := range append(js, p+".js") {
|
||||
b = append(b, "<script type='text/javascript' src='"+j+"'></script>\n"...)
|
||||
}
|
||||
c.Data(200, "text/html; charset=UTF-8", append(b, "</head>\n<body></body>\n</html>"...))
|
||||
default:
|
||||
c.AbortWithStatus(404)
|
||||
c.AbortWithStatus(400)
|
||||
}
|
||||
})
|
||||
r.GET("/msx/imdb", func(c *gin.Context) {
|
||||
idb.Lock()
|
||||
defer idb.Unlock()
|
||||
l := len(ids)
|
||||
ids = make(map[string]string)
|
||||
c.JSON(200, l)
|
||||
})
|
||||
r.GET("/msx/imdb/:id", func(c *gin.Context) {
|
||||
idb.Lock()
|
||||
defer idb.Unlock()
|
||||
p := c.Param("id")
|
||||
i, o := ids[p]
|
||||
if !o {
|
||||
if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + p + ".json"); e == nil {
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode == 200 {
|
||||
var j struct {
|
||||
D []struct{ I struct{ ImageUrl string } }
|
||||
}
|
||||
if e = json.NewDecoder(r.Body).Decode(&j); e == nil && len(j.D) > 0 {
|
||||
i = j.D[0].I.ImageUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
ids[p] = i
|
||||
}
|
||||
c.JSON(200, i)
|
||||
})
|
||||
}
|
||||
|
||||
BIN
server/web/msx/russian.min.gz
Normal file
BIN
server/web/msx/russian.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/torrent.min.gz
Normal file
BIN
server/web/msx/torrent.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/torrents.min.gz
Normal file
BIN
server/web/msx/torrents.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/ts.min.gz
Normal file
BIN
server/web/msx/ts.min.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user