@@ -35,10 +35,12 @@ public class Album : IDisposable
3535 private bool disposed = false ;
3636 public string id = "" ;
3737 public string name = "" ;
38+ public string releaseDate = "" ;
3839 public int tracksCount = 1 ;
3940 public List < Artist > artists = new List < Artist > ( ) ;
4041 public BitmapImage image = new BitmapImage ( ) ;
4142 public string imageUrl = "" ;
43+ public string href = "" ;
4244 private const string TRACKS_HREF = "https://api.spotify.com/v1/albums/{0}/tracks" ;
4345
4446 /// <summary>
@@ -78,15 +80,37 @@ public async Task SetInfo(string albumString)
7880 {
7981 return ;
8082 }
81- if ( albumJson . TryGetValue ( "id" , out IJsonValue idJson ) )
83+ if ( albumJson . TryGetValue ( "id" , out IJsonValue idJson ) && idJson . ValueType == JsonValueType . String )
8284 {
8385 id = idJson . GetString ( ) ;
8486 }
85- if ( albumJson . TryGetValue ( "name" , out IJsonValue nameJson ) )
87+ if ( albumJson . TryGetValue ( "name" , out IJsonValue nameJson ) && nameJson . ValueType == JsonValueType . String )
8688 {
8789 name = nameJson . GetString ( ) ;
8890 }
89- if ( albumJson . TryGetValue ( "artists" , out IJsonValue artistsJson ) ) {
91+ if ( albumJson . TryGetValue ( "href" , out IJsonValue hrefJson ) && hrefJson . ValueType == JsonValueType . String )
92+ {
93+ href = hrefJson . GetString ( ) ;
94+
95+ // extra request to get release date
96+ UriBuilder fullUriBuilder = new UriBuilder ( href ) ;
97+ string fullString = await RequestHandler . SendCliGetRequest ( fullUriBuilder . Uri . ToString ( ) ) ;
98+ JsonObject fullJson = new JsonObject ( ) ;
99+ try
100+ {
101+ fullJson = JsonObject . Parse ( fullString ) ;
102+ }
103+ catch ( COMException )
104+ {
105+ return ;
106+ }
107+
108+ if ( fullJson . TryGetValue ( "release_date" , out IJsonValue releaseJson ) && releaseJson . ValueType == JsonValueType . String )
109+ {
110+ releaseDate = releaseJson . GetString ( ) ;
111+ }
112+ }
113+ if ( albumJson . TryGetValue ( "artists" , out IJsonValue artistsJson ) && artistsJson . ValueType == JsonValueType . Array ) {
90114 JsonArray artistsArray = artistsJson . GetArray ( ) ;
91115 foreach ( JsonValue artistObject in artistsArray )
92116 {
@@ -95,7 +119,7 @@ public async Task SetInfo(string albumString)
95119 artists . Add ( artist ) ;
96120 }
97121 }
98- if ( albumJson . TryGetValue ( "images" , out IJsonValue imagesJson ) ) {
122+ if ( albumJson . TryGetValue ( "images" , out IJsonValue imagesJson ) && imagesJson . ValueType == JsonValueType . Array ) {
99123 JsonArray imagesArray = imagesJson . GetArray ( ) ;
100124 if ( imagesArray . Count > 0 )
101125 {
@@ -126,7 +150,7 @@ public async Task SetInfo(string albumString)
126150 return ;
127151 }
128152
129- if ( tracksJson . TryGetValue ( "total" , out IJsonValue totalJson ) )
153+ if ( tracksJson . TryGetValue ( "total" , out IJsonValue totalJson ) && totalJson . ValueType == JsonValueType . Number )
130154 {
131155 tracksCount = Convert . ToInt32 ( totalJson . GetNumber ( ) ) ;
132156 }
@@ -149,7 +173,7 @@ public async Task<List<Track>> GetTracks()
149173 {
150174 return tracks ;
151175 }
152- if ( tracksJson . TryGetValue ( "items" , out IJsonValue itemsJson ) )
176+ if ( tracksJson . TryGetValue ( "items" , out IJsonValue itemsJson ) && itemsJson . ValueType == JsonValueType . Array )
153177 {
154178 JsonArray itemsArray = itemsJson . GetArray ( ) ;
155179 foreach ( JsonValue trackJson in itemsArray )
@@ -186,20 +210,15 @@ protected virtual void Dispose(bool disposing)
186210 disposed = true ;
187211 if ( disposing )
188212 {
189- id = null ;
190- name = null ;
191213 while ( artists . Count > 0 )
192214 {
193215 Artist artist = artists . ElementAt ( 0 ) ;
194216 artists . Remove ( artist ) ;
195217 artist . Dispose ( ) ;
196- artist = null ;
197218 }
198219 artists . Clear ( ) ;
199- artists = null ;
200- image . UriSource = null ;
201- image = null ;
202- imageUrl = null ;
220+
221+ image . ClearValue ( BitmapImage . UriSourceProperty ) ;
203222 }
204223 }
205224 }
0 commit comments