public string SearchMusic(IMusic musicToSearch)
        {
            switch (musicToSearch)
            {
            case Track _:
            {
                YSearch response = yandexMusicClient.Search.Track(yAuthStorage,
                                                                  musicToSearch.QueryString( ))
                                   .Result;
                foreach (YSearchTrackModel ymTrack in response.Tracks.Results)
                {
                    if (musicToSearch.Equals(new Track(ymTrack.Title,
                                                       ymTrack.Artists.First( ).Name,
                                                       ymTrack.Albums.First( ).Title,
                                                       0)))
                    {
                        return(BuildUri(ymTrack));
                    }
                }
                break;
            }

            case Album _:
            {
                YSearch response = yandexMusicClient.Search.Albums(yAuthStorage,
                                                                   musicToSearch.QueryString( ))
                                   .Result;
                foreach (YSearchAlbumModel ymAlbum in response.Albums.Results)
                {
                    if (musicToSearch.Equals(new Album(ymAlbum.Title,
                                                       ymAlbum.Artists.First( ).Name,
                                                       ymAlbum.Year.ToString( ))))
                    {
                        return(BuildUri(ymAlbum));
                    }
                }
                break;
            }

            case Artist artistToSearch:
            {
                YSearch response = yandexMusicClient.Search.Artist(yAuthStorage,
                                                                   musicToSearch.QueryString( ))
                                   .Result;
                foreach (YSearchArtistModel ymArtist in response.Artists.Results)
                {
                    if (string.Equals(artistToSearch.Name, ymArtist.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        var ymArtistBrief = yandexMusicClient.Artist.Get(yAuthStorage,
                                                                         ymArtist.Id)
                                            .Result;
                        foreach (YAlbum ymAlbum in ymArtistBrief.Albums)
                        {
                            if (artistToSearch.SampleAlbum.Equals(new Album(ymAlbum.Title,
                                                                            ymArtist.Name,
                                                                            ymAlbum.Year.ToString( ))))
                            {
                                return(BuildUri(ymArtist));
                            }
                        }
                    }
                }

                break;
            }
            }

            return(null);
        }
示例#2
0
        public string SearchMusic(IMusic musicToSearch)
        {
            switch (musicToSearch)
            {
            case Track _:
            {
                SearchResponse response = ConverterBot.Clients.SpotifyClient.Search.Item(
                    new SearchRequest(SearchRequest.Types.Track,
                                      musicToSearch.QueryString( )))
                                          .Result;
                foreach (FullTrack sTrack in response.Tracks.Items)
                {
                    if (musicToSearch.Equals(new Track(sTrack.Name,
                                                       sTrack.Artists.First( ).Name,
                                                       sTrack.Album.Name,
                                                       0)))
                    {
                        return(BuildUri(sTrack));
                    }
                }

                break;
            }

            case Album _:
            {
                SearchResponse response = ConverterBot.Clients.SpotifyClient.Search.Item(
                    new SearchRequest(SearchRequest.Types.Album,
                                      musicToSearch.QueryString( )))
                                          .Result;
                foreach (SimpleAlbum sAlbum in response.Albums.Items)
                {
                    if (musicToSearch.Equals(new Album(sAlbum.Name,
                                                       sAlbum.Artists.First( ).Name,
                                                       sAlbum.ReleaseDate)))
                    {
                        return(BuildUri(sAlbum));
                    }
                }

                break;
            }

            case Artist artistToSearch:
            {
                SearchResponse response = ConverterBot.Clients.SpotifyClient.Search.Item(
                    new SearchRequest(SearchRequest.Types.Artist,
                                      musicToSearch.QueryString( )))
                                          .Result;
                foreach (FullArtist sArtist in response.Artists.Items)
                {
                    if (sArtist.Name == artistToSearch.Name)
                    {
                        List <SimpleAlbum> sArtistAlbums = ConverterBot.Clients.SpotifyClient.Artists.GetAlbums(sArtist.Id).Result.Items;
                        foreach (SimpleAlbum sSampleAlbum in sArtistAlbums)
                        {
                            if (artistToSearch.SampleAlbum.Equals(new Album(sSampleAlbum.Name,
                                                                            sSampleAlbum.Artists.First().Name,
                                                                            sSampleAlbum.ReleaseDate)))
                            {
                                return(BuildUri(sArtist));
                            }
                        }
                    }
                }
                break;
            }
            }

            return(null);
        }