Skip to content

Commit 8d27416

Browse files
author
Johnny @PC
committed
Tweaked SpotifyURI, moved parsing to a static method
1 parent 8a156ff commit 8d27416

4 files changed

Lines changed: 53 additions & 40 deletions

File tree

‎SpotifyAPI.Example/LocalControl.Designer.cs‎

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎SpotifyAPI.Example/LocalControl.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public async void UpdateTrack(Track track)
9393
albumLinkLabel.Text = track.AlbumResource.Name;
9494
albumLinkLabel.Tag = track.AlbumResource.Uri;
9595

96+
SpotifyUri uri = track.TrackResource.ParseUri();
97+
98+
trackInfoBox.Text = $"Track Info - {uri.Id}";
99+
96100
bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640);
97101
smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
98102
}

‎SpotifyAPI/Local/Models/SpotifyResource.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SpotifyResource
1616

1717
public SpotifyUri ParseUri()
1818
{
19-
return new SpotifyUri(this.Uri);
19+
return SpotifyUri.Parse(Uri);
2020
}
2121
}
2222
}

‎SpotifyAPI/Local/Models/SpotifyUri.cs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@ public class SpotifyUri
1212
public string Type { get; internal set; }
1313
public string Id { get; internal set; }
1414

15-
public SpotifyUri(string uri)
15+
public SpotifyUri(string uriBase, string uriType, string uriId)
16+
{
17+
Base = uriBase;
18+
Type = uriType;
19+
Id = uriId;
20+
}
21+
22+
public static SpotifyUri Parse(string uri)
1623
{
1724
if (String.IsNullOrEmpty(uri))
1825
throw new ArgumentNullException("Uri");
1926

2027
string[] props = uri.Split(':');
21-
2228
if (props.Length != 3)
2329
throw new ArgumentException("Unexpected Uri");
2430

25-
Base = props[0];
26-
Type = props[1];
27-
Id = props[2];
31+
return new SpotifyUri(props[0], props[1], props[2]);
32+
}
33+
34+
public override string ToString()
35+
{
36+
return $"{Base}:{Type}:{Id}";
2837
}
2938
}
3039
}

0 commit comments

Comments
 (0)