mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
Merge branch 'master' into old-engine
This commit is contained in:
@@ -89,14 +89,14 @@ func (bt *BTServer) configure(ctx context.Context) {
|
||||
upnpID := "TorrServer/" + version.Version
|
||||
cliVers := userAgent
|
||||
|
||||
// bt.config.AcceptPeerConnections = false
|
||||
// bt.config.AlwaysWantConns = true
|
||||
bt.config.Debug = settings.BTsets.EnableDebug
|
||||
bt.config.DisableIPv6 = settings.BTsets.EnableIPv6 == false
|
||||
bt.config.DisableIPv6 = !settings.BTsets.EnableIPv6
|
||||
bt.config.DisableTCP = settings.BTsets.DisableTCP
|
||||
bt.config.DisableUTP = settings.BTsets.DisableUTP
|
||||
// https://github.com/anacrolix/torrent/issues/703
|
||||
// bt.config.DisableWebtorrent = true
|
||||
// bt.config.DisableWebtorrent = true // TODO: check memory usage
|
||||
// bt.config.DisableWebseeds = true
|
||||
bt.config.NoDefaultPortForwarding = settings.BTsets.DisableUPNP
|
||||
bt.config.NoDHT = settings.BTsets.DisableDHT
|
||||
bt.config.DisablePEX = settings.BTsets.DisablePEX
|
||||
@@ -207,12 +207,6 @@ func (bt *BTServer) RemoveTorrent(hash torrent.InfoHash) {
|
||||
}
|
||||
|
||||
func isPrivateIP(ip net.IP) bool {
|
||||
// log.Println(ip, "IsLoopback:", ip.IsLoopback())
|
||||
// log.Println(ip, "IsPrivate:", ip.IsPrivate())
|
||||
// log.Println(ip, "IsLinkLocalUnicast:", ip.IsLinkLocalUnicast())
|
||||
// log.Println(ip, "IsLinkLocalMulticast:", ip.IsLinkLocalMulticast())
|
||||
// log.Println(ip, "IsGlobalUnicast:", ip.IsGlobalUnicast())
|
||||
|
||||
if ip.IsLoopback() || ip.IsPrivate() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
defer func() {
|
||||
if t.Stat == state.TorrentPreload {
|
||||
t.Stat = state.TorrentWorking
|
||||
// Очистка по окончании прелоада
|
||||
t.BitRate = ""
|
||||
t.DurationSeconds = 0
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -67,13 +70,18 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
}()
|
||||
|
||||
if ffprobe.Exists() {
|
||||
host := "http://127.0.0.1:" + settings.Port + "/play/" + t.Hash().HexString() + "/" + strconv.Itoa(index) // + "&play"
|
||||
if data, err := ffprobe.ProbeUrl(host); err == nil {
|
||||
link := "http://127.0.0.1:" + settings.Port + "/play/" + t.Hash().HexString() + "/" + strconv.Itoa(index)
|
||||
if data, err := ffprobe.ProbeUrl(link); err == nil {
|
||||
t.BitRate = data.Format.BitRate
|
||||
t.DurationSeconds = data.Format.DurationSeconds
|
||||
}
|
||||
}
|
||||
|
||||
if t.Stat == state.TorrentClosed {
|
||||
log.TLogln("End preload: torrent closed")
|
||||
return
|
||||
}
|
||||
|
||||
// startend -> 8/16 MB
|
||||
startend := t.Info().PieceLength
|
||||
if startend < 8*1024*1024 {
|
||||
@@ -98,19 +106,20 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
readerEndStart := file.Length() - startend
|
||||
readerEndEnd := file.Length()
|
||||
|
||||
var wa sync.WaitGroup
|
||||
var wg sync.WaitGroup
|
||||
go func() {
|
||||
offset := int64(0)
|
||||
if readerEndStart > readerStartEnd {
|
||||
// Если конечный ридер не входит в диапозон начального
|
||||
wa.Add(1)
|
||||
defer wa.Done()
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
if t.Stat == state.TorrentPreload {
|
||||
readerEnd := file.NewReader()
|
||||
readerEnd.SetResponsive()
|
||||
readerEnd.SetReadahead(0)
|
||||
readerEnd.Seek(readerEndStart, io.SeekStart)
|
||||
offset = readerEndStart
|
||||
tmp := make([]byte, 32768, 32768)
|
||||
tmp := make([]byte, 32768)
|
||||
for offset+int64(len(tmp)) < readerEndEnd {
|
||||
n, err := readerEnd.Read(tmp)
|
||||
if err != nil {
|
||||
@@ -120,6 +129,7 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
}
|
||||
readerEnd.Close()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
pieceLength := t.Info().PieceLength
|
||||
@@ -129,7 +139,7 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
}
|
||||
readerStart.SetReadahead(readahead)
|
||||
offset := int64(0)
|
||||
tmp := make([]byte, 32768, 32768)
|
||||
tmp := make([]byte, 32768)
|
||||
for offset+int64(len(tmp)) < readerStartEnd {
|
||||
n, err := readerStart.Read(tmp)
|
||||
if err != nil {
|
||||
@@ -143,7 +153,7 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
}
|
||||
}
|
||||
|
||||
wa.Wait()
|
||||
wg.Wait()
|
||||
}
|
||||
log.TLogln("End preload:", file.Torrent().InfoHash().HexString(), "Peers:[", t.Torrent.Stats().ConnectedSeeders, "]", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers)
|
||||
}
|
||||
|
||||
@@ -104,10 +104,9 @@ func (c *Cache) Close() error {
|
||||
}
|
||||
}
|
||||
|
||||
c.pieces = nil
|
||||
|
||||
c.muReaders.Lock()
|
||||
c.readers = nil
|
||||
c.pieces = nil
|
||||
c.muReaders.Unlock()
|
||||
|
||||
utils.FreeOSMemGC()
|
||||
|
||||
Reference in New Issue
Block a user