diff options
author | Keuin <[email protected]> | 2023-07-30 19:04:12 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-30 19:04:12 +0800 |
commit | 3fad4189646cca5d6db99ccfe79be695ef765d03 (patch) | |
tree | 6ab1c57a7a954dfd08afba9d2c4ab582382e0eb0 /bilibili | |
parent | d60bdefcabbc7fc0e0bbb690045222896f688f3f (diff) |
Refactor: extract pretty duration to a function. Create `pretty` package for creating human friendly stringsv0.5.1
Diffstat (limited to 'bilibili')
-rw-r--r-- | bilibili/streaming.go | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/bilibili/streaming.go b/bilibili/streaming.go index a275ea2..c1228ef 100644 --- a/bilibili/streaming.go +++ b/bilibili/streaming.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" errs "github.com/keuin/slbr/bilibili/errors" - "github.com/keuin/slbr/common/files" + "github.com/keuin/slbr/common/pretty" "github.com/keuin/slbr/types" "io" "net/http" @@ -96,12 +96,8 @@ func (b *Bilibili) CopyLiveStream( for { select { case <-printTicker.C: - d := int64(time.Now().Sub(startTime).Seconds()) - h := d / 3600 - m := (d % 3600) / 60 - s := d % 60 - b.logger.Info("Downloaded: %v, duration: %02d:%02d:%02d", - files.PrettyBytes(uint64(n.Load())), h, m, s) + b.logger.Info("Downloaded: %v, duration: %v", + pretty.Bytes(uint64(n.Load())), pretty.Duration(time.Now().Sub(startTime))) case <-stopPrintLoop: return } @@ -133,6 +129,6 @@ copyLoop: b.logger.Error("Stream copying was interrupted unexpectedly: %v", err) } - b.logger.Info("Total downloaded: %v", files.PrettyBytes(uint64(n.Load()))) + b.logger.Info("Total downloaded: %v", pretty.Bytes(uint64(n.Load()))) return err } |