From 2173edd1c6e69f9a37f28c644c8eb086a575f845 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Tue, 19 May 2015 01:21:33 -0700 Subject: [PATCH] Fix https://github.com/matthieugrieger/mumbledj/issues/70: panic on playlist add --- service_youtube.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index 1712c13..fc321d2 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -59,7 +59,9 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub offsetMatch := offsetExp.FindStringSubmatch(offset) offsetResult := make(map[string]string) for i, name := range offsetExp.SubexpNames() { - offsetResult[name] = offsetMatch[i] + if i < len(offsetMatch) { + offsetResult[name] = offsetMatch[i] + } } if offsetResult["days"] != "" { @@ -85,7 +87,9 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub timestampMatch := timestampExp.FindStringSubmatch(duration) timestampResult := make(map[string]string) for i, name := range timestampExp.SubexpNames() { - timestampResult[name] = timestampMatch[i] + if i < len(timestampMatch) { + timestampResult[name] = timestampMatch[i] + } } if timestampResult["days"] != "" { @@ -354,8 +358,11 @@ func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) { timestampExp := regexp.MustCompile(`P(?P\d+D)?T(?P\d+H)?(?P\d+M)?(?P\d+S)?`) timestampMatch := timestampExp.FindStringSubmatch(videoDuration) timestampResult := make(map[string]string) + fmt.Println(timestampExp.SubexpNames()) for i, name := range timestampExp.SubexpNames() { - timestampResult[name] = timestampMatch[i] + if i < len(timestampMatch) { + timestampResult[name] = timestampMatch[i] + } } if timestampResult["days"] != "" {