/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public Track(JToken token) { /* Simple Fields */ Disc_Number = token.Value <int?>("disc_number ") ?? 1; Duration_Ms = token.Value <long?>("duration_ms") ?? 0; Explicit = token.Value <bool?>("explicit") ?? false; Href = token.Value <string>("href") ?? string.Empty; Is_Playable = token.Value <bool?>("is_playable") ?? false; Id = token.Value <string>("id") ?? string.Empty; Name = token.Value <string>("name") ?? string.Empty; Popularity = token.Value <int?>("popularity") ?? 0; Preview_Url = token.Value <string>("preview_url") ?? string.Empty; Track_Number = token.Value <int?>("track_number") ?? 1; Uri = token.Value <string>("uri") ?? string.Empty; /*Complex Fields */ /* Available Markets */ JArray markets = token.Value <JArray>("available_markets"); if (markets != null) { this.Available_Markets = markets.Values <string>().ToArray(); } /* Album */ JObject album = token.Value <JObject>("album"); if (album != null) { this.Album = new Album(album); } /* Artists */ JArray artists = token.Value <JArray>("artists"); if (artists != null) { List <Artist> arts = new List <Artist>(); foreach (JObject jobj in artists) { arts.Add(new Artist(jobj)); } Artists = arts.ToArray(); } JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* External Ids */ JObject extids = token.Value <JObject>("external_ids"); if (extids != null) { foreach (JProperty x in extids.Properties()) { External_Ids.Add(x.Name, x.Value <JToken>().ToString()); } } /* Linked From */ JObject linked = token.Value <JObject>("linked_from"); if (linked != null) { Linked_From = new TrackLink(linked); } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public Album(JToken token) { /* simple fields */ Album_Type = token.Value <string>("album_type") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Label = token.Value <string>("label") ?? string.Empty; Name = token.Value <string>("name") ?? string.Empty; Popularity = token.Value <int?>("popularity") ?? 0; Release_Date = token.Value <string>("release_date") ?? string.Empty; Release_Date_Precision = token.Value <string>("release_date_precision") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; /* complex fields */ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* External Ids */ JObject extids = token.Value <JObject>("external_ids"); if (extids != null) { foreach (JProperty x in extids.Properties()) { External_Ids.Add(x.Name, x.Value <JToken>().ToString()); } } /* Images */ JArray images = token.Value <JArray>("images"); if (images != null) { List <Image> ims = new List <Image>(); foreach (JObject jobj in images.Values <JObject>()) { Image i = new Image(jobj); ims.Add(i); } Images = ims.ToArray(); } /* Genres */ JArray genres = token.Value <JArray>("genres"); if (genres != null) { List <string> gens = new List <string>(); foreach (JValue jv in genres) { string s = jv.ToString(); gens.Add(s); } Genres = gens.ToArray(); } /* Copyrights */ JArray copyrights = token.Value <JArray>("copyright"); if (copyrights != null) { List <Copyright> cps = new List <Copyright>(); foreach (JObject jobj in copyrights.Values <JObject>()) { Copyright i = new Copyright(jobj); cps.Add(i); } Copyrights = cps.ToArray(); } /* Available Markets */ JArray markets = token.Value <JArray>("available_markets"); if (markets != null) { this.Available_Markets = markets.Values <string>().ToArray(); } /* Artists */ JArray artists = token.Value <JArray>("artists"); if (artists != null) { List <Artist> arts = new List <Artist>(); foreach (JObject jobj in artists) { arts.Add(new Artist(jobj)); } Artists = arts.ToArray(); } //tracks JToken paging = token.Value <JToken>("tracks"); if (paging != null) { Tracks = new Paging <Track>(paging); } }