using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Net; using System.IO; namespace SpotifyAPIv1 { public class Track { public TrackResource track_resource { get; set; } public TrackResource artist_resource { get; set; } public TrackResource album_resource { get; set; } public int length { get; set; } public string track_type { get; set; } /// /// Returns the track name /// /// A String. which is the track name public String GetTrackName() { return track_resource.name; } /// /// Returns the track lenght /// /// A integer, which is the track length public int GetLength() { return length; } /// /// Returns the URI for the album /// /// A String, which is the album URI public String GetAlbumURI() { return album_resource.uri; } /// /// Returns the URI for the track /// /// A String, which is the track URI public String GetTrackURI() { return track_resource.uri; } /// /// Returns the URI for the artist /// /// A String, which is the artist URI public String GetArtistURI() { return artist_resource.uri; } /// /// Returns the albume name /// /// A String, which is the album name public String GetAlbumName() { return album_resource.name; } /// /// Returns the artist name /// /// A String, which is the artist name public String GetArtistName() { return artist_resource.name; } /// /// Returns a URL to the album cover in the provided size /// /// AlbumArtSize (160,320,640) /// A String, which is the URL to the Albumart public String GetAlbumArtURL(AlbumArtSize size) { if (album_resource.uri.Contains("local")) return ""; int albumsize = 0; switch (size) { case AlbumArtSize.SIZE_160: albumsize = 160; break; case AlbumArtSize.SIZE_320: albumsize = 320; break; case AlbumArtSize.SIZE_640: albumsize = 640; break; } String raw = ""; using(WebClient wc = new WebClient()) { wc.Proxy = null; raw = wc.DownloadString("http://open.spotify.com/album/" + album_resource.uri.Split(new string[] { ":" }, StringSplitOptions.None)[2]); } raw = raw.Replace("\t", ""); ; string[] lines = raw.Split(new string[] { "\n" }, StringSplitOptions.None); foreach (string line in lines) { if (line.StartsWith("", ""); } } return ""; } /// /// Returns a Bitmap of the album cover in the provided size asynchronous /// /// AlbumArtSize (160,320,640) /// A Bitmap, which is the albumart public async Task GetAlbumArtAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; String url = GetAlbumArtURL(size); if (url == "") return new Bitmap(640, 640); byte[] data = null; try { data = await wc.DownloadDataTaskAsync(url); } catch(WebException) { throw; } using (MemoryStream ms = new MemoryStream(data)) { return (Bitmap)Image.FromStream(ms); } } } /// /// Returns a Bitmap of the album cover in the provided size /// /// AlbumArtSize (160,320,640) /// A Bitmap, which is the albumart public Bitmap GetAlbumArt(AlbumArtSize size) { using(WebClient wc = new WebClient()) { wc.Proxy = null; String url = GetAlbumArtURL(size); if (url == "") return new Bitmap(640,640); byte[] data = null; try { data = wc.DownloadData(url); } catch (WebException e) { throw; } using (MemoryStream ms = new MemoryStream(data)) { return (Bitmap)Image.FromStream(ms); } } } } public class TrackResource { public String name { get; set; } public String uri { get; set; } public TrackResourceLocation location { get; set; } } public class TrackResourceLocation { public String og { get; set; } } public class OpenGraphState { public Boolean private_session { get; set; } public Boolean posting_disabled { get; set; } } }