mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
change preload
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package torr
|
package torr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -261,30 +263,32 @@ func (t *Torrent) Preload(index int, size int64) {
|
|||||||
if file == nil {
|
if file == nil {
|
||||||
file = t.Files()[0]
|
file = t.Files()[0]
|
||||||
}
|
}
|
||||||
pieceLength := t.Info().PieceLength
|
|
||||||
startPiece := file.Offset() / pieceLength
|
|
||||||
endPiece := (file.Offset() + size) / pieceLength
|
|
||||||
for i := startPiece; i < endPiece; i++ {
|
|
||||||
t.Torrent.Piece(int(i)).SetPriority(torrent.PiecePriorityNormal)
|
|
||||||
}
|
|
||||||
|
|
||||||
endedPiece := (file.Offset() + file.Length() - 1024) / t.Info().PieceLength
|
// Reader for not pieces break in cache without readers
|
||||||
t.Torrent.Piece(int(endedPiece)).SetPriority(torrent.PiecePriorityNormal)
|
readerStart := t.cache.NewReader(file)
|
||||||
|
readerStart.Read(make([]byte, 1))
|
||||||
|
defer t.cache.CloseReader(readerStart)
|
||||||
|
readerEnd := t.cache.NewReader(file)
|
||||||
|
readerEnd.Seek(-1024, io.SeekEnd)
|
||||||
|
readerEnd.Read(make([]byte, 1))
|
||||||
|
defer t.cache.CloseReader(readerEnd)
|
||||||
|
|
||||||
for t.PreloadedBytes < size-pieceLength {
|
lastStat := ""
|
||||||
|
for t.PreloadedBytes < size {
|
||||||
t.muTorrent.Lock()
|
t.muTorrent.Lock()
|
||||||
if t.Torrent == nil {
|
if t.Torrent == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.PreloadedBytes = t.Torrent.BytesCompleted()
|
t.PreloadedBytes = t.Torrent.BytesCompleted()
|
||||||
t.muTorrent.Unlock()
|
t.muTorrent.Unlock()
|
||||||
log.TLogln("Preload:", file.Torrent().InfoHash().HexString(), utils2.Format(float64(t.PreloadedBytes)), "/", utils2.Format(float64(t.PreloadSize)), "Speed:", utils2.Format(t.DownloadSpeed), "Peers:[", t.Torrent.Stats().ConnectedSeeders, "]", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers)
|
|
||||||
|
stat := fmt.Sprint(file.Torrent().InfoHash().HexString(), utils2.Format(float64(t.PreloadedBytes)), "/", utils2.Format(float64(t.PreloadSize)), "Speed:", utils2.Format(t.DownloadSpeed), "Peers:[", t.Torrent.Stats().ConnectedSeeders, "]", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers)
|
||||||
|
if stat != lastStat {
|
||||||
|
log.TLogln("Preload:", stat)
|
||||||
|
lastStat = stat
|
||||||
|
}
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
}
|
}
|
||||||
for i := startPiece; i < endPiece; i++ {
|
|
||||||
t.Torrent.Piece(int(i)).SetPriority(torrent.PiecePriorityNone)
|
|
||||||
}
|
|
||||||
t.Torrent.Piece(int(endedPiece)).SetPriority(torrent.PiecePriorityNone)
|
|
||||||
log.TLogln("End preload:", file.Torrent().InfoHash().HexString(), "Peers:[", t.Torrent.Stats().ConnectedSeeders, "]", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers)
|
log.TLogln("End preload:", file.Torrent().InfoHash().HexString(), "Peers:[", t.Torrent.Stats().ConnectedSeeders, "]", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user