Skip to content

Commit

Permalink
Merge pull request #69 from csaavedra/support-album-artist
Browse files Browse the repository at this point in the history
Add album artist information to scrobbles and now-playing requests
  • Loading branch information
jesseward authored Oct 3, 2024
2 parents b405bf7 + 42a934d commit ef6f7e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Jellyfin.Plugin.Lastfm/Api/LastfmApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public async Task Scrobble(Audio item, LastfmUser user)
{
request.MbId = item.ProviderIds["MusicBrainzTrack"];
}
var albumArtist = item.AlbumArtists.First();
if (!string.IsNullOrWhiteSpace(albumArtist) && albumArtist != request.Artist)
{
request.AlbumArtist = albumArtist;
}

try
{
Expand All @@ -82,7 +87,7 @@ public async Task Scrobble(Audio item, LastfmUser user)
}
catch (Exception ex)
{
_logger.LogError("Failed to Scrobble track: track: ex={0}, name={1}, track={2}, artist={3}, album={4}, mbid={5}", ex, item.Name, request.Track, request.Artist, request.Album, request.MbId);
_logger.LogError("Failed to Scrobble track: track: ex={0}, name={1}, track={2}, artist={3}, album={4}, albumArtist={5}, mbid={6}", ex, item.Name, request.Track, request.Artist, request.Album, request.AlbumArtist, request.MbId);
}
}

Expand All @@ -108,6 +113,11 @@ public async Task NowPlaying(Audio item, LastfmUser user)
{
request.MbId = item.ProviderIds["MusicBrainzTrack"];
}
var albumArtist = item.AlbumArtists.First();
if (!string.IsNullOrWhiteSpace(albumArtist) && albumArtist != request.Artist)
{
request.AlbumArtist = albumArtist;
}

// Add duration
if (item.RunTimeTicks != null)
Expand All @@ -126,7 +136,7 @@ public async Task NowPlaying(Audio item, LastfmUser user)
}
catch (Exception ex)
{
_logger.LogError("Failed to send now playing for track: ex={0}, name={1}, track={2}, artist={3}, album={4}, mbid={5}", ex, item.Name, request.Track, request.Artist, request.Album, request.MbId);
_logger.LogError("Failed to send now playing for track: ex={0}, name={1}, track={2}, artist={3}, album={4}, albumArtist={5}, mbid={6}", ex, item.Name, request.Track, request.Artist, request.Album, request.AlbumArtist, request.MbId);
}
}

Expand Down
5 changes: 5 additions & 0 deletions Jellyfin.Plugin.Lastfm/Models/Requests/NowPlayingRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class NowPlayingRequest : BaseAuthedRequest
public string Track { get; set; }
public string Album { get; set; }
public string Artist { get; set; }
public string AlbumArtist { get; set; }
public int Duration { get; set; }
public string MbId { get; set; }

Expand All @@ -29,6 +30,10 @@ public override Dictionary<string, string> ToDictionary()
{
nowPlaying.Add("mbid", MbId);
}
if (!string.IsNullOrWhiteSpace(AlbumArtist))
{
nowPlaying.Add("albumArtist", AlbumArtist);
}

return nowPlaying;
}
Expand Down
7 changes: 6 additions & 1 deletion Jellyfin.Plugin.Lastfm/Models/Requests/ScrobbleRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class ScrobbleRequest : BaseAuthedRequest
{
// API docs for scrobbling located at https://www.last.fm/api/show/track.scrobble
// Track, Artist, and Timestamp are required
// Album and MusicBrainzid are optional.
// Album, ArtistAlbum, and MusicBrainzid are optional.
public string Track { get; set; }
public string Artist { get; set; }
public int Timestamp { get; set; }
public string Album { get; set; }
public string AlbumArtist { get; set; }
public string MbId { get; set; }

public override Dictionary<string, string> ToDictionary()
Expand All @@ -31,6 +32,10 @@ public override Dictionary<string, string> ToDictionary()
{
scrobbleRequest.Add("mbid", MbId);
}
if (!string.IsNullOrWhiteSpace(AlbumArtist))
{
scrobbleRequest.Add("albumArtist", AlbumArtist);
}

return scrobbleRequest;
}
Expand Down

0 comments on commit ef6f7e4

Please sign in to comment.