/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A String, which is the URL to the Albumart</returns> 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.Trim().StartsWith("<meta property=\"og:image\"")) { string[] l = line.Split(new string[] { "/" }, StringSplitOptions.None); return "http://o.scdn.co/" + albumsize + @"/" + l[4].Replace("\"", "").Replace(">", ""); } } return ""; }
/// <summary> /// Returns a Bitmap of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> 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)); } } }
/// <summary> /// Returns a byte[] of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A byte[], which is the albumart in binary data</returns> public byte[] GetAlbumArtAsByteArray(AlbumArtSize size) { using (WebClient wc = new WebClient()) { string url = GetAlbumArtUrl(size); if (string.IsNullOrEmpty(url)) { return(null); } return(wc.DownloadData(url)); } }
/// <summary> /// Returns a byte[] of the the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A byte[], which is the albumart in binary data</returns> public Task <byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { string url = GetAlbumArtUrl(size); if (url == "") { return(null); } return(wc.DownloadDataTaskAsync(url)); } }
private string GetSizeAsString(AlbumArtSize albumArtSize) { switch (albumArtSize) { case AlbumArtSize.Size160: return("160"); case AlbumArtSize.Size320: return("320"); case AlbumArtSize.Size640: return("640"); } return("0"); }
/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A String, which is the URL to the Albumart</returns> public string GetAlbumArtUrl(AlbumArtSize size) { if (AlbumResource.Uri == null || !AlbumResource.Uri.Contains("spotify:album:") || AlbumResource.Uri.Contains("spotify:album:0000000000000000000000")) { return(""); } int albumsize = 0; switch (size) { case AlbumArtSize.Size160: albumsize = 160; break; case AlbumArtSize.Size320: albumsize = 320; break; case AlbumArtSize.Size640: albumsize = 640; break; } string raw; using (WebClient wc = new WebClient()) { wc.Proxy = null; raw = wc.DownloadString("http://open.spotify.com/album/" + AlbumResource.Uri.Split(new[] { ":" }, StringSplitOptions.None)[2]); } raw = raw.Replace("\t", ""); // < meta property = "og:image" content = "http://o.scdn.co/cover/12b318ffe0e4c92f9b4e1486e4726a57e6437ca7" > // Spotify changed the response so I am now getting the substring from the first line that parses out the above tag. string[] lines = raw.Split(new[] { "\n" }, StringSplitOptions.None); string startString = "<meta property=\"og:image\""; string endString = "\">"; foreach (string line in lines) { if (line.Trim().Contains("<meta property=\"og:image\"")) { int start = line.IndexOf(startString, 0) + startString.Length; int end = line.IndexOf(endString, start); string content = line.Substring(start, end - start); string[] l = content.Split(new[] { "/" }, StringSplitOptions.None); return("http://o.scdn.co/" + albumsize + @"/" + l[4].Replace("\"", "").Replace(">", "")); } } return(""); }
/// <summary> /// Returns a Bitmap of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <param name="proxyConfig">Optional proxy settings</param> /// <returns>A Bitmap, which is the albumart</returns> public Bitmap GetAlbumArt(AlbumArtSize size, ProxyConfig proxyConfig = null) { var data = GetAlbumArtAsByteArray(size, proxyConfig); if (data != null) { using (MemoryStream ms = new MemoryStream(data)) { return((Bitmap)Image.FromStream(ms)); } } return(null); }
private string GetPathToFileInCache(AlbumArtSize albumArtSize, string albumUrlId) { var appDataDir = Utils.GetAppDataPath(); var cacheDirectory = Path.Combine(appDataDir, "cache"); if (!Directory.Exists(cacheDirectory)) { Directory.CreateDirectory(cacheDirectory); } var fileName = albumUrlId + "-" + GetSizeAsString(albumArtSize) + ".jpg"; var imageFilePath = Path.Combine(cacheDirectory, fileName); return(imageFilePath); }
/// <summary> /// Returns a Bitmap of the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <param name="proxyConfig">Optional proxy settings</param> /// <returns>A Bitmap, which is the albumart</returns> public async Task <Bitmap> GetAlbumArtAsync(AlbumArtSize size, ProxyConfig proxyConfig = null) { var data = await GetAlbumArtAsByteArrayAsync(size, proxyConfig).ConfigureAwait(false); if (data != null) { using (MemoryStream ms = new MemoryStream(data)) { return((Bitmap)Image.FromStream(ms)); } } return(null); }
private string GetAlbumArtUrl(AlbumArtSize size, IWebProxy proxy = null) { if (AlbumResource.Uri == null || !AlbumResource.Uri.Contains("spotify:album:") || AlbumResource.Uri.Contains("spotify:album:0000000000000000000000")) { return(""); } int albumsize = 0; switch (size) { case AlbumArtSize.Size160: albumsize = 160; break; case AlbumArtSize.Size320: albumsize = 320; break; case AlbumArtSize.Size640: albumsize = 640; break; } string raw; using (WebClient wc = new WebClient()) { wc.Proxy = proxy; wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); raw = wc.DownloadString("http://open.spotify.com/album/" + AlbumResource.Uri.Split(new[] { ":" }, StringSplitOptions.None)[2]); } raw = raw.Replace("\t", ""); // <img id="cover-img" src="https://d3rt1990lpmkn.cloudfront.net/640/e62a04cfea4122961f3b9159493730c27d61f71b" ... string[] lines = raw.Split(new[] { "\n" }, StringSplitOptions.None); const string pattern = "id=\"cover-img\".*?src=\"(.*?)\""; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); foreach (string line in lines) { MatchCollection matches = rgx.Matches(line); if (matches.Count > 0) { string content = matches[0].Groups[1].Value; string[] l = content.Split(new[] { "/" }, StringSplitOptions.None); return("http://o.scdn.co/" + albumsize + @"/" + l[4]); } } return(""); }
/// <summary> /// Returns a byte[] of the the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <param name="proxyConfig">Optional proxy settings</param> /// <returns>A byte[], which is the albumart in binary data</returns> public Task <byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size, ProxyConfig proxyConfig = null) { using (WebClient wc = new WebClient()) { IWebProxy proxy = proxyConfig?.CreateWebProxy(); wc.Proxy = proxy; string url = GetAlbumArtUrl(size, proxy); if (url == "") { return(null); } return(wc.DownloadDataTaskAsync(url)); } }
/// <summary> /// Returns a Bitmap of the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> public async Task<Bitmap> GetAlbumArtAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; String url = GetAlbumArtUrl(size); if (url == "") return null; var data = await wc.DownloadDataTaskAsync(url); using (MemoryStream ms = new MemoryStream(data)) { return (Bitmap)Image.FromStream(ms); } } }
/// <summary> /// Returns a byte[] of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <param name="proxyConfig">Optional proxy settings</param> /// <returns>A byte[], which is the albumart in binary data</returns> public byte[] GetAlbumArtAsByteArray(AlbumArtSize size, ProxyConfig proxyConfig = null) { using (WebClient wc = new WebClient()) { IWebProxy proxy = proxyConfig?.CreateWebProxy(); wc.Proxy = proxy; string url = GetAlbumArtUrl(size, proxy); if (string.IsNullOrEmpty(url)) { return(null); } return(wc.DownloadData(url)); } }
/// <summary> /// Returns a Bitmap of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> public Bitmap GetAlbumArt(AlbumArtSize size) { using (WebClient wc = new WebClient()) { string url = GetAlbumArtUrl(size); if (string.IsNullOrEmpty(url)) { return(null); } var data = wc.DownloadData(url); using (MemoryStream ms = new MemoryStream(data)) { return((Bitmap)Image.FromStream(ms)); } } }
public override int GetHashCode() { var hash = 13; var hashFactor = 7; hash = Id.GetHashCode(hash, hashFactor); hash = Artist.GetHashCode(hash, hashFactor); hash = Genre.GetHashCode(hash, hashFactor); hash = hash * hashFactor + Year.GetHashCode(); hash = hash * hashFactor + Rating.GetHashCode(); hash = hash * hashFactor + Starred.GetHashCode(); hash = hash * hashFactor + AlbumArtSize.GetHashCode(); hash = CoverArt.GetHashCode(hash, hashFactor); hash = hash * hashFactor + Child.GetHashCode(); return(hash); }
/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A String, which is the URL to the Albumart</returns> public string GetAlbumArtUrl(AlbumArtSize size) { if (AlbumResource.Uri == null || !AlbumResource.Uri.Contains("spotify:album:") || AlbumResource.Uri.Contains("spotify:album:0000000000000000000000")) return ""; int albumsize = 0; switch (size) { case AlbumArtSize.Size160: albumsize = 160; break; case AlbumArtSize.Size320: albumsize = 320; break; case AlbumArtSize.Size640: albumsize = 640; break; } string raw; using (WebClient wc = new WebClient()) { wc.Proxy = null; raw = wc.DownloadString("http://open.spotify.com/album/" + AlbumResource.Uri.Split(new[] { ":" }, StringSplitOptions.None)[2]); } raw = raw.Replace("\t", ""); // < meta property = "og:image" content = "http://o.scdn.co/cover/12b318ffe0e4c92f9b4e1486e4726a57e6437ca7" > // Spotify changed the response so I am now getting the substring from the first line that parses out the above tag. string[] lines = raw.Split(new[] { "\n" }, StringSplitOptions.None); string startString = "<meta property=\"og:image\""; string endString = "\">"; foreach (string line in lines) { if (line.Trim().Contains("<meta property=\"og:image\"")) { int start = line.IndexOf(startString, 0) + startString.Length; int end = line.IndexOf(endString, start); string content = line.Substring(start, end - start); string[] l = content.Split(new[] { "/" }, StringSplitOptions.None); return "http://o.scdn.co/" + albumsize + @"/" + l[4].Replace("\"", "").Replace(">", ""); } } return ""; }
/// <summary> /// Returns a Bitmap of the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> public async Task <Bitmap> GetAlbumArtAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { string url = GetAlbumArtUrl(size); if (url == "") { return(null); } var data = await wc.DownloadDataTaskAsync(url).ConfigureAwait(false); using (MemoryStream ms = new MemoryStream(data)) { return((Bitmap)Image.FromStream(ms)); } } }
public string GetCoverArtUrl(AlbumArtSize size) { string url = string.Empty; try { if (this.spotifyTrack?.AlbumResource != null) { url = this.spotifyTrack.GetAlbumArtUrl(size, App.ProxyConfig.ProxyConfig); } } catch (Exception e) { logger.Error("Error while getting album art url", e); } return(url); }
/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A String, which is the URL to the Albumart</returns> public String GetAlbumArtUrl(AlbumArtSize size) { if (AlbumResource.Uri == null || !AlbumResource.Uri.Contains("spotify:album:") || AlbumResource.Uri.Contains("spotify:album:0000000000000000000000")) { return(""); } int albumsize = 0; switch (size) { case AlbumArtSize.Size160: albumsize = 160; break; case AlbumArtSize.Size320: albumsize = 320; break; case AlbumArtSize.Size640: albumsize = 640; break; } String raw; using (WebClient wc = new WebClient()) { wc.Proxy = null; raw = wc.DownloadString("http://open.spotify.com/album/" + AlbumResource.Uri.Split(new[] { ":" }, StringSplitOptions.None)[2]); } raw = raw.Replace("\t", ""); string[] lines = raw.Split(new[] { "\n" }, StringSplitOptions.None); foreach (string line in lines) { if (line.Trim().StartsWith("<meta property=\"og:image\"")) { string[] l = line.Split(new[] { "/" }, StringSplitOptions.None); return("http://o.scdn.co/" + albumsize + @"/" + l[4].Replace("\"", "").Replace(">", "")); } } return(""); }
/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A String, which is the URL to the Albumart</returns> 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("<meta property=\"og:image\"")) { string[] l = line.Split(new string[] { "/" }, StringSplitOptions.None); return("http://o.scdn.co/" + albumsize + @"/" + l[4].Replace("\"", "").Replace(">", "")); } } return(""); }
public Task <Bitmap> GetAlbumArtAsync(AlbumArtSize size) { return(localApi.GetStatus().Track.GetAlbumArtAsync(size)); }
/// <summary> /// Returns a byte[] of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A byte[], which is the albumart in binary data</returns> public byte[] GetAlbumArtAsByteArray(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; string url = GetAlbumArtUrl(size); if (string.IsNullOrEmpty(url)) return null; return wc.DownloadData(url); } }
/// <summary> /// Returns a Bitmap of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> public Bitmap GetAlbumArt(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; string url = GetAlbumArtUrl(size); if (string.IsNullOrEmpty(url)) return null; var data = wc.DownloadData(url); using (MemoryStream ms = new MemoryStream(data)) { return (Bitmap)Image.FromStream(ms); } } }
/// <summary> /// Returns a byte[] of the the album cover in the provided size asynchronous /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A byte[], which is the albumart in binary data</returns> public Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; string url = GetAlbumArtUrl(size); if (url == "") return null; return wc.DownloadDataTaskAsync(url); } }
/// <summary> /// Returns a Bitmap of the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <returns>A Bitmap, which is the albumart</returns> 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); } } }
/// <summary> /// Returns a URL to the album cover in the provided size /// </summary> /// <param name="size">AlbumArtSize (160,320,640)</param> /// <param name="proxyConfig">Optional proxy settings</param> /// <returns>A String, which is the URL to the Albumart</returns> public string GetAlbumArtUrl(AlbumArtSize size, ProxyConfig proxyConfig = null) { return(GetAlbumArtUrl(size, proxyConfig?.CreateWebProxy())); }
public Bitmap AlbumArt(AlbumArtSize size) { return(_spotify.GetStatus().Track.GetAlbumArt(size)); }
/// <summary> /// Downloads the album art. /// </summary> /// <param name="size">The size of the album art.</param> /// <returns>The album art.</returns> public Image DownloadAlbumArt(AlbumArtSize size) { using (WebClient client = new WebClient() { Proxy = null }) { string source = client.DownloadString(string.Format("http://open.spotify.com/album/{0}", this.AlbumResource.InternalUri.AbsolutePath.Split(':')[1])).Replace("\t", string.Empty); foreach (string line in source.Split('\r', '\n')) { if (line.StartsWith("<meta property=\"og:image\"")) { byte[] image = client.DownloadData(line.Split('"')[3].Replace("image", ((int)size).ToString())); using (MemoryStream stream = new MemoryStream(image)) { return Image.FromStream(stream); } } } } return null; }