This commit is contained in:
YouROK
2020-11-30 23:04:49 +03:00
parent f1aa7858f2
commit 0569ade7b8
7 changed files with 35 additions and 30 deletions

View File

@@ -24,7 +24,6 @@ type BTSets struct {
DisableUPNP bool
DisableDHT bool
DisableUpload bool
Encryption int // ???? 0 - Enable, 1 - disable, 2 - force
DownloadRateLimit int // in kb, 0 - inf
UploadRateLimit int // in kb, 0 - inf
ConnectionsLimit int
@@ -66,7 +65,7 @@ func loadBTSets() {
sets := new(BTSets)
sets.EnableDebug = false
sets.DisableUTP = true
sets.CacheSize = 200 * 1024 * 1024 // 200mb
sets.PreloadBufferSize = 20 * 1024 * 1024
sets.ConnectionsLimit = 20

View File

@@ -3,6 +3,7 @@ package torr
import (
"os"
"sort"
"time"
"server/log"
sets "server/settings"
@@ -57,6 +58,7 @@ func GetTorrent(hashHex string) *Torrent {
hash := metainfo.NewHashFromHex(hashHex)
tor := bts.GetTorrent(hash)
if tor != nil {
tor.expiredTime = time.Now().Add(time.Minute)
return tor
}

View File

@@ -100,6 +100,8 @@ func (bt *BTServer) configure() {
bt.config.ListenPort = settings.BTsets.PeersListenPort
}
bt.config.DefaultRequestStrategy = torrent.RequestStrategyFuzzing()
log.Println("Configure client:", settings.BTsets)
}

View File

@@ -15,6 +15,7 @@ func AddTorrentDB(torr *Torrent) {
t.Name = torr.Name()
t.Title = torr.Title
t.Poster = torr.Poster
t.Size = torr.Size
t.Timestamp = time.Now().Unix()
settings.AddTorrent(t)
}

View File

@@ -1,4 +1,4 @@
package version
const Version = "1.2.78"
const Version = "1.2.78_"
const VerInt = 78

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"path/filepath"
"sort"
"time"
"github.com/anacrolix/missinggo/httptoo"
@@ -19,14 +20,14 @@ import (
)
func allPlayList(c *gin.Context) {
_, fromlast := c.GetQuery("fromlast")
torrs := torr.ListTorrent()
host := "http://" + c.Request.Host
list := "#EXTM3U\n"
hash := ""
for _, tr := range torrs {
list += getM3uList(tr.Status(), host, fromlast)
list += "#EXTINF:0 type=\"playlist\"," + tr.Title + "\n"
list += host + "/stream/" + url.PathEscape(tr.Title) + ".m3u?link=" + tr.TorrentSpec.InfoHash.HexString() + "&m3u\n"
hash += tr.Hash().HexString()
}
@@ -34,28 +35,23 @@ func allPlayList(c *gin.Context) {
}
func playList(c *gin.Context) {
hash := c.Query("torrhash")
hash, _ := c.GetQuery("hash")
_, fromlast := c.GetQuery("fromlast")
if hash == "" {
c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))
return
}
tors := torr.ListTorrent()
var tor *torr.Torrent
for _, tr := range tors {
if tr.Hash().HexString() == hash {
tor = tr
break
}
}
tor := torr.GetTorrent(hash)
if tor == nil {
c.AbortWithStatus(http.StatusNotFound)
return
}
if !tor.WaitInfo() {
c.AbortWithError(http.StatusInternalServerError, errors.New("error get torrent info"))
return
}
// TODO проверить
host := "http://" + c.Request.Host
list := getM3uList(tor.Status(), host, fromlast)
list = "#EXTM3U\n" + list
@@ -94,13 +90,8 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
fn = f.Path
}
m3u += "#EXTINF:0," + fn + "\n"
title := filepath.Base(f.Path)
if tor.Title != "" {
title = tor.Title
} else if tor.Name != "" {
title = tor.Name
}
m3u += host + "/stream/" + url.PathEscape(title) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(f.Id) + "&play\n"
name := filepath.Base(f.Path)
m3u += host + "/stream/" + url.PathEscape(name) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(f.Id) + "&play\n"
}
}
}
@@ -108,15 +99,24 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
}
func searchLastPlayed(tor *state.TorrentStatus) int {
//TODO проверить
viewed := sets.ListViewed(tor.Hash)
for i := len(tor.FileStats); i > 0; i-- {
stat := tor.FileStats[i]
for _, v := range viewed {
if stat.Id == v.FileIndex {
return v.FileIndex
}
if len(viewed) == 0 {
return -1
}
sort.Slice(viewed, func(i, j int) bool {
return viewed[i].FileIndex > viewed[j].FileIndex
})
lastViewedIndex := viewed[0].FileIndex
for i, stat := range tor.FileStats {
if stat.Id == lastViewedIndex {
if i+1 >= len(tor.FileStats) {
return -1
}
return i + 1
}
}
return -1
}

View File

@@ -28,8 +28,9 @@ func SetupRoute(route *gin.Engine) {
route.POST("/viewed", viewed)
route.GET("/playlist/all.m3u", allPlayList)
route.GET("/playlistall/all.m3u", allPlayList)
route.GET("/playlist", playList)
route.GET("/playlist/*fname", playList)
}
func echo(c *gin.Context) {