示例#1
0
        public async Task ResolveAsync(Track track)
        {
            string title;
            string artist;
            this.PrepareTrack(track, out title, out artist);

            var q = $"track:%22{title}%22&artist:\"{artist}\"";
            q = PreprocessRequest(q);
            var searchItem = await _spotify.SearchItemsAsync(q, SearchType.Track, 50);
            LogIfError(q, searchItem);

            // if no result found, search for title only
            if (searchItem.Tracks?.Items?.Count == 0)
            {
                await Task.Delay(REQUESTSDELAY); // avoid "API rate limit exceeded"

                q = $"track:%22{title}%22";
                q = PreprocessRequest(q);
                searchItem = await _spotify.SearchItemsAsync(q, SearchType.Track, 50);
                LogIfError(q, searchItem);
            }

            var spotifyTracks = searchItem?.Tracks?.Items
                .OrderByDescending(x => x.Popularity)
                .Select(x => new SpotifyTrack(x));

            if (spotifyTracks != null)
                track.SetMatches(spotifyTracks);
        }