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

pull/18/head 2.2.5
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,20 +148,22 @@ 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]
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)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Download(); err == nil {
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Play()
} else {
user.Send(AUDIO_FAIL_MSG)
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Delete()
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)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Download(); err == nil {
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Play()
} else {
user.Send(AUDIO_FAIL_MSG)
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Delete()
}
}
}
}