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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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