From 36ff5818864de549b431f31e3db7093b9c1ec7de Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 9 May 2015 22:05:05 -0700 Subject: [PATCH] Fixed duration showing 0:00 when song is less than a minute long --- service_youtube.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index b91827a..52883f0 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -77,12 +77,16 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub var minutes, seconds int64 if strings.Contains(duration, "M") { minutes, _ = strconv.ParseInt(duration[2:strings.Index(duration, "M")], 10, 32) + if strings.Contains(duration, "S") { + seconds, _ = strconv.ParseInt(duration[strings.Index(duration, "M")+1:len(duration)-1], 10, 32) + } else { + seconds = 0 + } + } else if strings.Contains(duration, "S") { + minutes = 0 + seconds, _ = strconv.ParseInt(duration[2:len(duration)-1], 10, 32) } else { minutes = 0 - } - if strings.Contains(duration, "S") { - seconds, _ = strconv.ParseInt(duration[strings.Index(duration, "M")+1:len(duration)-1], 10, 32) - } else { seconds = 0 }