diff --git a/playingbar.go b/playingbar.go index eccabd7..5025a62 100644 --- a/playingbar.go +++ b/playingbar.go @@ -59,7 +59,7 @@ func (p *Progress) Run() { go func() { for { - if p._progress > p.full { + if p._progress > p.full || p.player.isSkipped { p._progress = 0 break @@ -83,10 +83,10 @@ func (p *Progress) Run() { x := p._progress * p.limit / p.full p.textView.SetText(fmt.Sprintf("%s %s%s %s", - start.String(), + fmtDuration(start), strings.Repeat("■", x), strings.Repeat("□", p.limit-x), - end.String(), + fmtDuration(end), )) } @@ -108,5 +108,5 @@ func (p *Progress) NewProgress(songTitle string, full, limit int) { // sets default title and progress bar func (p *Progress) SetDefault() { p.SetSongTitle("-") - p.textView.SetText(fmt.Sprintf("%s %s %s", "0s", strings.Repeat("□", 100), "0s")) + p.textView.SetText(fmt.Sprintf("%s %s %s", "00:00", strings.Repeat("□", 100), "00:00")) } diff --git a/playlist.go b/playlist.go index b4b5b0e..9a8b208 100644 --- a/playlist.go +++ b/playlist.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "path/filepath" - "time" "github.com/gdamore/tcell" "github.com/rivo/tview" @@ -89,9 +88,7 @@ func Playlist(list *tview.List, playBar *Progress, player *Player) *tview.TreeVi go func () { player.Run() - list.AddItem( - fmt.Sprintf("%s | %s", player.length.String(), audioFile.Name), - "", 0, nil) + list.AddItem("", "", 0, nil) } () } else { @@ -102,7 +99,7 @@ func Playlist(list *tview.List, playBar *Progress, player *Player) *tview.TreeVi log(err.Error()) } list.AddItem( - fmt.Sprintf("[ %s ] %s", songLength.Round(time.Second).String(), audioFile.Name), + fmt.Sprintf("[ %s ] %s", fmtDuration(songLength), audioFile.Name), "", 0, nil) } } diff --git a/utils.go b/utils.go index 0982444..19ade8a 100644 --- a/utils.go +++ b/utils.go @@ -2,7 +2,11 @@ package main -import "os" +import ( + "os" + "strings" + "time" +) func log(text string) { @@ -21,3 +25,28 @@ func log(text string) { } } + +func fmtDuration(input time.Duration) string { + + val := input.Round(time.Second).String() + + if !strings.Contains(val, "m") { + val = "0m" + val + } + val = strings.ReplaceAll(val, "h", ":") + val = strings.ReplaceAll(val, "m", ":") + val = strings.ReplaceAll(val, "s", "") + var result []string + + for _, v := range strings.Split(val, ":") { + + if len(v) < 2 { + result = append(result, "0" + v) + } else { + result = append(result, v) + } + + } + + return strings.Join(result, ":") +}