From f409959b3d0520f392bd5ca229edeb2d27309915 Mon Sep 17 00:00:00 2001 From: YouROK <8YouROK8@mail.ru> Date: Mon, 27 Feb 2023 23:20:46 +0300 Subject: [PATCH] add bitrate to torr status --- server/torr/preload.go | 12 +++++++++++- server/torr/state/state.go | 2 ++ server/torr/torrent.go | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/server/torr/preload.go b/server/torr/preload.go index 6e9a2be..df1efa6 100644 --- a/server/torr/preload.go +++ b/server/torr/preload.go @@ -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 } diff --git a/server/torr/state/state.go b/server/torr/state/state.go index 7e79ccf..39a96e2 100644 --- a/server/torr/state/state.go +++ b/server/torr/state/state.go @@ -61,6 +61,8 @@ type TorrentStatus struct { ChunksReadWasted int64 `json:"chunks_read_wasted,omitempty"` PiecesDirtiedGood int64 `json:"pieces_dirtied_good,omitempty"` PiecesDirtiedBad int64 `json:"pieces_dirtied_bad,omitempty"` + DurationSeconds float64 `json:"duration_seconds,omitempty"` + BitRate string `json:"bit_rate,omitempty"` FileStats []*TorrentFileStat `json:"file_stats,omitempty"` } diff --git a/server/torr/torrent.go b/server/torr/torrent.go index 7be01c4..689ba67 100644 --- a/server/torr/torrent.go +++ b/server/torr/torrent.go @@ -42,6 +42,9 @@ type Torrent struct { PreloadSize int64 PreloadedBytes int64 + DurationSeconds float64 + BitRate string + expiredTime time.Time closed <-chan struct{} @@ -277,6 +280,8 @@ func (t *Torrent) Status() *state.TorrentStatus { st.Data = t.Data st.Timestamp = t.Timestamp st.TorrentSize = t.Size + st.BitRate = t.BitRate + st.DurationSeconds = t.DurationSeconds if t.TorrentSpec != nil { st.Hash = t.TorrentSpec.InfoHash.HexString()