mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
Merge branch 'master' into old-engine
This commit is contained in:
@@ -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 + "/play/" + t.Hash().HexString() + "/" + 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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ type Torrent struct {
|
||||
PreloadSize int64
|
||||
PreloadedBytes int64
|
||||
|
||||
DurationSeconds float64
|
||||
BitRate string
|
||||
|
||||
expiredTime time.Time
|
||||
|
||||
closed <-chan struct{}
|
||||
@@ -116,9 +119,15 @@ func (t *Torrent) WaitInfo() bool {
|
||||
}
|
||||
|
||||
func (t *Torrent) GotInfo() bool {
|
||||
// log.TLogln("GotInfo state:", t.Stat)
|
||||
if t.Stat == state.TorrentClosed {
|
||||
return false
|
||||
}
|
||||
// assume we have info in preload state
|
||||
// and dont override with TorrentWorking
|
||||
if t.Stat == state.TorrentPreload {
|
||||
return true
|
||||
}
|
||||
t.Stat = state.TorrentGettingInfo
|
||||
if t.WaitInfo() {
|
||||
t.Stat = state.TorrentWorking
|
||||
@@ -247,11 +256,11 @@ func (t *Torrent) GetCache() *torrstor.Cache {
|
||||
|
||||
func (t *Torrent) drop() {
|
||||
t.muTorrent.Lock()
|
||||
defer t.muTorrent.Unlock()
|
||||
if t.Torrent != nil {
|
||||
t.Torrent.Drop()
|
||||
t.Torrent = nil
|
||||
}
|
||||
t.muTorrent.Unlock()
|
||||
}
|
||||
|
||||
func (t *Torrent) Close() {
|
||||
@@ -277,6 +286,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()
|
||||
|
||||
Reference in New Issue
Block a user