add scrobbling of played tracks

This commit is contained in:
Drew Weymouth
2022-12-31 08:43:36 -08:00
parent 36169f9e5b
commit 923d8ddbe9
2 changed files with 73 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package util
import "time"
type Stopwatch struct {
running bool
started time.Time
elapsed time.Duration
}
func (s *Stopwatch) Start() {
if s.running {
return
}
s.started = time.Now()
s.running = true
}
func (s *Stopwatch) Stop() {
if !s.running {
return
}
s.elapsed += time.Since(s.started)
s.running = false
}
func (s *Stopwatch) Elapsed() time.Duration {
e := s.elapsed
if s.running {
e += time.Since(s.started)
}
return e
}
func (s *Stopwatch) Reset() {
s.running = false
s.elapsed = time.Duration(0)
}