2023-01-06 21:11:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-10-07 18:29:33 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SpotifyAPI.Web;
|
|
|
|
|
|
|
|
|
|
namespace Selector.CLI.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class SpotifyExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task<(FullPlaylist, IEnumerable<PlaylistTrack<IPlayableItem>>)> GetPopulated(this ISpotifyClient client, string playlistId, ILogger logger = null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var playlist = await client.Playlists.Get(playlistId);
|
|
|
|
|
var items = await client.Paginate(playlist.Tracks).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return (playlist, items);
|
|
|
|
|
}
|
|
|
|
|
catch (APIUnauthorizedException e)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogDebug("Unauthorised error: [{message}] (should be refreshed and retried?)", e.Message);
|
2023-01-06 21:11:29 +00:00
|
|
|
|
throw;
|
2022-10-07 18:29:33 +01:00
|
|
|
|
}
|
|
|
|
|
catch (APITooManyRequestsException e)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogDebug("Too many requests error: [{message}]", e.Message);
|
2023-01-06 21:11:29 +00:00
|
|
|
|
throw;
|
2022-10-07 18:29:33 +01:00
|
|
|
|
}
|
|
|
|
|
catch (APIException e)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogDebug("API error: [{message}]", e.Message);
|
2023-01-06 21:11:29 +00:00
|
|
|
|
throw;
|
2022-10-07 18:29:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|