Exemplo n.º 1
0
        public static void ParseMostPlayed(string xml)
        {

            XDocument doc = XDocument.Parse(xml);
            XElement x = doc.Root.Element("{http://schemas.zune.net/profiles/2008/01}artists");
            foreach (XElement artist in x.Elements())
            {
                Artist _artist = new Artist();
                _artist.Name = artist.Element("{http://schemas.zune.net/profiles/2008/01}name").Value;
                _artist.ArtistID = artist.Element("{http://schemas.zune.net/profiles/2008/01}id").Value.Remove(0, 9);

                WebClient client = new WebClient();
                client.DownloadStringAsync(new Uri("http://catalog.zune.net/v3.2/en-US/music/artist/" + _artist.ArtistID));
                client.DownloadStringCompleted += (s, e) => HandleArtistDownload(s, e, _artist);    
            }
        }
Exemplo n.º 2
0
        private static void HandleArtistDownload(object sender, DownloadStringCompletedEventArgs e, Artist artist)
        {

            try
            {
                XDocument xdoc = XDocument.Parse(e.Result);
                string imageId = xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}image")
                    .Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0, 9);

                artist.Playcount = "Global plays: " + xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}playCount").Value;
                artist.HasRadio = Convert.ToBoolean(xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}hasRadioChannel").Value);
                artist.Genre = xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}primaryGenre")
                    .Element("{http://schemas.zune.net/catalog/music/2007/10}title").Value;

                BitmapImage image = new BitmapImage(new Uri(string.Format("http://catalog.zune.net/v3.2/image/{0}?width=100&height=100", imageId)));
                artist.ArtistImage = image;
            }
            catch
            {
                artist.ArtistImage = new BitmapImage(new Uri("Images/unknown.png", UriKind.Relative));
            }

            ProfileViewModelLocator.ProfileModel.MostPlayed.Add(artist);
        }