Making Duration of type time.Duration

This commit is contained in:
MichaelOultram 2015-09-26 16:15:41 +01:00
parent cd03a947ed
commit 508065f608
3 changed files with 5 additions and 13 deletions

View file

@ -170,7 +170,6 @@ func isNil(a interface{}) bool {
} }
// dj variable declaration. This is done outside of main() to allow global use. // dj variable declaration. This is done outside of main() to allow global use.
var dj = mumbledj{
keepAlive: make(chan bool), keepAlive: make(chan bool),
queue: NewSongQueue(), queue: NewSongQueue(),
playlistSkips: make(map[string][]string), playlistSkips: make(map[string][]string),

View file

@ -37,8 +37,7 @@ type Song interface {
Title() string Title() string
ID() string ID() string
Filename() string Filename() string
DurationInt() int Duration() time.Duration
DurationString() string
Thumbnail() string Thumbnail() string
Playlist() Playlist Playlist() Playlist
DontSkip() bool DontSkip() bool
@ -92,8 +91,7 @@ func FindServiceAndAdd(user *gumble.User, url string) error {
oldLength := dj.queue.Len() oldLength := dj.queue.Len()
for _, song := range songArray { for _, song := range songArray {
// Check song is not too long // Check song is not too long
time, _ := time.ParseDuration(song.DurationInt()) if dj.conf.General.MaxSongDuration == 0 || song.Duration().Seconds()) <= dj.conf.General.MaxSongDuration {
if dj.conf.General.MaxSongDuration == 0 || int(time.Seconds()) <= dj.conf.General.MaxSongDuration {
if !isNil(song.Playlist()) { if !isNil(song.Playlist()) {
title = song.Playlist().Title() title = song.Playlist().Title()
} else { } else {

View file

@ -169,15 +169,10 @@ func (dl *YouTubeSong) Filename() string {
return dl.id + "." + dl.format return dl.id + "." + dl.format
} }
// DurationInt returns number of seconds for the Song. // Duration returns duration for the Song.
func (dl *YouTubeSong) DurationInt() string { func (dl *YouTubeSong) Duration() time.Duration {
return duration
}
// DurationString returns the pretty version of duration for the Song.
func (dl *YouTubeSong) DurationString() string {
timeDuration, _ := time.ParseDuration(strconv.Itoa(dl.duration) + "s") timeDuration, _ := time.ParseDuration(strconv.Itoa(dl.duration) + "s")
return timeDuration.String() return timeDuration
} }
// Thumbnail returns the thumbnail URL for the Song. // Thumbnail returns the thumbnail URL for the Song.