Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spotify Liked Songs playlist in Import List #4613

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Feat : add Liked Songs in Spotify Playlist import list
  • Loading branch information
hazardsy committed Feb 18, 2024
commit d3ee21b9199b49e5de36e1c27ce2f2e2c531f7df
26 changes: 24 additions & 2 deletions src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class SpotifyPlaylist : SpotifyImportListBase<SpotifyPlaylistSettings>

public override string Name => "Spotify Playlists";

private const string LIKEDSONGSID = "LikedSongs";

public override IList<SpotifyImportListItemInfo> Fetch(SpotifyWebAPI api)
{
return Settings.PlaylistIds.SelectMany(x => Fetch(api, x)).ToList();
Expand All @@ -40,7 +42,27 @@ public IList<SpotifyImportListItemInfo> Fetch(SpotifyWebAPI api, string playlist

_logger.Trace($"Processing playlist {playlistId}");

var playlistTracks = _spotifyProxy.GetPlaylistTracks(this, api, playlistId, "next, items(track(name, artists(id, name), album(id, name, release_date, release_date_precision, artists(id, name))))");
Paging<PlaylistTrack> playlistTracks;

if (playlistId.Equals(LIKEDSONGSID))
{
var savedTracks = _spotifyProxy.GetSavedTracks(this, api);
playlistTracks = new Paging<PlaylistTrack>
{
Href = savedTracks.Href,
Limit = savedTracks.Limit,
Offset = savedTracks.Offset,
Next = savedTracks.Next,
Previous = savedTracks.Previous,
Total = savedTracks.Total,
Error = savedTracks.Error,
Items = savedTracks.Items.Select(t => new PlaylistTrack { AddedAt = t.AddedAt, Track = t.Track }).ToList()
};
}
else
{
playlistTracks = _spotifyProxy.GetPlaylistTracks(this, api, playlistId, "next, items(track(name, artists(id, name), album(id, name, release_date, release_date_precision, artists(id, name))))");
}

while (true)
{
Expand Down Expand Up @@ -140,7 +162,7 @@ public override object RequestAction(string action, IDictionary<string, string>
{
id = p.Id,
name = p.Name
})
}).Prepend(new { id = LIKEDSONGSID, name = "Liked Songs" }) // TODO : Add Translation
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public SpotifyPlaylistSettings()
PlaylistIds = System.Array.Empty<string>();
}

public override string Scope => "playlist-read-private";
public override string Scope => "playlist-read-private user-library-read";

[FieldDefinition(1, Label = "Playlists", Type = FieldType.Playlist)]
public IEnumerable<string> PlaylistIds { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions src/NzbDrone.Core/ImportLists/Spotify/SpotifyProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Paging<SavedAlbum> GetSavedAlbums<TSettings>(SpotifyImportListBase<TSettings> li
where TSettings : SpotifySettingsBase<TSettings>, new();
Paging<PlaylistTrack> GetPlaylistTracks<TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api, string id, string fields)
where TSettings : SpotifySettingsBase<TSettings>, new();
Paging<SavedTrack> GetSavedTracks<TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api)
where TSettings : SpotifySettingsBase<TSettings>, new();
Paging<T> GetNextPage<T, TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api, Paging<T> item)
where TSettings : SpotifySettingsBase<TSettings>, new();
FollowedArtists GetNextPage<TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api, FollowedArtists item)
Expand Down Expand Up @@ -63,6 +65,12 @@ public Paging<PlaylistTrack> GetPlaylistTracks<TSettings>(SpotifyImportListBase<
return Execute(list, api, x => x.GetPlaylistTracks(id, fields: fields));
}

public Paging<SavedTrack> GetSavedTracks<TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api)
where TSettings : SpotifySettingsBase<TSettings>, new()
{
return Execute(list, api, x => x.GetSavedTracks(50));
}

public Paging<T> GetNextPage<T, TSettings>(SpotifyImportListBase<TSettings> list, SpotifyWebAPI api, Paging<T> item)
where TSettings : SpotifySettingsBase<TSettings>, new()
{
Expand Down