add bitrate to torr status

This commit is contained in:
YouROK
2023-02-27 23:20:46 +03:00
parent dd9e72ef80
commit f409959b3d
3 changed files with 18 additions and 1 deletions

View File

@@ -3,6 +3,8 @@ package torr
import (
"fmt"
"io"
"server/ffprobe"
"strconv"
"sync"
"time"
@@ -63,8 +65,16 @@ func (t *Torrent) Preload(index int, size int64) {
}
}()
if ffprobe.Exists() {
host := "http://127.0.0.1:" + settings.Port + "/stream?link=" + t.Hash().HexString() + "&index=" + strconv.Itoa(index) + "&play"
if data, err := ffprobe.ProbeUrl(host); err == nil {
t.BitRate = data.Format.BitRate
t.DurationSeconds = data.Format.DurationSeconds
}
}
// startend -> 8/16 MB
startend := int64(t.Info().PieceLength)
startend := t.Info().PieceLength
if startend < 8*1024*1024 {
startend = 8 * 1024 * 1024
}