private async Task <SpotifyTracks> GetTracks(string token, string playlistid) { string url = string.Format("https://api.spotify.com/v1/playlists/{0}/tracks", playlistid); SpotifyTracks tracks = JsonConvert.DeserializeObject <SpotifyTracks>(await GetSpotifyType(token, url)); if (tracks.total > 20) { do { SpotifyTracks tmp = JsonConvert.DeserializeObject <SpotifyTracks>(await GetSpotifyType(token, url)); if (tmp.next != null) { url = tmp.next.ToString(); } else { url = null; } for (int i = 0; i < tmp.items.Count; i++) { tracks.items.Add(tmp.items[i]); } } while (url != null); } return(tracks); }
private async void Button_Click(object sender, RoutedEventArgs e) { cover.Children.RemoveRange(0, cover.Children.Count); errorbox.Text = ""; if (userid.Text == "") { errorbox.Text = "insert a userid"; return; } SpotifyPlaylists playlists = new SpotifyPlaylists(); playlists = await GetPlayLists(await GetToken(), userid.Text); int tracks = 0; for (int i = 0; i < playlists.items.Count; i++) { tracks += playlists.items[i].tracks.total; } playlistcount.Text = "Playlists: " + playlists.items.Count; songcount.Text = "Songs: " + tracks; if (track.Text != "") { for (int i = 0; i < playlists.items.Count; i++) { bool containstrack = false; SpotifyTracks playlisttracks = await GetTracks(await GetToken(), playlists.items[i].id); for (int y = 0; y < playlisttracks.items.Count; y++) { if (playlisttracks.items[y].track.name.ToLower() == track.Text.ToLower()) { containstrack = true; } } if (!containstrack) { playlists.items.RemoveAt(i); i--; } } } for (int i = 0; i < playlists.items.Count; i++) { Grid grid = new Grid(); StackPanel panel = new StackPanel(); System.Windows.Controls.Image image = new System.Windows.Controls.Image(); TextBlock textBlock = new TextBlock(); DropShadowEffect myDropShadowEffect = new DropShadowEffect(); myDropShadowEffect.Color = Colors.Black; myDropShadowEffect.Direction = 320; myDropShadowEffect.ShadowDepth = 25; myDropShadowEffect.Opacity = 0.5; myDropShadowEffect.BlurRadius = 40; panel.Margin = new Thickness(0, 60, 0, 0); panel.Orientation = Orientation.Vertical; grid.Margin = new Thickness(10, 10, 10, 10); textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.Foreground = Brushes.Gray; textBlock.Margin = new Thickness(59, 5, 59, 0); textBlock.Width = 100; textBlock.TextAlignment = TextAlignment.Center; image.Width = 150; image.Height = 150; textBlock.Text = playlists.items[i].name; Uri resourceUri = new Uri(playlists.items[i].images[0].url, UriKind.RelativeOrAbsolute); image.Source = new BitmapImage(resourceUri); image.Effect = myDropShadowEffect; panel.Children.Add(image); panel.Children.Add(textBlock); grid.Children.Add(panel); cover.Children.Add(grid); } }