From 3f3ceeae5e73881708e17594a0d59c741f6e8e0a Mon Sep 17 00:00:00 2001 From: Marcel Welna <69851263+mx2rel@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:47:12 +0200 Subject: [PATCH] Add NowPlaying status, UserPlayCount and UserLoved (#9) --- src/Hqub.Lastfm/Entities/Track.cs | 15 +++++++++++++++ src/Hqub.Lastfm/ResponseParser.cs | 14 +++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Hqub.Lastfm/Entities/Track.cs b/src/Hqub.Lastfm/Entities/Track.cs index b6dba6a..b4a6f3b 100644 --- a/src/Hqub.Lastfm/Entities/Track.cs +++ b/src/Hqub.Lastfm/Entities/Track.cs @@ -83,6 +83,21 @@ public class Track /// public Statistics Statistics { get; set; } + /// + /// Gets or sets user playcount (available only with track.getInfo). + /// + public int UserPlayCount { get; set; } + + /// + /// Gets or sets user loved status (available only with track.getInfo). + /// + public bool UserLoved { get; set; } + + /// + /// Gets or sets now playing status (available only for users, i.e. user.getRecentTracks). + /// + public bool NowPlaying { get; internal set; } + #endregion } } diff --git a/src/Hqub.Lastfm/ResponseParser.cs b/src/Hqub.Lastfm/ResponseParser.cs index 4d3fec8..5d8549f 100644 --- a/src/Hqub.Lastfm/ResponseParser.cs +++ b/src/Hqub.Lastfm/ResponseParser.cs @@ -613,9 +613,7 @@ private Track ParseTrack(XElement node) if ((a = node.Attribute("nowplaying")) != null) { - // TODO: nowplaying - - //track.NowPlaying = a.Value.Equals("true", StringComparison.OrdinalIgnoreCase); + track.NowPlaying = a.Value.Equals("true", StringComparison.OrdinalIgnoreCase); } if ((e = node.Element("date")) != null) @@ -681,6 +679,16 @@ private Track ParseTrack(XElement node) track.Wiki = ParseWiki(e); } + if ((e = node.Element("userplaycount")) != null) + { + track.UserPlayCount = int.Parse(e.Value); + } + + if ((e = node.Element("userloved")) != null) + { + track.UserLoved = int.Parse(e.Value) == 1; + } + track.Images = ParseImages(node.Elements("image")); return track;