This commit is contained in:
YouROK
2020-11-10 22:57:16 +03:00
parent 6a11651cf5
commit 1ce27ef121
12 changed files with 63 additions and 32 deletions

View File

@@ -8,11 +8,12 @@ import (
"path/filepath"
"time"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
sets "server/settings"
"server/torr/state"
"server/utils"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func allPlayList(c *gin.Context) {

View File

@@ -5,18 +5,19 @@ import (
"net/url"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"server/torr"
"server/web/api/utils"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
// http://127.0.0.1:8090/stream/fname?link=...&index=0&stat
// http://127.0.0.1:8090/stream/fname?link=...&index=0&m3u
// http://127.0.0.1:8090/stream/fname?link=...&index=0&play
// http://127.0.0.1:8090/stream/fname?link=...&index=1&stat
// http://127.0.0.1:8090/stream/fname?link=...&index=1&m3u
// http://127.0.0.1:8090/stream/fname?link=...&index=1&play
// http://127.0.0.1:8090/stream/fname?link=...&save&title=...&poster=...
// http://127.0.0.1:8090/stream/fname?link=...&index=0&play&save
// http://127.0.0.1:8090/stream/fname?link=...&index=0&play&save&title=...&poster=...
// http://127.0.0.1:8090/stream/fname?link=...&index=1&play&save
// http://127.0.0.1:8090/stream/fname?link=...&index=1&play&save&title=...&poster=...
func stream(c *gin.Context) {
link := c.Query("link")
@@ -82,7 +83,7 @@ func stream(c *gin.Context) {
c.Status(200)
}
// wait torrent info
if !tor.WaitInfo() {
if !tor.GotInfo() {
c.AbortWithError(http.StatusInternalServerError, errors.New("timeout torrent get info"))
return
}
@@ -90,7 +91,7 @@ func stream(c *gin.Context) {
// find file
index := -1
if len(tor.Files()) == 1 {
index = 0
index = 1
} else {
ind, err := strconv.Atoi(indexStr)
if err == nil {

View File

@@ -3,13 +3,14 @@ package api
import (
"net/http"
"github.com/anacrolix/torrent/metainfo"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"server/log"
"server/torr"
"server/torr/state"
"server/web/api/utils"
"github.com/anacrolix/torrent/metainfo"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
//Action: add, get, rem, list, drop
@@ -70,7 +71,7 @@ func addTorrent(req torrReqJS, c *gin.Context) {
return
}
if !torr.WaitInfo() {
if !torr.GotInfo() {
log.TLogln("error add torrent:", "timeout connection torrent")
c.AbortWithError(http.StatusNotFound, errors.New("timeout connection torrent"))
return

View File

@@ -3,9 +3,11 @@ package utils
import (
"time"
"github.com/anacrolix/torrent/metainfo"
"server/settings"
"server/torr"
"server/torr/state"
"github.com/anacrolix/torrent/metainfo"
)
func AddTorrent(torr *torr.Torrent) {
@@ -26,6 +28,7 @@ func GetTorrent(hash metainfo.Hash) *torr.Torrent {
torr.TorrentSpec = db.TorrentSpec
torr.Title = db.Title
torr.Poster = db.Poster
torr.Status = state.TorrentInDB
return torr
}
}
@@ -44,6 +47,7 @@ func ListTorrents() []*torr.Torrent {
torr.TorrentSpec = db.TorrentSpec
torr.Title = db.Title
torr.Poster = db.Poster
torr.Status = state.TorrentInDB
ret = append(ret, torr)
}
return ret

View File

@@ -35,7 +35,7 @@ func ParseLink(link string) (*torrent.TorrentSpec, error) {
}
func fromMagnet(link string) (*torrent.TorrentSpec, error) {
mag, err := metainfo.ParseMagnetURI(link)
mag, err := metainfo.ParseMagnetUri(link)
if err != nil {
return nil, err
}