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-]+)`, `https?:\/\/www.youtube.com\/v\/([\w-]+)`,
} }
matchFound := false matchFound := false
shortUrl := ""
for _, pattern := range youtubePatterns { for _, pattern := range youtubePatterns {
if re, err := regexp.Compile(pattern); err == nil { if re, err := regexp.Compile(pattern); err == nil {
if re.MatchString(url) { if re.MatchString(url) {
matchFound = true matchFound = true
shortUrl = re.FindStringSubmatch(url)[1]
break break
} }
} }
} }
if matchFound { if matchFound {
urlMatch := strings.Split(url, "=")
shortUrl := urlMatch[1]
newSong := NewSong(user, shortUrl) newSong := NewSong(user, shortUrl)
if err := dj.queue.AddSong(newSong); err == nil { if err := dj.queue.AddSong(newSong); err == nil {
return newSong.title, nil return newSong.title, nil