small comment changes

This commit is contained in:
Nikola Jovicic 2016-02-08 16:49:24 +01:00
parent 317de0200a
commit 3788c84607
4 changed files with 13 additions and 9 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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)

View file

@ -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()))