コード例 #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            CredentialsAuth auth  = new CredentialsAuth(clientId, clientSecret);
            Token           token = await auth.GetToken();

            _spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            //FullTrack track = _spotify.GetTrack("3Hvu1pq89D4R0lyPBoujSv");
            //Console.WriteLine("Current Track: " + track.Name); //Yeay! We just printed a tracks name.
            //string Search = textBox1.Text;
            //SearchItem item = _spotify.SearchItems(Search, SpotifyAPI.Web.Enums.SearchType.Album | SpotifyAPI.Web.Enums.SearchType.Playlist);
            //Console.WriteLine(item.Albums.Total);

            List <string> AllTitles = Load_Articles();

            foreach (string Word in AllTitles)
            {
                List <string> ImportantWords = Word_Extractor(Word);
                foreach (string Query in ImportantWords)
                {
                    QueryList(Query);
                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Load all the songs from our songs folder into an list of <c>SongObject</c>
        /// </summary>
        public async static void Initialize(GraphicsDevice graphics)
        {
            if (!Directory.Exists(CONTENT_PATH))
            {
                Directory.CreateDirectory(CONTENT_PATH);
            }

            CredentialsAuth auth  = new CredentialsAuth("e1c3ce28971a4396bd46eba97d14c271", "951448c26c5544ce8af238bdda3277d8");
            Token           token = await auth.GetToken();

            spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            foreach (string song in Directory.EnumerateFiles(CONTENT_PATH, "*_p.psarc", SearchOption.AllDirectories))
            {
                using (var inputStream = File.OpenRead(song))
                {
                    SongObject newSong = UnpackArchive(song, inputStream, graphics);
                    if (newSong != null)
                    {
                        songObjects.Add(newSong);
                    }
                }
            }
        }
コード例 #3
0
        private async Task <Token> getToken()
        {
            CredentialsAuth auth  = new CredentialsAuth(clientId, clientSecret);
            Token           token = await auth.GetToken();

            return(token);
        }
コード例 #4
0
        public async Task <IActionResult> GetSpotifyAlt(string title, string artist)
        {
            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            var keyVaultClient = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback)
                );
            var spotifyID = await keyVaultClient.GetSecretAsync("https://wakeyvault.vault.azure.net/secrets/appSettings--connectionSettings--spotifyId/69cdf003254f4b2e81a5ce90dffe80ab").ConfigureAwait(false);

            Console.Write(spotifyID);
            var spotifySecret = await keyVaultClient.GetSecretAsync("https://wakeyvault.vault.azure.net/secrets/appSettings--connectionStrings--spotifySecret/49de24c1d0a44edcb4c7e9379b49d1a4").ConfigureAwait(false);

            CredentialsAuth auth  = new CredentialsAuth(spotifyID.Value, spotifySecret.Value);
            Token           token = await auth.GetToken();

            SpotifyWebAPI api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            SearchItem searchItem = api.SearchItems(title, SearchType.Track);


            return(Ok(searchItem.Tracks.Items[1]));
        }
コード例 #5
0
        public async Task <AlbumDto> GetSpotifyAlbum(string id)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var albumFromSpotify = await api.GetAlbumAsync(id);

            if (!albumFromSpotify.HasError())
            {
                return new AlbumDto()
                       {
                           Artist   = string.Join(",", albumFromSpotify.Artists.Select((x) => x.Name)),
                           Name     = albumFromSpotify.Name,
                           Id       = albumFromSpotify.Id,
                           UserId   = 1,
                           CoverUrl = albumFromSpotify.Images[0].Url,
                           Year     = albumFromSpotify.ReleaseDate.Substring(0, 4),
                           ArtistId = albumFromSpotify.Artists[0].Id,
                       }
            }
            ;
            if (albumFromSpotify.Error.Message != "invalid id")
            {
                throw new Exception("Problem with retrieving album data from spotify");
            }

            throw new Exception($"Album with id: {id} was not found.");
        }
コード例 #6
0
        public static async Task <Token> GetSpotifyApiToken()
        {
            auth = new CredentialsAuth(_clientId, _secretId);
            var token = await auth.GetToken();

            return(token);
        }
コード例 #7
0
        public async Task <IEnumerable <ArtistDto> > GetSpotifyArtists(List <string> artistsIdToGet)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var artistsFromSpotify = await api.GetSeveralArtistsAsync(artistsIdToGet);

            var artistsToReturn = new List <ArtistDto>();

            foreach (var artist in artistsFromSpotify.Artists)
            {
                var artistToReturn = new ArtistDto
                {
                    Name = artist.Name, Id = artist.Id, PhotoUrl = artist.Images[0].Url
                };
                artistsToReturn.Add(artistToReturn);
            }

            return(artistsToReturn);
        }
コード例 #8
0
        public async Task <IEnumerable <ArtistDto> > SearchSpotifyArtists(string keyword)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var searchItem = await api.SearchItemsAsync(keyword, SearchType.Artist);

            var artistsToReturn = new List <ArtistDto>();

            foreach (var artist in searchItem.Artists.Items)
            {
                var artistToReturn = new ArtistDto
                {
                    Name     = artist.Name,
                    Id       = artist.Id,
                    PhotoUrl = artist.Images.Count > 0 ? artist.Images[0].Url : null
                };
                artistsToReturn.Add(artistToReturn);
            }

            return(artistsToReturn);
        }
コード例 #9
0
        public async Task <IEnumerable <AlbumDto> > SearchSpotifyAlbums(string keyword)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var searchItem = await api.SearchItemsAsync(keyword, SearchType.Album);

            var albumsToReturn = new List <AlbumDto>();

            foreach (var album in searchItem.Albums.Items)
            {
                var albumToReturn = new AlbumDto
                {
                    Artist   = album.Artists[0].Name,
                    Name     = album.Name,
                    Id       = album.Id,
                    UserId   = 1,
                    CoverUrl = album.Images[0].Url,
                    Year     = album.ReleaseDate.Substring(0, 4)
                };
                albumsToReturn.Add(albumToReturn);
            }

            return(albumsToReturn);
        }
コード例 #10
0
        public async Task <IEnumerable <AlbumDto> > GetSpotifyAlbums(List <string> albumsIdToGet)
        {
            var auth  = new CredentialsAuth(ClientId, SecretId);
            var token = await auth.GetToken();

            var api = new SpotifyWebAPI()
            {
                TokenType   = token.TokenType,
                AccessToken = token.AccessToken
            };

            var albumsFromSpotify = await api.GetSeveralAlbumsAsync(albumsIdToGet);

            var albumsToReturn = new List <AlbumDto>();

            foreach (var album in albumsFromSpotify.Albums)
            {
                var albumToReturn = new AlbumDto
                {
                    Artist   = album.Artists[0].Name,
                    ArtistId = album.Artists[0].Id,
                    Name     = album.Name,
                    Id       = album.Id,
                    UserId   = 1,
                    CoverUrl = album.Images[0].Url,
                    Year     = album.ReleaseDate.Substring(0, 4)
                };
                albumsToReturn.Add(albumToReturn);
            }

            return(albumsToReturn);
        }
コード例 #11
0
        private static async Task <SpotifyWebAPI> ConnectSpotifyApi()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            CredentialsAuth auth  = new CredentialsAuth(config.GetSection("SpotifyApi:ClientId").Value, config.GetSection("SpotifyApi:ClientSecret").Value);
            Token           token = await auth.GetToken();

            var _spotify = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };

            //var listCategories = _spotify.GetCategories();
            //var list = _spotify.GetAlbumTracks()

            //foreach (var item in listCategories.Categories.Items)
            //{
            //    Console.WriteLine(item.Name);
            //}

            return(_spotify);
        }
コード例 #12
0
        public List <Disk> GetTop50ByGenre()
        {
            var auth  = new CredentialsAuth(CLIENTID, SECRET);
            var token = auth.GetToken().Result;
            var api   = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };
            var         genres = Enum.GetValues(typeof(EDiskGenre));
            List <Disk> disks  = new List <Disk>();


            //search the top 50 albums by genre and add in the disk list
            foreach (var g in genres)
            {
                SearchItem search = api.SearchItems(g.ToString(), SearchType.Album, 50);

                foreach (var sDisk in search.Albums.Items)
                {
                    decimal value       = Convert.ToDecimal(string.Format("{0:0.##}", new Random().NextDouble() * 10));
                    var     description = $"Released Date: {sDisk.ReleaseDate} | URI: {sDisk.Uri} | Album Type: {sDisk.AlbumType}  | Artists: {string.Join<string>(",", sDisk.Artists.Select(x=> x.Name).ToArray())}";
                    disks.Add(new Disk(sDisk.Name, description, value, (EDiskGenre)g, sDisk.Images.FirstOrDefault().Url));
                }
            }

            return(disks);
        }
コード例 #13
0
        public async Task <ActionResult> GenerateTokens()
        {
            CredentialsAuth cred = new CredentialsAuth(Private.Private.Spotify_clientId, Private.Private.Spotify_clientSecret);

            Token token = await cred.GetToken();


            string artistId = "5tWbDIXx7HTHSwBZNJrRgQ";

            SpotifyWebAPI api = new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            var result = api.GetArtist(artistId);

            var result2 = api.GetArtistsTopTracks(artistId, "US");

            int popularity = result2.Tracks[1].Popularity;

            foreach (var song in result2.Tracks)
            {
            }



            return(RedirectToAction("About"));
        }
コード例 #14
0
        /// <summary>
        /// Get a token for use in a SpotyFy API
        /// </summary>
        /// <returns></returns>
        private SpotifyWebAPI GetTokenAuth()
        {
            CredentialsAuth auth  = new CredentialsAuth(_clientID, _clientSecret);
            Token           token = auth.GetToken().Result;

            return(new SpotifyWebAPI {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            });
        }
        public async void GetUserAsync(CredentialsAuth auth)
        {
            Token token = await auth.GetToken();

            WebApi = new SpotifyWebAPI {
                AccessToken = token.AccessToken, TokenType = token.TokenType
            };
            User = await WebApi.GetPrivateProfileAsync();
        }
コード例 #16
0
ファイル: MenuHandle.cs プロジェクト: DrGurka/Play_Tabs
        public MenuHandle(GraphicsDevice graphicsDevice)
        {
            rectangle = new Texture2D(graphicsDevice, 1, 1, false, SurfaceFormat.Color);
            rectangle.SetData <Color>(new Color[] { Color.White });

            screenGradient = CreateGradient(graphicsDevice, new Color(96, 255, 128), new Color(32, 26, 44));

            SongOrganizer.Initialize(graphicsDevice);

            #region Test
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Roundabout", album = "Yesstory", artist = "Yes", length = 512, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "1992"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Africa", album = "Toto IV", artist = "Toto", length = 296, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "1982"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Parabola", album = "Lateralus", artist = "Tool", length = 364, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "2001"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "The Frail", album = "The Fragile", artist = "Nine Inch Nails", length = 114, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "1999"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "The Outsider", album = "Thirteenth Step", artist = "A Perfect Circle", length = 246, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "2003"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Bonneville", album = "Malina", artist = "Leprous", length = 329, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "2017"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Amsterdam", album = "Broken Machine", artist = "Nothing But Thieves", length = 272, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "2017"
            });
            SongOrganizer.songObjects.Add(new SongObject("")
            {
                title = "Change (In the House of Flies)", album = "White Pony", artist = "Deftones", length = 300, tuningLead = new sbyte[6], tuningRhythm = new sbyte[6], year = "2000"
            });

            CredentialsAuth auth    = new CredentialsAuth("e1c3ce28971a4396bd46eba97d14c271", "951448c26c5544ce8af238bdda3277d8");
            Token           token   = Task.Run(() => auth.GetToken()).Result;
            SpotifyWebAPI   spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };

            foreach (SongObject song in SongOrganizer.songObjects)
            {
                SongOrganizer.albumImages.Add(song.artist + "+" + song.album, new AlbumImage(spotify, song.artist + "+" + song.album, graphicsDevice));
            }
            #endregion
        }
コード例 #17
0
        public async void GetToken(CredentialsAuth auth)
        {
            Token token = await auth.GetToken();

            webAPI = new SpotifyWebAPI {
                AccessToken = token.AccessToken, TokenType = token.TokenType
            };
            user = await webAPI.GetPrivateProfileAsync();
        }
コード例 #18
0
        public async void StartClient()
        {
            CredentialsAuth SpotifyAuth  = new CredentialsAuth(SpotifyClientID, SpotifyClientToken);
            Token           SpotifyToken = await SpotifyAuth.GetToken();

            Spotify.TokenType   = SpotifyToken.TokenType;
            Spotify.AccessToken = SpotifyToken.AccessToken;
            this.SpotifyToken   = SpotifyToken;
            OnClientReady?.Invoke();
        }
コード例 #19
0
        public SpotifyService(BotSettings settings)
        {
            CredentialsAuth auth  = new CredentialsAuth(settings.SpotifyClientId, settings.SpotifyClientSecret);
            Token           token = auth.GetToken().Result;

            client = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };
        }
コード例 #20
0
ファイル: SpotifyClient.cs プロジェクト: ikuosaito1989/Client
        public SpotifyClient(string clientId, string clientSecret)
        {
            var auth  = new CredentialsAuth(clientId, clientSecret);
            var token = auth.GetToken().Result;

            _spotify = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };
        }
コード例 #21
0
        async void simpleAuthorize(string clientId, string secretId)
        {
            CredentialsAuth auth  = new CredentialsAuth(_clientId, _secretId);
            Token           token = await auth.GetToken();

            api = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };
        }
        public static void StartCredentialsAuth()
        {
            CredentialsAuth auth  = new CredentialsAuth(_clientId, _secretId);
            Token           token = auth.GetToken().Result;

            api = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };
        }
コード例 #23
0
        public static async Task <SpotifyWebAPI> Create()
        {
            CredentialsAuth auth  = new CredentialsAuth("b2fdac7e678e4d278c8a746869dd0e1c", "ee7ced550c6d40c28342120b3b1ed49d");
            Token           token = await auth.GetToken();

            return(new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType = token.TokenType
            });
        }
コード例 #24
0
        /// <summary>
        /// Method to create a new Spotify API client.
        /// </summary>
        /// <returns>A Spotify API client object that can be reused.</returns>
        private async Task <SpotifyWebAPI> createSpotifyAPI()
        {
            CredentialsAuth credentials = new CredentialsAuth(SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET);
            Token           token       = await credentials.GetToken();

            return(new SpotifyWebAPI
            {
                AccessToken = token.AccessToken,
                TokenType = token.TokenType
            });
        }
コード例 #25
0
        /*
         * AuthenticationHandler()
         * {
         *      auth = new AuthorizationCodeAuth(
         *         _clientId,
         *         _secretId,
         *         "http://localhost:4002",
         *         "http://localhost:4002",
         *         Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative
         *         );
         *
         *      auth.AuthReceived += async (sender, payload) =>
         *      {
         *              auth.Stop();
         *              Token token = await auth.ExchangeCode(payload.Code);
         *              SpotifyWebAPI api = new SpotifyWebAPI()
         *              {
         *                      TokenType = token.TokenType,
         *                      AccessToken = token.AccessToken
         *              };
         *              // Do requests with API client
         *              auth.Start(); // Starts an internal HTTP Server
         *              auth.OpenBrowser();
         *      };
         *
         * }*/

        public static async Task <SpotifyWebAPI> CredentialsAuthMode()
        {
            CredentialsAuth auth  = new CredentialsAuth(clientId, secretId);
            Token           token = await auth.GetToken();

            return(new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType = token.TokenType
            });
        }
コード例 #26
0
        public async Task ConnectWithAPI()
        {
            CredentialsAuth auth  = new CredentialsAuth(clientId, clientSecretId);
            Token           token = await auth.GetToken();

            spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };
        }
コード例 #27
0
        public async Task InitializeAsync()
        {
            CredentialsAuth auth  = new CredentialsAuth(_config.ClientId, _config.ClientSecret);
            Token           token = await auth.GetToken();

            _spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };
        }
コード例 #28
0
        private async Task <SpotifyWebAPI> InitializeWebApi()
        {
            var auth  = new CredentialsAuth(_auth.ClientId, _auth.ClientSecret);
            var token = await auth.GetToken();

            return(new SpotifyWebAPI
            {
                UseAuth = true,
                AccessToken = token.AccessToken,
                TokenType = "Bearer"
            });
        }
コード例 #29
0
        private async Task <SpotifyWebAPI> GetSpotifyWebAPIClient(BotSettings settings)
        {
            CredentialsAuth auth  = new CredentialsAuth(settings.SpotifyClientId, settings.SpotifyClientSecret);
            Token           token = await auth.GetToken();

            SpotifyWebAPI api = new SpotifyWebAPI()
            {
                TokenType = token.TokenType, AccessToken = token.AccessToken
            };

            return(api);
        }
コード例 #30
0
        public static async void getSpotify()
        {
            //ClientID and SecretID
            CredentialsAuth auth  = new CredentialsAuth("088f576b5164473c99d0f31d261d1501", "d42f8386acbe4f6b8894ef9ccae9ef0a");
            Token           token = await auth.GetToken();

            _spotify = new SpotifyWebAPI()
            {
                AccessToken = token.AccessToken,
                TokenType   = token.TokenType
            };
        }