Click here to Skip to main content
15,878,814 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF EF Core 6 DP Question Pin
Richard Deeming30-Jul-23 21:55
mveRichard Deeming30-Jul-23 21:55 
QuestionWPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois20-Jun-23 18:17
professionalKevin Marois20-Jun-23 18:17 
AnswerRe: WPF xceed CheckcComboBox SelectAll Text Pin
Richard Deeming20-Jun-23 20:53
mveRichard Deeming20-Jun-23 20:53 
GeneralRe: WPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois21-Jun-23 10:32
professionalKevin Marois21-Jun-23 10:32 
QuestionList of Images Pin
Kevin Marois9-Jun-23 13:47
professionalKevin Marois9-Jun-23 13:47 
QuestionChange Image URL's Assembly At Runtime Pin
Kevin Marois6-Jun-23 7:15
professionalKevin Marois6-Jun-23 7:15 
AnswerRe: Change Image URL's Assembly At Runtime Pin
Gerry Schmitz6-Jun-23 15:52
mveGerry Schmitz6-Jun-23 15:52 
Questionc# Spotify API not returning correctly. Pin
elfenliedtopfan52-Jun-23 18:03
elfenliedtopfan52-Jun-23 18:03 
Good morning all,

been writing a little program that when you put a spotify playlist id in it will get the whole playlist

want the name and total songs in the playlist mainly so all songs in the playlist and then total count of all songs

with a bit of hard work managed to get it to deserialize the content but cant seem to get it to return that

what i have currently is this,

so it goes though and get as far as here,

json data returned from spotify api

put it in pastebin link as contains a lot of data

then thought i would use json2c#
to create my structure for me,

and have this in a playlist.cs
<pre lang="C#"><pre>using System;
using System.Collections.Generic;
using System.Text;

namespace Dark_Admin_Panel.Model
{
    public class Playlist
    {
        // Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
        public class AddedBy
        {
            public ExternalUrls external_urls { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class Album
        {
            public string album_type { get; set; }
            public List<Artist> artists { get; set; }
            public List<string> available_markets { get; set; }
            public ExternalUrls external_urls { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public List<Image> images { get; set; }
            public string name { get; set; }
            public string release_date { get; set; }
            public string release_date_precision { get; set; }
            public int total_tracks { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class Artist
        {
            public ExternalUrls external_urls { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public string name { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class ExternalIds
        {
            public string isrc { get; set; }
        }

        public class ExternalUrls
        {
            public string spotify { get; set; }
        }

        public class Followers
        {
            public object href { get; set; }
            public int total { get; set; }
        }

        public class Image
        {
            public int height { get; set; }
            public string url { get; set; }
            public int width { get; set; }
        }

        public class Item
        {
            public DateTime added_at { get; set; }
            public AddedBy added_by { get; set; }
            public bool is_local { get; set; }
            public object primary_color { get; set; }
            public Track track { get; set; }
            public VideoThumbnail video_thumbnail { get; set; }
        }

        public class Owner
        {
            public string display_name { get; set; }
            public ExternalUrls external_urls { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class Root
        {
            public bool collaborative { get; set; }
            public string description { get; set; }
            public ExternalUrls external_urls { get; set; }
            public Followers followers { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public List<Image> images { get; set; }
            public string name { get; set; }
            public Owner owner { get; set; }
            public object primary_color { get; set; }
            public bool @public { get; set; }
            public string snapshot_id { get; set; }
            public Tracks tracks { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class Track
        {
            public Album album { get; set; }
            public List<Artist> artists { get; set; }
            public List<string> available_markets { get; set; }
            public int disc_number { get; set; }
            public int duration_ms { get; set; }
            public bool episode { get; set; }
            public bool @explicit { get; set; }
            public ExternalIds external_ids { get; set; }
            public ExternalUrls external_urls { get; set; }
            public string href { get; set; }
            public string id { get; set; }
            public bool is_local { get; set; }
            public string name { get; set; }
            public int popularity { get; set; }
            public string preview_url { get; set; }
            public bool track { get; set; }
            public int track_number { get; set; }
            public string type { get; set; }
            public string uri { get; set; }
        }

        public class Tracks
        {
            public string href { get; set; }
            public List<Item> items { get; set; }
            public int limit { get; set; }
            public object next { get; set; }
            public int offset { get; set; }
            public object previous { get; set; }
            public int total { get; set; }
        }

        public class VideoThumbnail
        {
            public object url { get; set; }
        }

    }
}


and is called via the spotifySearch methord
C#
<pre>using System;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Text;
using static Dark_Admin_Panel.Model.SpotifySearch;

namespace Dark_Admin_Panel.Model
{
    public class SpotifySearch
    {
        public class ExternalUrls
        {
            public string spotify { get; set; }
        }

        public class Followers
        {
            public object href { get; set; }
            public int total { get; set; }
        }

        public class ImageSP
        {
            public int width { get; set; }
            public string url { get; set; }
            public int height { get; set; }
        }

        public class Item
        {
            public ExternalUrls external_urls { get; set; }
            public Followers followers { get; set; }
            public List<string> genres { get; set; }
            public string id { get; set; }
            public List<ImageSP> images { get; set; }
            public string name { get; set; }
            public int popularity { get; set; }
            public string type { get; set; }
            public string uri { get; set; }

        }

        public class Artists
        {
            public string href { get; set; }
            public List<Item> items { get; set; }
            public int limit { get; set; }

        }


        //public class playlist
        //{
        //    public string href { get; set; }
        //    public int limit { get; set; }
        //    public List<playlistItems> items { get; set; }
        //    public int total { get; set; }
        //}


        public class PlaylistItem
        {
            public ExternalUrls external_urls { get; set; }
            public string id { get; set; }
            public string name { get; set; }
            public string type { get; set; }
            public List<ImageSP> images { get; set; }

            public Tracks tracks { get; set; }

            public string uri { get; set; }
        }



        public class PlaylistContainer
        {
            public string href { get; set; }
            public List<PlaylistItem> items { get; set; }
            public int total { get; set; }
            public int limit { get; set; }
        }



        public class Tracks
        {
          public string href { get; set; }
          
          public int total { get; set; }



        }

        public class SpotifyResult
        {
            public PlaylistContainer playlists { get; set; }
            public class AddedBy
            {
                public ExternalUrls external_urls { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class Album
            {
                public string album_type { get; set; }
                public List<Artist> artists { get; set; }
                public List<string> available_markets { get; set; }
                public ExternalUrls external_urls { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public List<Image> images { get; set; }
                public string name { get; set; }
                public string release_date { get; set; }
                public string release_date_precision { get; set; }
                public int total_tracks { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class Artist
            {
                public ExternalUrls external_urls { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public string name { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class ExternalIds
            {
                public string isrc { get; set; }
            }

            public class ExternalUrls
            {
                public string spotify { get; set; }
            }

            public class Followers
            {
                public object href { get; set; }
                public int total { get; set; }
            }

            public class Image
            {
                public int height { get; set; }
                public string url { get; set; }
                public int width { get; set; }
            }

            public class Item
            {
                public DateTime added_at { get; set; }
                public AddedBy added_by { get; set; }
                public bool is_local { get; set; }
                public object primary_color { get; set; }
                public Track track { get; set; }
                public VideoThumbnail video_thumbnail { get; set; }
            }

            public class Owner
            {
                public string display_name { get; set; }
                public ExternalUrls external_urls { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class Root
            {
                public bool collaborative { get; set; }
                public string description { get; set; }
                public ExternalUrls external_urls { get; set; }
                public Followers followers { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public List<Image> images { get; set; }
                public string name { get; set; }
                public Owner owner { get; set; }
                public object primary_color { get; set; }
                public bool @public { get; set; }
                public string snapshot_id { get; set; }
                public Tracks tracks { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class Track
            {
                public Album album { get; set; }
                public List<Artist> artists { get; set; }
                public List<string> available_markets { get; set; }
                public int disc_number { get; set; }
                public int duration_ms { get; set; }
                public bool episode { get; set; }
                public bool @explicit { get; set; }
                public ExternalIds external_ids { get; set; }
                public ExternalUrls external_urls { get; set; }
                public string href { get; set; }
                public string id { get; set; }
                public bool is_local { get; set; }
                public string name { get; set; }
                public int popularity { get; set; }
                public string preview_url { get; set; }
                public bool track { get; set; }
                public int track_number { get; set; }
                public string type { get; set; }
                public string uri { get; set; }
            }

            public class Tracks
            {
                public string href { get; set; }
                public List<Item> items { get; set; }
                public int limit { get; set; }
                public object next { get; set; }
                public int offset { get; set; }
                public object previous { get; set; }
                public int total { get; set; }
            }

            public class VideoThumbnail
            {
                public object url { get; set; }
            }

            public class SpotifySearch
            {
                public class ExternalUrls
                {
                    public string spotify { get; set; }
                }

                public class Followers
                {
                    public object href { get; set; }
                    public int total { get; set; }
                }

                public class ImageSP
                {
                    public int width { get; set; }
                    public string url { get; set; }
                    public int height { get; set; }
                }

                public class Item
                {
                    public ExternalUrls external_urls { get; set; }
                    public Followers followers { get; set; }
                    public List<string> genres { get; set; }
                    public string id { get; set; }
                    public List<ImageSP> images { get; set; }
                    public string name { get; set; }
                    public int popularity { get; set; }
                    public string type { get; set; }
                    public string uri { get; set; }

                }

                public class Artists
                {
                    public string href { get; set; }
                    public List<Item> items { get; set; }
                    public int limit { get; set; }

                }

                public class PlaylistItem
                {
                    public ExternalUrls external_urls { get; set; }
                    public string id { get; set; }
                    public string name { get; set; }
                    public string type { get; set; }
                    public List<ImageSP> images { get; set; }

                    public Tracks tracks { get; set; }

                    public string uri { get; set; }
                }

                public class PlaylistContainer
                {
                    public string href { get; set; }
                    public List<PlaylistItem> items { get; set; }
                    public int total { get; set; }
                    public int limit { get; set; }
                }

                public class Tracks
                {
                    public string href { get; set; }
                    public int total { get; set; }
                }

                public class SpotifyResult
                {
                    public PlaylistContainer playlists { get; set; }
                }
            }
        }

    }
}


then when the item is searched it uses
search helper
and this is where it returns nothing
however the responce.Content returns all the values,

search helper
C#
<pre>public static SpotifySearch.SpotifyResult SearchArtistOrSong(string searchword)
        {
            var client = new RestClient("https://api.spotify.com/v1/playlists");
            client.AddDefaultHeader("Authorization", $"Bearer {token.access_token}");
            var request = new RestRequest($"{searchword}", Method.Get); // Corrected here
            var response = client.Execute(request);

            if (response.IsSuccessful)
            {
                var result = JsonConvert.DeserializeObject<SpotifySearch.SpotifyResult>(response.Content);
                return result;
            }
            else
            {
                return null;
            }
        }


and the mainwindow.cs
C#
<pre> private void elfentext_KeyUp(object sender, KeyEventArgs e)
        {

            var result = SearchHelper.SearchArtistOrSong(elfentext.Text);
            if (result == null)
            {
                return;
            }

            var listArtist = new List<SpotifySearch.PlaylistItem>();

            if (result?.playlists?.items != null)
            {
                foreach (var item in result.playlists.items)
                {
                    var images = item.images.Any() ? item.images : new List<SpotifySearch.ImageSP>();
                    listArtist.Add(new SpotifySearch.PlaylistItem()
                    {
                        external_urls = item.external_urls,
                        id = item.id,
                        name = item.name,
                        type = item.type,
                        images = images,
                        tracks = item.tracks,
                        uri = item.uri
                    });
                }
            }

            elfenlist.ItemsSource = listArtist;
        }


i managed to get artist working fine before but just playlist returns so much i just not quite sure what i am doing wrong any help would be so much appreciated

thanks in advance elfenliedtopfan5
AnswerRe: c# Spotify API not returning correctly. Pin
Pete O'Hanlon4-Jun-23 8:42
mvePete O'Hanlon4-Jun-23 8:42 
AnswerRe: c# Spotify API not returning correctly. Pin
jschell5-Jun-23 5:01
jschell5-Jun-23 5:01 
QuestionNeed help please regarding your awesome WPF MultiComboBox project :) Pin
Member 1160463425-May-23 5:21
Member 1160463425-May-23 5:21 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
jeron125-May-23 5:50
jeron125-May-23 5:50 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
Richard Deeming25-May-23 21:28
mveRichard Deeming25-May-23 21:28 
QuestionNavigationControl - Part 3 Pin
Kevin Marois14-May-23 8:01
professionalKevin Marois14-May-23 8:01 
AnswerRe: NavigationControl - Part 3 Pin
Richard Deeming14-May-23 21:40
mveRichard Deeming14-May-23 21:40 
GeneralRe: NavigationControl - Part 3 Pin
Kevin Marois15-May-23 17:14
professionalKevin Marois15-May-23 17:14 
QuestionBubbling Event Question Pin
Kevin Marois9-May-23 14:32
professionalKevin Marois9-May-23 14:32 
AnswerRe: Bubbling Event Question Pin
Gerry Schmitz12-May-23 5:28
mveGerry Schmitz12-May-23 5:28 
GeneralRe: Bubbling Event Question Pin
Kevin Marois12-May-23 5:35
professionalKevin Marois12-May-23 5:35 
GeneralRe: Bubbling Event Question Pin
Gerry Schmitz12-May-23 5:46
mveGerry Schmitz12-May-23 5:46 
GeneralRe: Bubbling Event Question Pin
Kevin Marois12-May-23 6:16
professionalKevin Marois12-May-23 6:16 
AnswerRe: Bubbling Event Question Pin
Kenneth Haugland14-May-23 9:55
mvaKenneth Haugland14-May-23 9:55 
GeneralRe: Bubbling Event Question Pin
Kevin Marois14-May-23 10:40
professionalKevin Marois14-May-23 10:40 
GeneralRe: Bubbling Event Question Pin
Kenneth Haugland14-May-23 11:06
mvaKenneth Haugland14-May-23 11:06 
GeneralRe: Bubbling Event Question Pin
Kevin Marois14-May-23 11:08
professionalKevin Marois14-May-23 11:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.