Skip to content

Commit 887409a

Browse files
committed
Added: Playlists API: upload Custom Playlist Image
1 parent 6715453 commit 887409a

File tree

3 files changed

+113
-17
lines changed

3 files changed

+113
-17
lines changed

src/main/java/Client/SpotifyRestAPI.java

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import Controller.PlayerController.CurrentTrack.baseCurrentTrack;
2020
import Controller.PlayerController.Devices.basePlayerDevice;
2121
import Controller.PlayerController.baseUserPlayback;
22+
import Controller.PlaylistController.CoverImage;
2223
import Controller.PlaylistController.Playlist;
2324
import Controller.PlaylistController.PlaylistItems.BasePlaylistItems;
2425
import Controller.PlaylistController.SnapshotId;
@@ -63,23 +64,6 @@ public String getTokenString(String token){
6364
}
6465

6566

66-
public void makeRequest(String requestType){
67-
68-
if(requestType.toLowerCase(Locale.ENGLISH).equals("get")){
69-
// make get request
70-
}
71-
else if(requestType.toLowerCase(Locale.ENGLISH).equals("post")){
72-
// make post request
73-
}
74-
else if(requestType.toLowerCase(Locale.ENGLISH).equals("put")){
75-
// make put request
76-
}
77-
else{
78-
// make delete request
79-
}
80-
81-
}
82-
8367
/*
8468
8569
Authorization Method <--- generates token that expires
@@ -1448,6 +1432,65 @@ public SnapshotId reorderOrReplacePlaylistItems(SpotifyClient client) throws IOE
14481432

14491433
}
14501434

1435+
public SnapshotId removePlaylistItems(SpotifyClient client) throws IOException {
1436+
1437+
String url = baseUrl + String.format("/v1/playlists/%s/tracks/",client.getPlaylist().getPlaylistId());
1438+
1439+
Retrofit retrofit = new Retrofit.Builder()
1440+
.baseUrl(url)
1441+
.addConverterFactory(GsonConverterFactory.create())
1442+
.build();
1443+
1444+
playlistInterface playlistInterface = retrofit.create(Model.playlistInterface.class);
1445+
1446+
Call<SnapshotId> call = playlistInterface.removeItemsFromPlaylist(getTokenString(client.getToken()),client.getPlaylist().getPlaylistId(),client.getTrackIds().convertTrackIds());
1447+
1448+
Response<SnapshotId> response = call.execute();
1449+
1450+
return response.body();
1451+
1452+
}
1453+
1454+
public CoverImage getPlaylistCoverImage(SpotifyClient client) throws IOException {
1455+
1456+
String url = baseUrl + String.format("/v1/playlists/%s/images/",client.getPlaylist().getPlaylistId());
1457+
1458+
Retrofit retrofit = new Retrofit.Builder()
1459+
.baseUrl(url)
1460+
.addConverterFactory(GsonConverterFactory.create())
1461+
.build();
1462+
1463+
playlistInterface playlistInterface = retrofit.create(Model.playlistInterface.class);
1464+
1465+
Call<CoverImage> call = playlistInterface.getPlaylistCoverImage(getTokenString(client.getToken()),client.getPlaylist().getPlaylistId());
1466+
1467+
Response<CoverImage> response = call.execute();
1468+
1469+
return response.body();
1470+
1471+
}
1472+
1473+
public boolean uploadCustomPlaylistImage(SpotifyClient client) throws IOException {
1474+
1475+
String url = baseUrl + String.format("/v1/playlists/%s/images/",client.getPlaylist().getPlaylistId());
1476+
1477+
Retrofit retrofit = new Retrofit.Builder()
1478+
.baseUrl(url)
1479+
.addConverterFactory(GsonConverterFactory.create())
1480+
.build();
1481+
1482+
playlistInterface playlistInterface = retrofit.create(Model.playlistInterface.class);
1483+
1484+
Call<Object> call = playlistInterface.uploadPlaylistCoverImage(getTokenString(client.getToken()),client.getContentType(),client.getPlaylist().getPlaylistId());
1485+
1486+
Response<Object> response = call.execute();
1487+
1488+
return response.isSuccessful();
1489+
1490+
1491+
1492+
}
1493+
14511494

14521495

14531496

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package Controller.PlaylistController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class CoverImage {
7+
8+
@SerializedName("height")
9+
@Expose
10+
private Integer height;
11+
@SerializedName("url")
12+
@Expose
13+
private String url;
14+
@SerializedName("width")
15+
@Expose
16+
private Integer width;
17+
18+
public Integer getHeight() {
19+
return height;
20+
}
21+
22+
public void setHeight(Integer height) {
23+
this.height = height;
24+
}
25+
26+
public String getUrl() {
27+
return url;
28+
}
29+
30+
public void setUrl(String url) {
31+
this.url = url;
32+
}
33+
34+
public Integer getWidth() {
35+
return width;
36+
}
37+
38+
public void setWidth(Integer width) {
39+
this.width = width;
40+
}
41+
42+
43+
}

src/main/java/Model/playlistInterface.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Model;
22

3+
import Controller.PlaylistController.CoverImage;
34
import Controller.PlaylistController.Playlist;
45
import Controller.PlaylistController.PlaylistItems.BasePlaylistItems;
56
import Controller.PlaylistController.SnapshotId;
@@ -35,4 +36,13 @@ public interface playlistInterface {
3536
@PUT("https://api.spotify.com/v1/playlists/{playlistId}/tracks")
3637
Call<SnapshotId> reorderOrReplacePlaylistsItems(@Header("Authorization") String auth, @Path("playlistId") String playlistId);
3738

39+
@DELETE("https://api.spotify.com/v1/playlists/{playlistId}/tracks")
40+
Call<SnapshotId> removeItemsFromPlaylist(@Header("Authorization") String auth, @Path("playlistId") String playlistId, @Body String tracks);
41+
42+
@GET("https://api.spotify.com/v1/playlists/{playlistId}/images")
43+
Call<CoverImage> getPlaylistCoverImage(@Header("Authorization") String auth, @Path("playlistId") String playlistId);
44+
45+
@PUT("https://api.spotify.com/v1/playlists/{playlistId}/images")
46+
Call<Object> uploadPlaylistCoverImage(@Header("Authorization") String auth, @Header("Content-Type") String contentType, @Path("playlistId") String playlistId);
47+
3848
}

0 commit comments

Comments
 (0)