fix samsung tv divx

This commit is contained in:
YouROK
2021-03-16 14:47:02 +03:00
parent 4b270d47aa
commit d92e8146ff
2 changed files with 21 additions and 26 deletions

View File

@@ -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

View File

@@ -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")