From 3788c846071250a3c47e4b3c5071f3d806bc19b0 Mon Sep 17 00:00:00 2001 From: Nikola Jovicic Date: Mon, 8 Feb 2016 16:49:24 +0100 Subject: [PATCH] small comment changes --- commands.go | 4 ++-- service.go | 6 ++++-- service_soundcloud.go | 3 ++- service_youtube.go | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/commands.go b/commands.go index 60774da..8522f92 100644 --- a/commands.go +++ b/commands.go @@ -247,8 +247,8 @@ func addNext(user *gumble.User, url string) error { } } -// searchSong performs !addnext functionality. Checks input searchString for service, and adds -// the found song to the queue as the next song if the format matches. +// searchSong performs !search functionality. Checks input searchString for service, and searches +// for a song or video and tries to add the first result to the playlist. func searchSong(user *gumble.User, searchString string) error { if searchString == "" { dj.SendPrivateMessage(user, NO_ARGUMENT_MSG) diff --git a/service.go b/service.go index 318b3ec..df36fa9 100644 --- a/service.go +++ b/service.go @@ -134,6 +134,8 @@ func FindServiceAndAdd(user *gumble.User, url string) error { } } +// FindServiceAndSearch tries to find the right service and gives the url escaped query to it. +// The resulting string is a URL to the video/song and its supplied to the function FindServiceAndAdd func FindServiceAndSearch(user *gumble.User, searchString string) error { var searchService Service @@ -148,7 +150,7 @@ func FindServiceAndSearch(user *gumble.User, searchString string) error { return errors.New("NO_ARGUMENT") } - // Checks all services to see if any can take the URL + // Checks all services to see if any can take the searchString for _, service := range services { if service.SearchRegex(serviceProvider) { searchService = service @@ -161,7 +163,7 @@ func FindServiceAndSearch(user *gumble.User, searchString string) error { var songURL string var err error - // Get service to create songs + // Get song/video URL if songURL, err = searchService.SearchSong(argument); err != nil { return err } diff --git a/service_soundcloud.go b/service_soundcloud.go index de29f57..ce53fc8 100644 --- a/service_soundcloud.go +++ b/service_soundcloud.go @@ -46,6 +46,7 @@ func (sc SoundCloud) URLRegex(url string) bool { return RegexpFromURL(url, []string{soundcloudSongPattern, soundcloudPlaylistPattern}) != nil } +// SearchRegex checks to see if service will accept the searchString func (sc SoundCloud) SearchRegex(searchService string) bool { return searchService == soundcloudSearchServiceName } @@ -104,7 +105,7 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) ([]Song, error) { } } -// SearchSong searches for a Song and adds the first hit +// SearchSong searches for a Song and returns the Songs URL func (sc SoundCloud) SearchSong(searchString string) (string, error) { var returnString string url := fmt.Sprintf("https://api.soundcloud.com/tracks?q=%s&client_id=%s&limit=1", searchString, dj.conf.ServiceKeys.SoundCloud) diff --git a/service_youtube.go b/service_youtube.go index 73e9015..6e1818b 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -33,8 +33,8 @@ var youtubeVideoPatterns = []string{ // SearchService name var youtubeSearchServiceName = "yt" -// SearchService vidoe UTL prefix -var videoURLprefix = "https://www.youtube.com/watch?v=" +// SearchService video URL prefix +var youtubeVideoURLprefix = "https://www.youtube.com/watch?v=" // YouTube implements the Service interface type YouTube struct{} @@ -54,6 +54,7 @@ func (yt YouTube) URLRegex(url string) bool { return RegexpFromURL(url, append(youtubeVideoPatterns, []string{youtubePlaylistPattern}...)) != nil } +// SearchRegex checks to see if service will accept the searchString func (yt YouTube) SearchRegex(searchService string) bool { return searchService == youtubeSearchServiceName } @@ -85,14 +86,14 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) ([]Song, error) { } } -// SearchSong searches for a Song and adds the first hit +// SearchSong searches for a Song and returns the Songs URL func (yt YouTube) SearchSong(searchString string) (string, error) { var returnString, apiStringValue string searchURL := fmt.Sprintf("https://www.googleapis.com/youtube/v3/search?part=snippet&q=%s&key=%s&maxResults=1&type=video", searchString, dj.conf.ServiceKeys.Youtube) if apiResponse, err := PerformGetRequest(searchURL); err == nil { apiStringValue, _ = apiResponse.String("items", "0", "id", "videoId") - returnString = videoURLprefix + apiStringValue + returnString = youtubeVideoURLprefix + apiStringValue return returnString, nil } return "", errors.New(fmt.Sprintf(INVALID_API_KEY, yt.ServiceName()))