From d3ee21b9199b49e5de36e1c27ce2f2e2c531f7df Mon Sep 17 00:00:00 2001 From: HazardSy Date: Sun, 18 Feb 2024 14:25:00 +0100 Subject: [PATCH 1/3] Feat : add Liked Songs in Spotify Playlist import list --- .../ImportLists/Spotify/SpotifyPlaylist.cs | 26 +++++++++++++++++-- .../Spotify/SpotifyPlaylistSettings.cs | 2 +- .../ImportLists/Spotify/SpotifyProxy.cs | 8 ++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs index 54bc232f0..553c857cc 100644 --- a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs +++ b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs @@ -29,6 +29,8 @@ namespace NzbDrone.Core.ImportLists.Spotify public override string Name => "Spotify Playlists"; + private const string LIKEDSONGSID = "LikedSongs"; + public override IList Fetch(SpotifyWebAPI api) { return Settings.PlaylistIds.SelectMany(x => Fetch(api, x)).ToList(); @@ -40,7 +42,27 @@ namespace NzbDrone.Core.ImportLists.Spotify _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 playlistTracks; + + if (playlistId.Equals(LIKEDSONGSID)) + { + var savedTracks = _spotifyProxy.GetSavedTracks(this, api); + playlistTracks = new Paging + { + 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) { @@ -140,7 +162,7 @@ namespace NzbDrone.Core.ImportLists.Spotify { id = p.Id, name = p.Name - }) + }).Prepend(new { id = LIKEDSONGSID, name = "Liked Songs" }) // TODO : Add Translation } }; } diff --git a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylistSettings.cs b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylistSettings.cs index 2b18f9d81..52ca74d50 100644 --- a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylistSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylistSettings.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Core.ImportLists.Spotify PlaylistIds = System.Array.Empty(); } - 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 PlaylistIds { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyProxy.cs b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyProxy.cs index a36a63638..476079e47 100644 --- a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyProxy.cs +++ b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyProxy.cs @@ -18,6 +18,8 @@ namespace NzbDrone.Core.ImportLists.Spotify where TSettings : SpotifySettingsBase, new(); Paging GetPlaylistTracks(SpotifyImportListBase list, SpotifyWebAPI api, string id, string fields) where TSettings : SpotifySettingsBase, new(); + Paging GetSavedTracks(SpotifyImportListBase list, SpotifyWebAPI api) + where TSettings : SpotifySettingsBase, new(); Paging GetNextPage(SpotifyImportListBase list, SpotifyWebAPI api, Paging item) where TSettings : SpotifySettingsBase, new(); FollowedArtists GetNextPage(SpotifyImportListBase list, SpotifyWebAPI api, FollowedArtists item) @@ -63,6 +65,12 @@ namespace NzbDrone.Core.ImportLists.Spotify return Execute(list, api, x => x.GetPlaylistTracks(id, fields: fields)); } + public Paging GetSavedTracks(SpotifyImportListBase list, SpotifyWebAPI api) + where TSettings : SpotifySettingsBase, new() + { + return Execute(list, api, x => x.GetSavedTracks(50)); + } + public Paging GetNextPage(SpotifyImportListBase list, SpotifyWebAPI api, Paging item) where TSettings : SpotifySettingsBase, new() { From 638940a035ebfdf2180c8b3ccaf77cd2e7fc8644 Mon Sep 17 00:00:00 2001 From: HazardSy Date: Sun, 18 Feb 2024 14:33:11 +0100 Subject: [PATCH 2/3] Feat: add localization for Liked Songs --- src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs | 7 ++++++- src/NzbDrone.Core/Localization/Core/en.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs index 553c857cc..c1f6ad3c1 100644 --- a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs +++ b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs @@ -5,6 +5,7 @@ using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Localization; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Parser; using NzbDrone.Core.Validation; @@ -22,15 +23,19 @@ namespace NzbDrone.Core.ImportLists.Spotify IConfigService configService, IParsingService parsingService, IHttpClient httpClient, + ILocalizationService localizationService, Logger logger) : base(spotifyProxy, requestBuilder, importListStatusService, importListRepository, configService, parsingService, httpClient, logger) { + _localizationService = localizationService; } public override string Name => "Spotify Playlists"; private const string LIKEDSONGSID = "LikedSongs"; + private readonly ILocalizationService _localizationService; + public override IList Fetch(SpotifyWebAPI api) { return Settings.PlaylistIds.SelectMany(x => Fetch(api, x)).ToList(); @@ -162,7 +167,7 @@ namespace NzbDrone.Core.ImportLists.Spotify { id = p.Id, name = p.Name - }).Prepend(new { id = LIKEDSONGSID, name = "Liked Songs" }) // TODO : Add Translation + }).Prepend(new { id = LIKEDSONGSID, name = _localizationService.GetLocalizedString("LikedSongs") }) } }; } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 4b5f966c9..50e87df14 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -611,6 +611,7 @@ "LidarrSupportsAnyIndexerThatUsesTheNewznabStandardAsWellAsOtherIndexersListedBelow": "{appName} supports any indexer that uses the Newznab standard, as well as other indexers listed below.", "LidarrSupportsMultipleListsForImportingAlbumsAndArtistsIntoTheDatabase": "{appName} supports multiple lists for importing Albums and Artists into the database.", "LidarrTags": "{appName} Tags", + "LikedSongs": "Liked Songs", "Links": "Links", "ListRefreshInterval": "List Refresh Interval", "ListWillRefreshEveryInterp": "List will refresh every {0}", From 961484412a2327eeb5f57de4620162bb4e21b280 Mon Sep 17 00:00:00 2001 From: HazardSy Date: Wed, 21 Feb 2024 08:40:20 +0100 Subject: [PATCH 3/3] Rename constant --- src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs index c1f6ad3c1..54c350bde 100644 --- a/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs +++ b/src/NzbDrone.Core/ImportLists/Spotify/SpotifyPlaylist.cs @@ -30,10 +30,9 @@ namespace NzbDrone.Core.ImportLists.Spotify _localizationService = localizationService; } + private const string LIKED_SONGS_ID = "LikedSongs"; public override string Name => "Spotify Playlists"; - private const string LIKEDSONGSID = "LikedSongs"; - private readonly ILocalizationService _localizationService; public override IList Fetch(SpotifyWebAPI api) @@ -49,7 +48,7 @@ namespace NzbDrone.Core.ImportLists.Spotify Paging playlistTracks; - if (playlistId.Equals(LIKEDSONGSID)) + if (playlistId.Equals(LIKED_SONGS_ID)) { var savedTracks = _spotifyProxy.GetSavedTracks(this, api); playlistTracks = new Paging @@ -167,7 +166,7 @@ namespace NzbDrone.Core.ImportLists.Spotify { id = p.Id, name = p.Name - }).Prepend(new { id = LIKEDSONGSID, name = _localizationService.GetLocalizedString("LikedSongs") }) + }).Prepend(new { id = LIKED_SONGS_ID, name = _localizationService.GetLocalizedString("LikedSongs") }) } }; }