Fixed URL parsing not working for some URLs

This commit is contained in:
Matthieu Grieger 2014-12-30 13:27:12 -08:00
parent ff222e10c1
commit 68a4052809

View file

@ -143,19 +143,19 @@ func add(user, url string) (string, error) {
`https?:\/\/www.youtube.com\/v\/([\w-]+)`,
}
matchFound := false
shortUrl := ""
for _, pattern := range youtubePatterns {
if re, err := regexp.Compile(pattern); err == nil {
if re.MatchString(url) {
matchFound = true
shortUrl = re.FindStringSubmatch(url)[1]
break
}
}
}
if matchFound {
urlMatch := strings.Split(url, "=")
shortUrl := urlMatch[1]
newSong := NewSong(user, shortUrl)
if err := dj.queue.AddSong(newSong); err == nil {
return newSong.title, nil