Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            try
            {
                var token = await SpotifyClient.GetAccessToken(CLIENT_ID, CLIENT_SECRET);

                try
                {
                    var client = new SpotifyClient(token);

                    var searchResponse = await client.Search("Coheed & Cambria", new string[] { "track" });

                    foreach (var track in searchResponse.Tracks.Items)
                    {
                        Console.WriteLine(track.Name);
                    }
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine($"Error while executing API request: {e.Message}");
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"Error while authenticating: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Uncaught error: {e}");
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        public async IAsyncEnumerable <AbstractQueryResult> Process(Query query)
        {
            var queryParts = query.RawQuery.Split(new[] { ' ' }, 2);

            if (queryParts[0] == "skip" || queryParts[0] == "next" ||
                queryParts[0] == "prev" || queryParts[0] == "back")
            {
                yield return(new ChangeTrackResult(queryParts[0]));

                yield break;
            }

            yield return(new PlayPauseResult());

            var isSearchQuery = queryParts.Length > 1 &&
                                queryParts[1].Length > 3 &&
                                queryParts[0] != "pause";

            if (!isSearchQuery)
            {
                yield break;
            }

            var queryType   = MapToSpotifySearchType(queryParts[0]);
            var searchQuery = queryParts[1];

            var searchResults = await _spotifyClient.Search(searchQuery, queryType);

            foreach (var searchResult in searchResults)
            {
                yield return(new SpotifySearchResult(searchResult.DisplayString, searchResult.Uri));
            }
        }
Exemplo n.º 3
0
        public async IAsyncEnumerable <AbstractQueryResult> Process(Query query)
        {
            var queryParts  = query.RawQuery.Split(new[] { ' ' }, 2);
            var queryType   = MapToSpotifySearchType(queryParts[0]);
            var searchQuery = queryParts[1];


            var searchResults = await _spotifyClient.Search(searchQuery, queryType);

            yield return(new PlayPauseResult());

            foreach (var searchResult in searchResults)
            {
                yield return(new SpotifySearchResult(searchResult.DisplayString, searchResult.Uri));
            }
        }