From ac775479575914961d76ba02f398edac80c62768 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Sat, 26 Sep 2015 17:37:19 +0100 Subject: [PATCH] Fixed youtube offset for reals this time --- service_youtube.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index a2c5b0c..1568d8b 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -88,8 +88,8 @@ func (yt YouTube) NewSong(user *gumble.User, id, offset string, playlist Playlis title: title, id: id, url: "https://youtu.be/" + id, - offset: int(yt.parseTime(offset).Seconds()), - duration: int(yt.parseTime(duration).Seconds()), + offset: int(yt.parseTime(offset, `t\=(?P\d+d)?(?P\d+h)?(?P\d+m)?(?P\d+s)?`).Seconds()), + duration: int(yt.parseTime(duration, `P(?P\d+D)?T(?P\d+H)?(?P\d+M)?(?P\d+S)?`).Seconds()), thumbnail: thumbnail, format: "m4a", skippers: make([]string, 0), @@ -104,10 +104,10 @@ func (yt YouTube) NewSong(user *gumble.User, id, offset string, playlist Playlis } // parseTime converts from the string youtube returns to a time.Duration -func (yt YouTube) parseTime(duration string) time.Duration { +func (yt YouTube) parseTime(duration, regex string) time.Duration { var days, hours, minutes, seconds, totalSeconds int64 if duration != "" { - timestampExp := regexp.MustCompile(`P(?P\d+D)?T(?P\d+H)?(?P\d+M)?(?P\d+S)?`) + timestampExp := regexp.MustCompile(regex) timestampMatch := timestampExp.FindStringSubmatch(strings.ToUpper(duration)) timestampResult := make(map[string]string) for i, name := range timestampExp.SubexpNames() {