mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
fix samsung tv divx
This commit is contained in:
@@ -3,7 +3,6 @@ package torrstor
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -15,11 +14,9 @@ type Piece struct {
|
|||||||
storage.PieceImpl
|
storage.PieceImpl
|
||||||
|
|
||||||
Id int
|
Id int
|
||||||
Hash string
|
|
||||||
Size int64
|
Size int64
|
||||||
|
|
||||||
complete bool
|
complete bool
|
||||||
readed bool
|
|
||||||
accessed int64
|
accessed int64
|
||||||
buffer []byte
|
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)
|
p.buffer = make([]byte, p.cache.pieceLength, p.cache.pieceLength)
|
||||||
}
|
}
|
||||||
n = copy(p.buffer[off:], b[:])
|
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.Size += int64(n)
|
||||||
p.accessed = time.Now().Unix()
|
p.accessed = time.Now().Unix()
|
||||||
return
|
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][:])
|
n = copy(b, p.buffer[int(off) : int(off)+size][:])
|
||||||
p.accessed = time.Now().Unix()
|
p.accessed = time.Now().Unix()
|
||||||
if int(off)+size >= len(p.buffer) {
|
|
||||||
p.readed = true
|
|
||||||
}
|
|
||||||
if int64(len(b))+off >= p.Size {
|
if int64(len(b))+off >= p.Size {
|
||||||
go p.cache.cleanPieces()
|
go p.cache.cleanPieces()
|
||||||
}
|
}
|
||||||
if n == 0 && err == nil {
|
if n == 0 {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package torrstor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"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 {
|
if r.file.Torrent() != nil && r.file.Torrent().Info() != nil {
|
||||||
n, err = r.Reader.Read(p)
|
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)
|
r.offset += int64(n)
|
||||||
} else {
|
} else {
|
||||||
log.TLogln("Torrent closed and readed")
|
log.TLogln("Torrent closed and readed")
|
||||||
|
|||||||
Reference in New Issue
Block a user