Skip to content

Commit f173e23

Browse files
mlavendeJohnnyCrazy
authored andcommitted
Support uploading an image for a playlist (JohnnyCrazy#318)
* Support uploading an image for a playlist * Support uploading a playlist image * Support uploading a playlist image Support uploading a playlist image * Add support for new playlist endpoint without userid
1 parent f31af23 commit f173e23

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎SpotifyAPI.Web/Enums/Scope.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public enum Scope
6060
UserReadCurrentlyPlaying = 131072,
6161

6262
[String("app-remote-control")]
63-
AppRemoteControl = 262144
63+
AppRemoteControl = 262144,
64+
65+
[String("ugc-image-upload")]
66+
UgcImageUpload = 524288
6467
}
6568
}

‎SpotifyAPI.Web/SpotifyWebAPI.cs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,56 @@ public async Task<ErrorResponse> UpdatePlaylistAsync(string userId, string playl
14961496
return (await UploadDataAsync<ErrorResponse>(_builder.UpdatePlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT").ConfigureAwait(false)) ?? new ErrorResponse();
14971497
}
14981498

1499+
/// <summary>
1500+
/// Change a playlist’s name and public/private state. (The user must, of course, own the playlist.)
1501+
/// </summary>
1502+
/// <param name="userId">The user's Spotify user ID.</param>
1503+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
1504+
/// <param name="base64EncodedJpgImage">The image as a base64 encoded string</param>
1505+
/// <returns></returns>
1506+
/// <remarks>AUTH NEEDED</remarks>
1507+
public ErrorResponse UploadPlaylistImage(string userId, string playlistId, string base64EncodedJpgImage)
1508+
{
1509+
return UploadData<ErrorResponse>(_builder.UploadPlaylistImage(userId, playlistId), base64EncodedJpgImage, "PUT") ?? new ErrorResponse();
1510+
}
1511+
1512+
/// <summary>
1513+
/// Change a playlist’s name and public/private state asynchronously. (The user must, of course, own the playlist.)
1514+
/// </summary>
1515+
/// <param name="userId">The user's Spotify user ID.</param>
1516+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
1517+
/// <param name="base64EncodedJpgImage">The image as a base64 encoded string</param>
1518+
/// <returns></returns>
1519+
/// <remarks>AUTH NEEDED</remarks>
1520+
public async Task<ErrorResponse> UploadPlaylistImageAsync(string userId, string playlistId, string base64EncodedJpgImage)
1521+
{
1522+
return (await UploadDataAsync<ErrorResponse>(_builder.UploadPlaylistImage(userId, playlistId), base64EncodedJpgImage, "PUT").ConfigureAwait(false)) ?? new ErrorResponse();
1523+
}
1524+
1525+
/// <summary>
1526+
/// Change a playlist’s name and public/private state. (The user must, of course, own the playlist.)
1527+
/// </summary>
1528+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
1529+
/// <param name="base64EncodedJpgImage">The image as a base64 encoded string</param>
1530+
/// <returns></returns>
1531+
/// <remarks>AUTH NEEDED</remarks>
1532+
public ErrorResponse UploadPlaylistImage(string playlistId, string base64EncodedJpgImage)
1533+
{
1534+
return UploadData<ErrorResponse>(_builder.UploadPlaylistImage(playlistId), base64EncodedJpgImage, "PUT") ?? new ErrorResponse();
1535+
}
1536+
1537+
/// <summary>
1538+
/// Change a playlist’s name and public/private state asynchronously. (The user must, of course, own the playlist.)
1539+
/// </summary>
1540+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
1541+
/// <param name="base64EncodedJpgImage">The image as a base64 encoded string</param>
1542+
/// <returns></returns>
1543+
/// <remarks>AUTH NEEDED</remarks>
1544+
public async Task<ErrorResponse> UploadPlaylistImageAsync(string playlistId, string base64EncodedJpgImage)
1545+
{
1546+
return (await UploadDataAsync<ErrorResponse>(_builder.UploadPlaylistImage(playlistId), base64EncodedJpgImage, "PUT").ConfigureAwait(false)) ?? new ErrorResponse();
1547+
}
1548+
14991549
/// <summary>
15001550
/// Replace all the tracks in a playlist, overwriting its existing tracks. This powerful request can be useful for
15011551
/// replacing tracks, re-ordering existing tracks, or clearing the playlist.

‎SpotifyAPI.Web/SpotifyWebBuilder.cs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,29 @@ public string ReorderPlaylist(string userId, string playlistId)
763763
return $"{APIBase}/users/{userId}/playlists/{playlistId}/tracks";
764764
}
765765

766+
/// <summary>
767+
/// Upload an image for a playlist.
768+
/// </summary>
769+
/// <param name="userId">The user's Spotify user ID.</param>
770+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
771+
/// <returns></returns>
772+
/// <remarks>AUTH NEEDED</remarks>
773+
public string UploadPlaylistImage(string userId, string playlistId)
774+
{
775+
return $"{APIBase}/users/{userId}/playlists/{playlistId}/images";
776+
}
777+
778+
/// <summary>
779+
/// Upload an image for a playlist.
780+
/// </summary>
781+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
782+
/// <returns></returns>
783+
/// <remarks>AUTH NEEDED</remarks>
784+
public string UploadPlaylistImage(string playlistId)
785+
{
786+
return $"{APIBase}/playlists/{playlistId}/images";
787+
}
788+
766789
#endregion Playlists
767790

768791
#region Profiles

0 commit comments

Comments
 (0)