namespace CoverSources import System.Xml import System.Drawing import util class Amazon: static AddSizeToImage = true //If true, this will add a caption to the top-left of the image with the size. static AddSizeToLabel = false //If true, this will put the size in the label. Note that this will spoil bold higlighing of exact matches static ThumbSize = Size(150, 150) //Size here should match thumbnail size in CoverDownloader settings for best results static SourceName as string: get: return "Amazon" static SourceVersion as decimal: get: return 0.2 static def GetThumbs(coverart,artist,album): x=System.Xml.XmlDocument() x.Load("http://xml.amazon.com/onca/xml3?f=xml&t=webservices-20&dev-t=1MV23E34ARMVYMBDZB02&type=lite&page=1&mode=music&KeywordSearch="+EncodeUrl(artist+" "+album)) results=x.GetElementsByTagName("Details") coverart.SetCountEstimate(results.Count) for node in results: large = System.Drawing.Bitmap.FromStream(GetPageStream(node["ImageUrlLarge"].InnerText)) if large.Height>10: caption = System.String.Format("{0} x {1}", large.Width, large.Height) //Create the thumbnail. thumb = Bitmap(large, ThumbSize) large.Dispose() //Caption the image if AddSizeToImage: g = Graphics.FromImage(thumb) f = Font(SystemFonts.DefaultFont, FontStyle.Bold) g.DrawString(caption, f, Brushes.White, 1,1 ) g.DrawString(caption, f, Brushes.Black, 0,0 ) f.Dispose() g.Dispose() //Add the size to the label label = node["ProductName"].InnerText if AddSizeToLabel: label = System.String.Format("{0} ({1})", label, caption) coverart.AddThumb(thumb,label,0,0,node["ImageUrlLarge"].InnerText) static def GetResult(param): return param