Skip to content

Commit 218a5ec

Browse files
committed
Retrieve playlist metadata (#168)
1 parent a7299e2 commit 218a5ec

6 files changed

Lines changed: 3980 additions & 7 deletions

File tree

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ All the endpoints will respond with `200` if successful or `204` if there isn't
1919
- `POST \player\current` Retrieve information about the current track (metadata and time).
2020

2121
### Metadata
22-
- `POST \metadata\{type}\{uri}` Retrieve metadata. `type` can be one of `episode`, `track`, `album`, `show`, `artist`, `uri` is the standard Spotify uri.
22+
- `POST \metadata\{type}\{uri}` Retrieve metadata. `type` can be one of `episode`, `track`, `album`, `show`, `artist` or `playlist`, `uri` is the standard Spotify uri.
2323

2424
### Search
2525
- `POST \search\{query}` Make a search.

api/src/main/java/xyz/gianlu/librespot/api/handlers/MetadataHandler.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import xyz.gianlu.librespot.core.Session;
1212
import xyz.gianlu.librespot.dealer.ApiClient;
1313
import xyz.gianlu.librespot.mercury.MercuryClient;
14+
import xyz.gianlu.librespot.mercury.MercuryRequests;
1415
import xyz.gianlu.librespot.mercury.model.*;
1516

1617
import java.io.IOException;
@@ -87,14 +88,29 @@ private JsonObject handle(@NotNull Session session, @NotNull MetadataType type,
8788
return ProtobufToJson.convert(session.api().getMetadata4Episode(EpisodeId.fromUri(uri)));
8889
case TRACK:
8990
return ProtobufToJson.convert(session.api().getMetadata4Track(TrackId.fromUri(uri)));
91+
case PLAYLIST:
92+
return handlePlaylist(session, uri);
9093
default:
9194
throw new IllegalArgumentException(type.name());
9295
}
9396
}
9497

98+
@NotNull
99+
private JsonObject handlePlaylist(@NotNull Session session, @NotNull String uri) throws IOException, MercuryClient.MercuryException {
100+
JsonObject obj = new JsonObject();
101+
obj.add("tracks", session.mercury().sendSync(MercuryRequests.getPlaylist(PlaylistId.fromUri(uri))).json());
102+
103+
try {
104+
obj.add("annotations", session.mercury().sendSync(MercuryRequests.getPlaylistAnnotation(PlaylistId.fromUri(uri))).json());
105+
} catch (MercuryClient.MercuryException ignored) {
106+
}
107+
108+
return obj;
109+
}
110+
95111
private enum MetadataType {
96112
EPISODE("episode"), TRACK("track"), ALBUM("album"),
97-
ARTIST("artist"), SHOW("show");
113+
ARTIST("artist"), SHOW("show"), PLAYLIST("playlist");
98114

99115
private final String val;
100116

0 commit comments

Comments
 (0)