diff --git a/service.go b/service.go index 17a2e77..a24e8ad 100644 --- a/service.go +++ b/service.go @@ -37,6 +37,7 @@ type Song interface { Title() string ID() string Filename() string + DurationInt() int DurationString() string Thumbnail() string Playlist() Playlist @@ -91,7 +92,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.Duration) + time, _ := time.ParseDuration(song.DurationInt()) if dj.conf.General.MaxSongDuration == 0 || int(time.Seconds()) <= dj.conf.General.MaxSongDuration { if !isNil(song.Playlist()) { title = song.Playlist().Title() diff --git a/service_youtube.go b/service_youtube.go index 6447f05..991cf9c 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -55,8 +55,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) ([]Song, error) { if re, err := regexp.Compile(youtubePlaylistPattern); err == nil { if re.MatchString(url) { shortURL = re.FindStringSubmatch(url)[1] - playlist, err := yt.NewPlaylist(user, shortURL) - return playlist.Title(), err + return yt.NewPlaylist(user, shortURL) } else { re = RegexpFromURL(url, youtubeVideoPatterns) matches := re.FindAllStringSubmatch(url, -1) @@ -136,7 +135,8 @@ func (yt YouTube) parseTime(duration string) time.Duration { } else { totalSeconds = 0 } - return time.ParseDuration(strconv.Itoa(totalSeconds) + "s") + output, _ := time.ParseDuration(strconv.Itoa(int(totalSeconds)) + "s") + return output } // NewPlaylist gathers the metadata for a YouTube playlist and returns it. diff --git a/youtube_dl.go b/youtube_dl.go index c0b9b89..2b1e352 100644 --- a/youtube_dl.go +++ b/youtube_dl.go @@ -15,6 +15,8 @@ import ( "net/http" "os" "os/exec" + "strconv" + "strings" "time" "github.com/jmoiron/jsonq" @@ -28,7 +30,7 @@ type YouTubeSong struct { title string thumbnail string submitter *gumble.User - Duration int + duration int url string offset int format string @@ -74,7 +76,7 @@ func (dl *YouTubeSong) Download() error { } // Play plays the song. Once the song is playing, a notification is displayed in a text message that features the song -// thumbnail, URL, title, Duration, and submitter. +// thumbnail, URL, title, duration, and submitter. func (dl *YouTubeSong) Play() { if dl.offset != 0 { offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset)) @@ -85,7 +87,7 @@ func (dl *YouTubeSong) Play() { panic(err) } else { message := `` - message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.Duration, dl.submitter.Name) + message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.duration, dl.submitter.Name) if !isNil(dl.playlist) { message = fmt.Sprintf(message+``, dl.playlist.Title()) } @@ -167,9 +169,14 @@ func (dl *YouTubeSong) Filename() string { return dl.id + "." + dl.format } -// Duration returns the Duration of the Song. +// 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 { - timeDuration, _ := time.ParseDuration(stvconv.Iota(dl.Duration) + "s") + timeDuration, _ := time.ParseDuration(strconv.Iota(dl.duration) + "s") return timeDuration.String() }
%s (%s)
Added by %s
From playlist "%s"