Fix https://github.com/matthieugrieger/mumbledj/issues/14: Bot crash on YouTube playlist URLs with '-' character

This commit is contained in:
Matthieu Grieger 2015-01-09 16:45:17 -08:00
parent f8c4078438
commit 7fe12c4e43
2 changed files with 15 additions and 10 deletions

View file

@ -1,6 +1,9 @@
MumbleDJ Changelog
==================
### January 9, 2015 -- `v2.2.5`
* Fixed some YouTube playlist URLs crashing the bot and not retrieving metadata correctly.
### January 8, 2015 -- `v2.2.4`
* Fixed a crash caused by a user trying to skip the same song more than once.

View file

@ -148,11 +148,12 @@ func add(user *gumble.User, username, url string) {
}
} else {
// Check to see if we have a playlist URL instead.
youtubePlaylistPattern := `https?:\/\/www\.youtube\.com\/playlist\?list=(\w+)`
youtubePlaylistPattern := `https?:\/\/www\.youtube\.com\/playlist\?list=([\w-]+)`
if re, err := regexp.Compile(youtubePlaylistPattern); err == nil {
if re.MatchString(url) {
if dj.HasPermission(username, dj.conf.Permissions.AdminAddPlaylists) {
shortUrl = re.FindStringSubmatch(url)[1]
if shortUrl != nil {
newPlaylist := NewPlaylist(username, shortUrl)
if dj.queue.AddItem(newPlaylist); err == nil {
dj.client.Self().Channel().Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
@ -165,6 +166,7 @@ func add(user *gumble.User, username, url string) {
}
}
}
}
} else {
user.Send(NO_PLAYLIST_PERMISSION_MSG)
}