Skip to content

Commit

Permalink
Add NowPlaying status, UserPlayCount and UserLoved (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mx2rel authored Jul 22, 2024
1 parent 7cefe95 commit 3f3ceea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Hqub.Lastfm/Entities/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public class Track
/// </summary>
public Statistics Statistics { get; set; }

/// <summary>
/// Gets or sets user playcount (available only with track.getInfo).
/// </summary>
public int UserPlayCount { get; set; }

/// <summary>
/// Gets or sets user loved status (available only with track.getInfo).
/// </summary>
public bool UserLoved { get; set; }

/// <summary>
/// Gets or sets now playing status (available only for users, i.e. user.getRecentTracks).
/// </summary>
public bool NowPlaying { get; internal set; }

#endregion
}
}
14 changes: 11 additions & 3 deletions src/Hqub.Lastfm/ResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3f3ceea

Please sign in to comment.