// NewRequest creates the requested song/playlist and adds to the queue func (sc SoundCloud) NewRequest(user *gumble.User, url string) ([]Song, error) { var apiResponse *jsonq.JsonQuery var songArray []Song var err error timesplit := strings.Split(url, "#t=") url = fmt.Sprintf("http://api.soundcloud.com/resolve?url=%s&client_id=%s", timesplit[0], dj.conf.ServiceKeys.SoundCloud) if apiResponse, err = PerformGetRequest(url); err != nil { return nil, errors.New(fmt.Sprintf(INVALID_API_KEY, sc.ServiceName())) } tracks, err := apiResponse.ArrayOfObjects("tracks") if err == nil { // PLAYLIST // Create playlist title, _ := apiResponse.String("title") permalink, _ := apiResponse.String("permalink_url") playlist := &AudioPlaylist{ id: permalink, title: title, } if dj.conf.General.MaxSongPerPlaylist > 0 && len(tracks) > dj.conf.General.MaxSongPerPlaylist { tracks = tracks[:dj.conf.General.MaxSongPerPlaylist] } // Add all tracks for _, t := range tracks { if song, err := sc.NewSong(user, jsonq.NewQuery(t), 0, playlist); err == nil { songArray = append(songArray, song) } } return songArray, nil } else { // SONG // Calculate offset offset := 0 if len(timesplit) == 2 { timesplit = strings.Split(timesplit[1], ":") multiplier := 1 for i := len(timesplit) - 1; i >= 0; i-- { time, _ := strconv.Atoi(timesplit[i]) offset += time * multiplier multiplier *= 60 } } // Add the track if song, err := sc.NewSong(user, apiResponse, offset, nil); err == nil { return append(songArray, song), err } return nil, err } }