mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
remove length
This commit is contained in:
@@ -60,10 +60,9 @@ func (c *Cache) Init(info *metainfo.Info, hash metainfo.Hash) {
|
|||||||
|
|
||||||
for i := 0; i < c.pieceCount; i++ {
|
for i := 0; i < c.pieceCount; i++ {
|
||||||
c.pieces[i] = &Piece{
|
c.pieces[i] = &Piece{
|
||||||
Id: i,
|
Id: i,
|
||||||
Length: info.Piece(i).Length(),
|
Hash: info.Piece(i).Hash().HexString(),
|
||||||
Hash: info.Piece(i).Hash().HexString(),
|
cache: c,
|
||||||
cache: c,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,11 +115,11 @@ func (c *Cache) GetState() *state.CacheState {
|
|||||||
var fill int64 = 0
|
var fill int64 = 0
|
||||||
for _, p := range c.pieces {
|
for _, p := range c.pieces {
|
||||||
if p.Size > 0 {
|
if p.Size > 0 {
|
||||||
fill += p.Length
|
fill += p.Size
|
||||||
piecesState[p.Id] = state.ItemState{
|
piecesState[p.Id] = state.ItemState{
|
||||||
Id: p.Id,
|
Id: p.Id,
|
||||||
Size: p.Size,
|
Size: p.Size,
|
||||||
Length: p.Length,
|
Length: c.pieceLength,
|
||||||
Completed: p.complete,
|
Completed: p.complete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,16 +191,14 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
if p.Size > 0 {
|
if p.Size > 0 {
|
||||||
fill += p.Size
|
fill += p.Size
|
||||||
}
|
}
|
||||||
piece := c.torrent.Piece(id)
|
|
||||||
state := c.torrent.PieceState(id)
|
|
||||||
if len(ranges) > 0 {
|
if len(ranges) > 0 {
|
||||||
if !inRanges(ranges, id) {
|
if !inRanges(ranges, id) {
|
||||||
if p.Size > 0 {
|
if p.Size > 0 && !c.isIdInFileBE(ranges, id) {
|
||||||
piecesRemove = append(piecesRemove, p)
|
piecesRemove = append(piecesRemove, p)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if state.Priority == torrent.PiecePriorityNone {
|
if c.torrent.PieceState(id).Priority == torrent.PiecePriorityNone {
|
||||||
piece.SetPriority(torrent.PiecePriorityNormal)
|
c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNormal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,3 +211,18 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
c.filled = fill
|
c.filled = fill
|
||||||
return piecesRemove
|
return piecesRemove
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cache) isIdInFileBE(ranges []Range, id int) bool {
|
||||||
|
for _, rng := range ranges {
|
||||||
|
ss := int(rng.File.Offset() / c.pieceLength)
|
||||||
|
se := int((5*1024*1024 + rng.File.Offset()) / c.pieceLength)
|
||||||
|
|
||||||
|
es := int((rng.File.Offset() + rng.File.Length() - 5*1024*1024) / c.pieceLength)
|
||||||
|
ee := int((rng.File.Offset() + rng.File.Length()) / c.pieceLength)
|
||||||
|
|
||||||
|
if id >= ss && id <= se || id >= es && id <= ee {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ import (
|
|||||||
type Piece struct {
|
type Piece struct {
|
||||||
storage.PieceImpl
|
storage.PieceImpl
|
||||||
|
|
||||||
Id int
|
Id int
|
||||||
Hash string
|
Hash string
|
||||||
Length int64
|
Size int64
|
||||||
Size int64
|
|
||||||
|
|
||||||
complete bool
|
complete bool
|
||||||
readed bool
|
readed bool
|
||||||
|
|||||||
Reference in New Issue
Block a user