From 3fad4189646cca5d6db99ccfe79be695ef765d03 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 30 Jul 2023 19:04:12 +0800 Subject: Refactor: extract pretty duration to a function. Create `pretty` package for creating human friendly strings --- bilibili/streaming.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'bilibili/streaming.go') 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 } -- cgit v1.2.3