示例#1
0
    public static async Task <string> Search(string query)
    {
        SpotifyUser?user = await GetSpotifyUser("strbhlfe");

        if (user is null)
        {
            return("can't search for a track at the moment");
        }

        SearchResponse response = await new SpotifyClient(user.AccessToken).Search.Item(new(SearchRequest.Types.Track, query));
        FullTrack?     track    = SpotifyHelper.GetExcactTrackFromSearch(response.Tracks.Items, query.Split().ToList());

        if (track is not null)
        {
            string[] artists = track.Artists.GetArtistNames();
            return($"{track.Name} by {string.Join(", ", artists)} || {track.Uri}");
        }
        else
        {
            return("no tracks found to match the search query");
        }
    }