cmd/torrent: Track download rate
This commit is contained in:
parent
a44f9921aa
commit
b9c36ebef3
|
@ -40,6 +40,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
|
||||||
fmt.Printf("%v: getting torrent info for %q\n", time.Since(start), t.Name())
|
fmt.Printf("%v: getting torrent info for %q\n", time.Since(start), t.Name())
|
||||||
<-t.GotInfo()
|
<-t.GotInfo()
|
||||||
}
|
}
|
||||||
|
lastStats := t.Stats()
|
||||||
var lastLine string
|
var lastLine string
|
||||||
for range time.Tick(time.Second) {
|
for range time.Tick(time.Second) {
|
||||||
var completedPieces, partialPieces int
|
var completedPieces, partialPieces int
|
||||||
|
@ -52,8 +53,9 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
|
||||||
partialPieces += r.Length
|
partialPieces += r.Length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stats := t.Stats()
|
||||||
line := fmt.Sprintf(
|
line := fmt.Sprintf(
|
||||||
"%v: downloading %q: %s/%s, %d/%d pieces completed (%d partial)\n",
|
"%v: downloading %q: %s/%s, %d/%d pieces completed (%d partial): %v/s\n",
|
||||||
time.Since(start),
|
time.Since(start),
|
||||||
t.Name(),
|
t.Name(),
|
||||||
humanize.Bytes(uint64(t.BytesCompleted())),
|
humanize.Bytes(uint64(t.BytesCompleted())),
|
||||||
|
@ -61,6 +63,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
|
||||||
completedPieces,
|
completedPieces,
|
||||||
t.NumPieces(),
|
t.NumPieces(),
|
||||||
partialPieces,
|
partialPieces,
|
||||||
|
humanize.Bytes(uint64(stats.BytesReadUsefulData.Int64()-lastStats.BytesReadUsefulData.Int64())),
|
||||||
)
|
)
|
||||||
if line != lastLine {
|
if line != lastLine {
|
||||||
lastLine = line
|
lastLine = line
|
||||||
|
@ -69,6 +72,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
|
||||||
if pieceStates {
|
if pieceStates {
|
||||||
fmt.Println(psrs)
|
fmt.Println(psrs)
|
||||||
}
|
}
|
||||||
|
lastStats = stats
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -155,7 +159,6 @@ func addTorrents(client *torrent.Client) error {
|
||||||
|
|
||||||
var flags struct {
|
var flags struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
Stats *bool
|
|
||||||
|
|
||||||
*DownloadCmd `arg:"subcommand:download"`
|
*DownloadCmd `arg:"subcommand:download"`
|
||||||
*ListFilesCmd `arg:"subcommand:list-files"`
|
*ListFilesCmd `arg:"subcommand:list-files"`
|
||||||
|
@ -176,8 +179,9 @@ type DownloadCmd struct {
|
||||||
PublicIP net.IP
|
PublicIP net.IP
|
||||||
Progress bool `default:"true"`
|
Progress bool `default:"true"`
|
||||||
PieceStates bool
|
PieceStates bool
|
||||||
Quiet bool `help:"discard client logging"`
|
Quiet bool `help:"discard client logging"`
|
||||||
Dht bool `default:"true"`
|
Stats *bool `help:"print stats at termination"`
|
||||||
|
Dht bool `default:"true"`
|
||||||
|
|
||||||
TcpPeers bool `default:"true"`
|
TcpPeers bool `default:"true"`
|
||||||
UtpPeers bool `default:"true"`
|
UtpPeers bool `default:"true"`
|
||||||
|
|
Loading…
Reference in New Issue