Esempio n. 1
0
        public static LastFm ArtistToObject(XElement objRest)
        {
            LastFm objResult = new LastFm();
            var    query     = from item in objRest.Descendants("artist")
                               select item;

            XElement[] nodes = query.ToArray();
            if (nodes.Length > 0)
            {
                XElement objTemp = nodes[0];
                objResult.ArtistName = Util.GetElementValue(objTemp, "name");

                objResult.ArtistId  = Util.GetElementValue(objTemp, "mbid");
                objResult.ArtistUrl = Util.GetElementValue(objTemp, "url");

                objResult.ArtistSmallImage      = Util.GetElementValue(objTemp, "image", "size", "small");
                objResult.ArtistLargeImage      = Util.GetElementValue(objTemp, "image", "size", "large");
                objResult.ArtistExtraLargeImage = Util.GetElementValue(objTemp, "image", "size", "extralarge");
                objResult.ArtistMegaImage       = Util.GetElementValue(objTemp, "image", "size", "mega");
            }

            query = from item in objRest.Descendants("bio")
                    select item;

            nodes = query.ToArray();
            if (nodes.Length > 0)
            {
                XElement objTemp = nodes[0];
                objResult.ArtistDescription = Util.PurgeHtml(Util.GetElementValue(objTemp, "summary"));
                objResult.ArtistContent     = Util.PurgeHtml(Util.GetElementValue(objTemp, "content"));
            }

            return(objResult);
        }
Esempio n. 2
0
        public static IEnumerable <LastFm> AlbumToCollection(XElement objRest)
        {
            if (objRest == null)
            {
                return(null);
            }

            Collection <LastFm> lstResults = new Collection <LastFm>();
            var query = from item in objRest.Descendants("album")
                        select item;

            XElement[] nodes = query.ToArray();
            foreach (XElement node in nodes)
            {
                XElement objTemp = node;
                LastFm   objItem = new LastFm();
                objItem.AlbumName            = Util.GetElementValue(objTemp, "name");
                objItem.ArtistName           = Util.GetElementValue(objTemp, "artist");
                objItem.AlbumUrl             = Util.GetElementValue(objTemp, "url");
                objItem.Id                   = Util.GetElementValue(objTemp, "mbid");
                objItem.AlbumSmallImage      = Util.GetElementValue(objTemp, "image", "size", "small");
                objItem.AlbumLargeImage      = Util.GetElementValue(objTemp, "image", "size", "large");
                objItem.AlbumExtraLargeImage = Util.GetElementValue(objTemp, "image", "size", "extralarge");
                lstResults.Add(objItem);
            }

            return(lstResults);
        }
Esempio n. 3
0
        private static LastFm AlbumToObject(XElement objRest, LastFm objResult)
        {
            var query = from item in objRest.Descendants("album")
                        select item;

            XElement[] nodes = query.ToArray();
            if (nodes.Length > 0)
            {
                XElement objTemp = nodes[0];
                objResult.AlbumName            = Util.GetElementValue(objTemp, "name");
                objResult.ArtistName           = Util.GetElementValue(objTemp, "artist");
                objResult.AlbumUrl             = Util.GetElementValue(objTemp, "url");
                objResult.AlbumReleased        = Util.GetElementValue(objTemp, "releasedate");
                objResult.AlbumSmallImage      = Util.GetElementValue(objTemp, "image", "size", "small");
                objResult.AlbumLargeImage      = Util.GetElementValue(objTemp, "image", "size", "large");
                objResult.AlbumExtraLargeImage = Util.GetElementValue(objTemp, "image", "size", "extralarge");
                objResult.AlbumMegaImage       = Util.GetElementValue(objTemp, "image", "size", "mega");
            }


            query = from item in objRest.Descendants("track")
                    select item;

            nodes = query.ToArray();

            objResult.AlbumDuration = 0;
            objResult.AlbumTracks   = new List <string>();

            foreach (XElement item in nodes)
            {
                objResult.AlbumTracks.Add(Util.GetElementValue(item, "name"));
                int duration;
                if (int.TryParse(Util.GetElementValue(item, "duration"), out duration))
                {
                    objResult.AlbumDuration += duration;
                }
            }

            query = from item in objRest.Descendants("tag")
                    select item;

            nodes = query.ToArray();
            objResult.AlbumTypes = new List <string>();
            foreach (XElement item in nodes)
            {
                string strTemp = Util.GetElementValue(item, "name");
                if (IsBadTag(strTemp) == false)
                {
                    if (strTemp.ToUpper().Contains(objResult.AlbumName.ToUpper()) == false)
                    {
                        if (strTemp.ToUpper().Contains(objResult.ArtistName.ToUpper()) == false)
                        {
                            objResult.AlbumTypes.Add(Util.FirstCharToUpper(strTemp));
                        }
                    }
                }
            }

            query = from item in objRest.Descendants("wiki")
                    select item;

            nodes = query.ToArray();
            if (nodes.Length > 0)
            {
                XElement objTemp = nodes[0];
                objResult.AlbumDescription = Util.PurgeHtml(Util.GetElementValue(objTemp, "summary"));
                objResult.AlbumContent     = Util.PurgeHtml(Util.GetElementValue(objTemp, "content"));
            }

            return(objResult);
        }