From 508065f6080a2ad127a483c2b96167c3d7368e8a Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Sat, 26 Sep 2015 16:15:41 +0100 Subject: [PATCH] Making Duration of type time.Duration --- main.go | 1 - service.go | 6 ++---- youtube_dl.go | 11 +++-------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 86c45c0..bda7499 100644 --- a/main.go +++ b/main.go @@ -170,7 +170,6 @@ func isNil(a interface{}) bool { } // dj variable declaration. This is done outside of main() to allow global use. -var dj = mumbledj{ keepAlive: make(chan bool), queue: NewSongQueue(), playlistSkips: make(map[string][]string), diff --git a/service.go b/service.go index a24e8ad..8f4a23d 100644 --- a/service.go +++ b/service.go @@ -37,8 +37,7 @@ type Song interface { Title() string ID() string Filename() string - DurationInt() int - DurationString() string + Duration() time.Duration Thumbnail() string Playlist() Playlist DontSkip() bool @@ -92,8 +91,7 @@ func FindServiceAndAdd(user *gumble.User, url string) error { oldLength := dj.queue.Len() for _, song := range songArray { // Check song is not too long - time, _ := time.ParseDuration(song.DurationInt()) - if dj.conf.General.MaxSongDuration == 0 || int(time.Seconds()) <= dj.conf.General.MaxSongDuration { + if dj.conf.General.MaxSongDuration == 0 || song.Duration().Seconds()) <= dj.conf.General.MaxSongDuration { if !isNil(song.Playlist()) { title = song.Playlist().Title() } else { diff --git a/youtube_dl.go b/youtube_dl.go index fcd6dba..acecf24 100644 --- a/youtube_dl.go +++ b/youtube_dl.go @@ -169,15 +169,10 @@ func (dl *YouTubeSong) Filename() string { return dl.id + "." + dl.format } -// DurationInt returns number of seconds for the Song. -func (dl *YouTubeSong) DurationInt() string { - return duration -} - -// DurationString returns the pretty version of duration for the Song. -func (dl *YouTubeSong) DurationString() string { +// Duration returns duration for the Song. +func (dl *YouTubeSong) Duration() time.Duration { timeDuration, _ := time.ParseDuration(strconv.Itoa(dl.duration) + "s") - return timeDuration.String() + return timeDuration } // Thumbnail returns the thumbnail URL for the Song.