コード例 #1
0
ファイル: UserService.cs プロジェクト: rdcarp/last-fm-dot-net
        public IEnumerable<ITrack> GetArtistTracks(IArtist artist, int? page = null, Timestamp startTime = null, Timestamp endTime = null)
        {
            IApiMethod method = this.CreateApiMethod("user.getArtistTracks");

            method.AddParameter("artist", artist.Name);

            if (page.HasValue)
            {
                method.AddParameter("page", page.ToString());
            }
            if (startTime != null)
            {
                method.AddParameter("startTimestamp", startTime.ToString());
            }
            if (endTime != null)
            {
                method.AddParameter("endTimestamp", endTime.ToString());
            }

            var response = method.Execute();

            JArray tracks = (JArray)response["lfm"]["artisttracks"]["track"];

            foreach (var track in tracks)
            {
                yield return new Track { Url = track.Value<string>("url"), Name = track.Value<string>("name") };

            }
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: rdcarp/last-fm-dot-net
        public IPagedList<ITrack> GetRecentTracks(string username, int? limit, int? page, Timestamp start, Timestamp end)
        {
            IApiMethod method = this.CreateApiMethod("user.getRecentTracks");

            method.AddParameter("user", username);

            if (page.HasValue)
            {
                method.AddParameter("page", page.ToString());
            }
            if (start != null)
            {
                method.AddParameter("from", start.GetUnixTimestamp());
            }
            if (start != null)
            {
                method.AddParameter("to", end.GetUnixTimestamp());
            }

            var response = method.Execute();

            var tracks = (JArray)response["recenttracks"]["track"];
            var attributes = response["recenttracks"]["@attr"];

            IPagedList<ITrack> result = new PagedList<ITrack>();
            result.Page = attributes.Value<int>("page");
            result.PerPage = attributes.Value<int>("perPage");
            result.TotalPages = attributes.Value<int>("totalPages");
            result.Total = attributes.Value<int>("total");

            foreach (var track in tracks)
            {
                result.Add(new Track { Url = track.Value<string>("url"), Name = track.Value<string>("name") });
            }

            return result;
        }