forked from porjo/youtubeuploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.go
35 lines (33 loc) · 869 Bytes
/
progress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"strings"
"time"
)
// Progress tracks upload progress
func Progress(quitChan chanChan, transport *limitTransport, filesize int64) {
ticker := time.Tick(time.Second)
var erase int
for {
select {
case <-ticker:
if transport.reader != nil {
s := transport.reader.Monitor.Status()
curRate := float32(s.CurRate)
var status string
if curRate >= 125000 {
status = fmt.Sprintf("Progress: %8.2f Mbps, %d / %d (%s) ETA %8s", curRate/125000, s.Bytes, filesize, s.Progress, s.TimeRem)
} else {
status = fmt.Sprintf("Progress: %8.2f kbps, %d / %d (%s) ETA %8s", curRate/125, s.Bytes, filesize, s.Progress, s.TimeRem)
}
fmt.Printf("\r%s\r%s", strings.Repeat(" ", erase), status)
erase = len(status)
}
case ch := <-quitChan:
// final newline
fmt.Println()
close(ch)
return
}
}
}