diff --git a/server/torr/storage/torrstor/piece.go b/server/torr/storage/torrstor/piece.go index a92daa6..f5ce3d7 100644 --- a/server/torr/storage/torrstor/piece.go +++ b/server/torr/storage/torrstor/piece.go @@ -3,7 +3,6 @@ package torrstor import ( "errors" "io" - "strings" "sync" "time" @@ -15,11 +14,9 @@ type Piece struct { storage.PieceImpl Id int - Hash string Size int64 complete bool - readed bool accessed int64 buffer []byte @@ -36,25 +33,6 @@ func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) { p.buffer = make([]byte, p.cache.pieceLength, p.cache.pieceLength) } n = copy(p.buffer[off:], b[:]) - //samsung tv fix xvid/divx - if p.Id == 0 && off < 192 { - str := strings.ToLower(string(p.buffer[112:116])) - if str == "xvid" || str == "divx" { - p.buffer[112] = 0x4D //M - p.buffer[113] = 0x50 //P - p.buffer[114] = 0x34 //4 - p.buffer[115] = 0x56 //V - } - str = strings.ToLower(string(p.buffer[188:192])) - if str == "xvid" || str == "divx" { - p.buffer[188] = 0x4D //M - p.buffer[189] = 0x50 //P - p.buffer[190] = 0x34 //4 - p.buffer[191] = 0x56 //V - } - - println(string(p.buffer[110:192])) - } p.Size += int64(n) p.accessed = time.Now().Unix() return @@ -76,13 +54,10 @@ func (p *Piece) ReadAt(b []byte, off int64) (n int, err error) { } n = copy(b, p.buffer[int(off) : int(off)+size][:]) p.accessed = time.Now().Unix() - if int(off)+size >= len(p.buffer) { - p.readed = true - } if int64(len(b))+off >= p.Size { go p.cache.cleanPieces() } - if n == 0 && err == nil { + if n == 0 { return 0, io.EOF } return n, nil diff --git a/server/torr/storage/torrstor/reader.go b/server/torr/storage/torrstor/reader.go index b49a969..28be26f 100644 --- a/server/torr/storage/torrstor/reader.go +++ b/server/torr/storage/torrstor/reader.go @@ -2,6 +2,7 @@ package torrstor import ( "io" + "strings" "sync" "github.com/anacrolix/torrent" @@ -62,6 +63,25 @@ func (r *Reader) Read(p []byte) (n int, err error) { } if r.file.Torrent() != nil && r.file.Torrent().Info() != nil { n, err = r.Reader.Read(p) + + //samsung tv fix xvid/divx + if r.offset == 0 && len(p) >= 192 { + str := strings.ToLower(string(p[112:116])) + if str == "xvid" || str == "divx" { + p[112] = 0x4D //M + p[113] = 0x50 //P + p[114] = 0x34 //4 + p[115] = 0x56 //V + } + str = strings.ToLower(string(p[188:192])) + if str == "xvid" || str == "divx" { + p[188] = 0x4D //M + p[189] = 0x50 //P + p[190] = 0x34 //4 + p[191] = 0x56 //V + } + } + r.offset += int64(n) } else { log.TLogln("Torrent closed and readed")