Fixed URL parsing not working for some URLs
This commit is contained in:
parent
ff222e10c1
commit
68a4052809
|
@ -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
|
||||||
|
|
Reference in a new issue