Пример #1
0
        public LastFMAlbum(XDocument xDoc)
        {
            if (xDoc.Root == null)
            {
                return;
            }
            var albumElement = xDoc.Root.Element("album");

            if (albumElement == null)
            {
                return;
            }

            MusicBrainzId = (string)albumElement.Element("mbid");
            AlbumName     = (string)albumElement.Element("name");
            ArtistName    = (string)albumElement.Element("artist");
            AlbumURL      = (string)albumElement.Element("url");
            Listeners     = (int)albumElement.Element("listeners");
            Playcount     = (int)albumElement.Element("playcount");

            Images = (from i in albumElement.Elements("image")
                      select new LastFMImage(
                          LastFMImage.GetImageSizeEnum((string)i.Attribute("size")),
                          (string)i
                          )).ToList();

            Tags = (from tagElement in xDoc.Descendants("toptags").Elements("tag")
                    let tagName = (string)tagElement.Element("name")
                                  let tagURL = (string)tagElement.Element("url")
                                               select new LastFMTag(tagName, tagURL)
                    ).ToList();

            Tracks = (from trackElement in xDoc.Descendants("tracks").Elements("track")
                      let trackName = (string)trackElement.Element("name")
                                      let duration = (int)trackElement.Element("duration")
                                                     let trackURL = (string)trackElement.Element("url")
                                                                    select
                                                                    new LastFMTrackBase
            {
                ArtistName = ArtistName,        // response does not include artists per track so pull from album
                Duration = duration,
                TrackTitle = trackName,
                TrackURL = trackURL
            }
                      ).ToList();
        }
Пример #2
0
        public LastFMTrackInfo(XDocument xDoc)
        {
            if (xDoc.Root == null)
            {
                return;
            }
            var track = xDoc.Root.Element("track");

            if (track == null)
            {
                return;
            }

            Identifier    = (int)track.Element("id");
            TrackTitle    = (string)track.Element("name");
            MusicBrainzId = (string)track.Element("mbid");
            TrackURL      = (string)track.Element("url");
            Duration      = (int)track.Element("duration");
            Listeners     = (int)track.Element("listeners");
            Playcount     = (int)track.Element("playcount");

            var artistElement = track.Element("artist");

            if (artistElement != null)
            {
                ArtistName = (string)artistElement.Element("name");
            }

            TopTags = (from tagElement in track.Descendants("tag")
                       let tagName = (string)tagElement.Element("name")
                                     let tagURL = (string)tagElement.Element("url")
                                                  select new LastFMTag(tagName, tagURL)
                       ).ToList();

            var albumElement = track.Element("album");

            if (albumElement != null)
            {
                Images = (from i in albumElement.Elements("image")
                          select new LastFMImage(
                              LastFMImage.GetImageSizeEnum((string)i.Attribute("size")),
                              (string)i
                              )
                          ).ToList();
            }
        }
Пример #3
0
        public static List <LastFMSimilarTrack> GetSimilarTracks(XDocument xDoc)
        {
            var ci = new CultureInfo("en-GB");

            if (xDoc != null)
            {
                var tracks = (from t in xDoc.Descendants("track")
                              let trackName = (string)t.Element("name")
                                              let playcount = (string)t.Element("playcount")
                                                              let mbid = (string)t.Element("mbid")
                                                                         let duration = (string)t.Element("duration")
                                                                                        let match = (string)t.Element("match")
                                                                                                    let trackURL = (string)t.Element("url")
                                                                                                                   let artistElement = t.Element("artist")
                                                                                                                                       where artistElement != null
                                                                                                                                       let artistName = (string)artistElement.Element("name")
                                                                                                                                                        let images = (
                                  from i in t.Elements("image")
                                  select new LastFMImage(
                                      LastFMImage.GetImageSizeEnum((string)i.Attribute("size")),
                                      (string)i
                                      )
                                  ).ToList()
                                                                                                                                                                     select new LastFMSimilarTrack
                {
                    TrackTitle = trackName,
                    Playcount = string.IsNullOrEmpty(playcount) ? 0 : int.Parse(playcount, ci),
                    MusicBrainzId = mbid,
                    Duration = string.IsNullOrEmpty(duration) ? 0 : int.Parse(duration, ci),
                    Match = string.IsNullOrEmpty(match) ? 0 : float.Parse(match, ci),
                    TrackURL = trackURL,
                    ArtistName = artistName,
                    Images = images
                }
                              ).ToList();
                return(tracks);
            }
            return(null);
        }
Пример #4
0
        }                              //TODO: last.fm have truncated this to 300 chars due to miuse.   Not sure this is worth it now

        /// <summary>
        /// CTOR based on xml returned by last.fm
        /// </summary>
        /// <param name="xDoc">xml returned by last.fm</param>
        public LastFMFullArtist(XDocument xDoc)
        {
            if (xDoc.Root == null)
            {
                return;
            }
            var artistElement = xDoc.Root.Element("artist");

            if (artistElement == null)
            {
                return;
            }

            MusicBrainzId = (string)artistElement.Element("mbid");
            ArtistName    = (string)artistElement.Element("name");
            ArtistURL     = (string)artistElement.Element("url");


            Images = (from i in artistElement.Elements("image")
                      select new LastFMImage(
                          LastFMImage.GetImageSizeEnum((string)i.Attribute("size")),
                          (string)i
                          )).ToList();


            var stats = artistElement.Element("stats");

            if (stats != null)
            {
                Listeners = (int)stats.Element("listeners");
                Playcount = (int)stats.Element("playcount");
            }

            SimilarArtists = (from similarArtistElement in xDoc.Descendants("similar").Elements("artist")
                              let artistName = (string)similarArtistElement.Element("name")
                                               let artistURL = (string)similarArtistElement.Element("url")
                                                               let artistImages = (
                                  from i in similarArtistElement.Elements("image")
                                  select new LastFMImage(
                                      LastFMImage.GetImageSizeEnum((string)i.Attribute("size")),
                                      (string)i
                                      )
                                  ).ToList()
                                                                                  select new LastFMArtist {
                ArtistName = artistName, ArtistURL = artistURL, Images = artistImages
            })
                             .ToList();

            Tags = (from tagElement in xDoc.Descendants("tags").Elements("tag")
                    let tagName = (string)tagElement.Element("name")
                                  let tagURL = (string)tagElement.Element("url")
                                               select new LastFMTag(tagName, tagURL)
                    ).ToList();

            BandMembers = (from memberElement in xDoc.Descendants("bandmembers").Elements("member")
                           let memberName = (string)memberElement.Element("name")
                                            let yearFrom = (string)memberElement.Element("yearfrom")
                                                           let yearTo = (string)memberElement.Element("yearto")
                                                                        select new LastFMBandMember(memberName, yearFrom, yearTo)
                           ).ToList();
        }