Hello, Alex!
I created Gracenote script
import System
import System.Xml
import System.Xml.Linq
import AlbumArtDownloader.Scripts
import util
class Gracenote(AlbumArtDownloader.Scripts.IScript):
Name as string:
get: return "Gracenote"
Version as string:
get: return "0.1"
Author as string:
get: return "VKP"
protected gnClientID as string:
get: return "XXXXXXX-XXXXXXXXXXXXXXXXXXX" //Please replace this with yours.
protected gnUserID as string:
get: return "XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXX" //Please replace this with yours.
protected gnUrl as string:
get: return "https://c" + gnClientID.Substring(0, 7) + ".web.cddbp.net/webapi/xml/1.0/"
protected coverSizeSearchPattern as string:
get: return "XLARGE,LARGE,MEDIUM,SMALL,THUMBNAIL"
def Search(artist as string, album as string, results as IScriptResults):
resXml = System.Xml.XmlDocument()
//Search Artist Image
reqXml = CreateSearchAlbumXml(artist, album, "SINGLE_BEST_COVER", "ARTIST_IMAGE")
try:
resXml.Load(GetResultXmlStream(reqXml))
imageUrlNode = resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM/URL[@TYPE='ARTIST_IMAGE']")
imageUrl = imageUrlNode.InnerText
albumArtistNode = resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM/ARTIST")
try:
width = System.Int32.Parse(imageUrlNode.Attributes["WIDTH"].Value)
height = System.Int32.Parse(imageUrlNode.Attributes["HEIGHT"].Value)
except e:
width = -1
height = -1
results.Add(imageUrl, albumArtistNode.InnerText, imageUrl, width, height, imageUrl)
results.EstimatedCount = 1
except e:
results.EstimatedCount = 0
//Search Cover Art
reqXml = CreateSearchAlbumXml(artist, album, "", "COVER")
try:
resXml.Load(GetResultXmlStream(reqXml))
albumNodes as System.Xml.XmlNodeList = resXml.SelectNodes("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM")
results.EstimatedCount += System.Int32.Parse(resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/RANGE/END").InnerText)
except e:
return
for albumNode as System.Xml.XmlNode in albumNodes:
try:
gnID = albumNode["GN_ID"].InnerText
reqXml = CreateFetchAlbumXml(gnID, "SINGLE_BEST_COVER", "COVER")
resXml.Load(GetResultXmlStream(reqXml))
imageUrlNode = resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM/URL[@TYPE='COVERART']")
imageUrl = imageUrlNode.InnerText
albumArtistNode = resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM/ARTIST")
albumTitleNode = resXml.SelectSingleNode("/RESPONSES/RESPONSE[@STATUS='OK']/ALBUM/TITLE")
title = albumArtistNode.InnerText + " - " + albumTitleNode.InnerText
try:
width = System.Int32.Parse(imageUrlNode.Attributes["WIDTH"].Value)
height = System.Int32.Parse(imageUrlNode.Attributes["HEIGHT"].Value)
except e:
width = -1
height = -1
results.Add(imageUrl, title , imageUrl, width, height, imageUrl, CoverType.Front)
except e:
continue
def RetrieveFullSizeImage(fullSizeCallbackParameter):
return fullSizeCallbackParameter
def CreateSearchAlbumXml(artist as string, album as string, mode as string, coverType as string):
xml = System.Xml.Linq.XElement("QUERIES",
System.Xml.Linq.XElement("AUTH",
System.Xml.Linq.XElement("CLIENT", gnClientID),
System.Xml.Linq.XElement("USER", gnUserID)
),
System.Xml.Linq.XElement("QUERY", System.Xml.Linq.XAttribute("CMD", "ALBUM_SEARCH"),
System.Xml.Linq.XElement("MODE", mode),
System.Xml.Linq.XElement("TEXT", System.Xml.Linq.XAttribute("TYPE", "ARTIST"), artist),
System.Xml.Linq.XElement("TEXT", System.Xml.Linq.XAttribute("TYPE", "ALBUM_TITLE"), album),
System.Xml.Linq.XElement("OPTION",
System.Xml.Linq.XElement("PARAMETER", "SELECT_EXTENDED"),
System.Xml.Linq.XElement("VALUE", coverType)
),
System.Xml.Linq.XElement("OPTION",
System.Xml.Linq.XElement("PARAMETER", "COVER_SIZE"),
System.Xml.Linq.XElement("VALUE", coverSizeSearchPattern)
)
)
)
return xml
def CreateFetchAlbumXml(gnID as string, mode as string, coverType as string):
xml = System.Xml.Linq.XElement("QUERIES",
System.Xml.Linq.XElement("AUTH",
System.Xml.Linq.XElement("CLIENT", gnClientID),
System.Xml.Linq.XElement("USER", gnUserID)
),
System.Xml.Linq.XElement("QUERY", System.Xml.Linq.XAttribute("CMD", "ALBUM_FETCH"),
System.Xml.Linq.XElement("MODE", mode),
System.Xml.Linq.XElement("GN_ID", gnID),
System.Xml.Linq.XElement("OPTION",
System.Xml.Linq.XElement("PARAMETER", "SELECT_EXTENDED"),
System.Xml.Linq.XElement("VALUE", coverType)
),
System.Xml.Linq.XElement("OPTION",
System.Xml.Linq.XElement("PARAMETER", "COVER_SIZE"),
System.Xml.Linq.XElement("VALUE", coverSizeSearchPattern)
)
)
)
return xml
def GetResultXmlStream(reqXml as System.Xml.Linq.XElement):
postData = Encoding.UTF8.GetBytes(reqXml.ToString());
req = System.Net.HttpWebRequest.Create(gnUrl);
req.Method = "POST";
req.ContentType = "text/xml; encoding='utf-8'";
req.ContentLength = postData.Length;
reqStream = req.GetRequestStream();
reqStream.Write(postData, 0, postData.Length);
reqStream.Close();
res = req.GetResponse();
resStream = res.GetResponseStream();
return resStream
Please replace gnClientID and gnUserID with yours.
Thanks