示例#1
0
        private static Artist ParseArtist(string artistName)
        {
            try
            {
                bool   isNew;
                Artist artist = ArtistServices.Get(artistName, out isNew);
                if (artist == null)
                {
                    artist = new Artist();
                }

                Uri      strUrl       = new Uri(string.Format(@"http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=7e1cb1060b6150e4fbb60e119250f54c&artist={0}&autocorrect=1", artistName));
                XElement restResponse = XElement.Parse(Util.GetRest(strUrl));

                LastFm objLastFm = LastFm.ArtistToObject(restResponse);

                artist.Bio       = objLastFm.ArtistContent;
                artist.FulleName = objLastFm.ArtistName;

                if (objLastFm.ArtistExtraLargeImage != null)
                {
                    artist.Picture = Util.GetImage(objLastFm.ArtistLargeImage);
                }

                artist.WebSite = objLastFm.ArtistUrl;

                strUrl       = new Uri(string.Format(@"http://ws.audioscrobbler.com/2.0/?method=artist.getTopAlbums&api_key=7e1cb1060b6150e4fbb60e119250f54c&mbid={0}&limit=500", objLastFm.ArtistId));
                restResponse = XElement.Parse(Util.GetRest(strUrl));
                IEnumerable <LastFm> credits = LastFm.AlbumToCollection(restResponse);

                if (credits != null && artist.ArtistCredits != null)
                {
                    foreach (LastFm item in credits)
                    {
                        if (artist.ArtistCredits.Any(x => x.Title.Trim().ToUpper() == item.AlbumName.Trim().ToUpper()) == false)
                        {
                            ArtistCredits artistcredit = new ArtistCredits();
                            artistcredit.ArtistId   = artist.Id;
                            artistcredit.BuyLink    = item.AlbumUrl;
                            artistcredit.Title      = item.AlbumName;
                            artistcredit.EntityType = EntityType.Music;

                            artist.ArtistCredits.Add(artistcredit);
                        }
                    }
                }
                return(artist);
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                return(null);
            }
        }