Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var match = Regex.Match(word, @"http:\/\/open.spotify.com\/track\/([\w]+)");
- if (match.Success)
- {
- if (linksPerLine.Contains(word))
- continue;
- linksPerLine.Add(word);
- var httpRequest = (HttpWebRequest)WebRequest.Create(string.Format("http://ws.spotify.com/lookup/1/?uri={0}", word));
- httpRequest.Method = "GET";
- httpRequest.KeepAlive = false;
- httpRequest.ContentType = "text/xml";
- using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
- {
- var enc = System.Text.Encoding.UTF8;
- using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), enc))
- {
- var response = streamReader.ReadToEnd();
- var spotifyXML = new XmlDocument();
- spotifyXML.LoadXml(response);
- var trackRoot = spotifyXML.SelectSingleNode("track");
- var name = trackRoot.SelectSingleNode("name").InnerText;
- var artist = trackRoot.SelectSingleNode("artist").SelectSingleNode("name").InnerText;
- var album = trackRoot.SelectSingleNode("album").SelectSingleNode("name").InnerText;
- var length = trackRoot.SelectSingleNode("length").InnerText;
- var popularity = Math.Round(double.Parse(trackRoot.SelectSingleNode("popularity").InnerText) * 100, 0).ToString() + "%";
- var ircResponse = string.Format("{0}: {1} - {2} ({3}} | {4} | {5} popular", word, name, artist, album, length, popularity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment