From 13feac24bde26974067d96723d347bc3d5c8a652 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Mon, 27 Jul 2015 23:30:59 +0100 Subject: [PATCH] Fixing build issues --- commands.go | 5 ++--- service_youtube.go | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 2e8f205..0d32d30 100644 --- a/commands.go +++ b/commands.go @@ -175,10 +175,9 @@ func add(user *gumble.User, username, url string) { if urlService == nil { dj.SendPrivateMessage(user, INVALID_URL_MSG) + } else { + urlService.NewRequest(user, url) } - // else { - // urlService.NewRequest(user, url) - // } youtubePatterns := []string{ `https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`, diff --git a/service_youtube.go b/service_youtube.go index 41a0e28..587f564 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -63,7 +63,27 @@ func (y YouTube) URLRegex(url string) bool { // Creates the requested song/playlist and adds to the queue func (y YouTube) NewRequest(user *gumble.User, url string) error { - return nil + var matches, shortURL, startOffset + 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] + NewYouTubePlaylist(username, shortURL) + } else { + return errors.new("NO_PLAYLIST_PERMISSION") + } + } else { + matches = re.FindAllStringSubmatch(url, -1) + shortURL = matches[0][1] + if len(matches[0]) == 3 { + startOffset = matches[0][2] + } + NewYouTubeSong(user, shortURL, startOffset, nil) + } + return nil + } + return err } // ------------