|
57 | 57 | from librespot.proto import Keyexchange_pb2 as Keyexchange |
58 | 58 | from librespot.proto import Metadata_pb2 as Metadata |
59 | 59 | from librespot.proto import Playlist4External_pb2 as Playlist4External |
60 | | -from librespot.proto.ExtendedMetadata_pb2 import EntityRequest, BatchedEntityRequest, ExtensionQuery |
| 60 | +from librespot.proto.ExtendedMetadata_pb2 import EntityRequest, BatchedEntityRequest, ExtensionQuery, BatchedExtensionResponse |
61 | 61 | from librespot.proto.ExtensionKind_pb2 import ExtensionKind |
62 | 62 | from librespot.proto.ExplicitContentPubsub_pb2 import UserAttributesUpdate |
63 | 63 | from librespot.proto.spotify.login5.v3 import Login5_pb2 as Login5 |
@@ -193,98 +193,76 @@ def put_connect_state(self, connection_id: str, |
193 | 193 | response.status_code, response.headers)) |
194 | 194 |
|
195 | 195 | def get_ext_metadata(self, extension_kind: ExtensionKind, uri: str): |
196 | | - query = ExtensionQuery(extension_kind=extension_kind) |
197 | | - req = EntityRequest(entity_uri=uri, query=[query,]) |
198 | | - batch = BatchedEntityRequest(entity_request=[req,]) |
199 | 196 | headers = CaseInsensitiveDict({"content-type": "application/x-protobuf"}) |
| 197 | + req = EntityRequest(entity_uri=uri, query=[ExtensionQuery(extension_kind=extension_kind),]) |
| 198 | + |
200 | 199 | response = self.send("POST", "/extended-metadata/v0/extended-metadata", |
201 | | - headers, batch.SerializeToString()) |
202 | | - return response |
| 200 | + headers, BatchedEntityRequest(entity_request=[req,]).SerializeToString()) |
| 201 | + ApiClient.StatusCodeException.check_status(response) |
| 202 | + |
| 203 | + body = response.content |
| 204 | + if body is None: |
| 205 | + raise RuntimeError() |
| 206 | + |
| 207 | + proto = BatchedExtensionResponse() |
| 208 | + proto.ParseFromString(body) |
| 209 | + mdb: bytes = proto.extended_metadata.pop().extension_data.pop().extension_data.value |
| 210 | + return mdb |
203 | 211 |
|
204 | 212 | def get_metadata_4_track(self, track: TrackId) -> Metadata.Track: |
205 | 213 | """ |
206 | 214 |
|
207 | 215 | :param track: TrackId: |
208 | 216 |
|
209 | 217 | """ |
210 | | - response = self.get_ext_metadata(ExtensionKind.TRACK_V4, track.to_spotify_uri()) |
211 | | - ApiClient.StatusCodeException.check_status(response) |
212 | | - body = response.content |
213 | | - if body is None: |
214 | | - raise RuntimeError() |
215 | | - # TODO: update parsing of successful response |
216 | | - proto = Metadata.Track() |
217 | | - proto.ParseFromString(body) |
218 | | - return proto |
| 218 | + mdb = self.get_ext_metadata(ExtensionKind.TRACK_V4, track.to_spotify_uri()) |
| 219 | + md = Metadata.Track() |
| 220 | + md.ParseFromString(mdb) |
| 221 | + return md |
219 | 222 |
|
220 | 223 | def get_metadata_4_episode(self, episode: EpisodeId) -> Metadata.Episode: |
221 | 224 | """ |
222 | 225 |
|
223 | 226 | :param episode: EpisodeId: |
224 | 227 |
|
225 | 228 | """ |
226 | | - response = self.sendToUrl("GET", "https://spclient.wg.spotify.com", |
227 | | - "/metadata/4/episode/{}".format(episode.hex_id()), |
228 | | - None, None) |
229 | | - ApiClient.StatusCodeException.check_status(response) |
230 | | - body = response.content |
231 | | - if body is None: |
232 | | - raise IOError() |
233 | | - proto = Metadata.Episode() |
234 | | - proto.ParseFromString(body) |
235 | | - return proto |
| 229 | + mdb = self.get_ext_metadata(ExtensionKind.EPISODE_V4, episode.to_spotify_uri()) |
| 230 | + md = Metadata.Episode() |
| 231 | + md.ParseFromString(mdb) |
| 232 | + return md |
236 | 233 |
|
237 | 234 | def get_metadata_4_album(self, album: AlbumId) -> Metadata.Album: |
238 | 235 | """ |
239 | 236 |
|
240 | 237 | :param album: AlbumId: |
241 | 238 |
|
242 | 239 | """ |
243 | | - response = self.sendToUrl("GET", "https://spclient.wg.spotify.com", |
244 | | - "/metadata/4/album/{}".format(album.hex_id()), |
245 | | - None, None) |
246 | | - ApiClient.StatusCodeException.check_status(response) |
247 | | - |
248 | | - body = response.content |
249 | | - if body is None: |
250 | | - raise IOError() |
251 | | - proto = Metadata.Album() |
252 | | - proto.ParseFromString(body) |
253 | | - return proto |
| 240 | + mdb = self.get_ext_metadata(ExtensionKind.ALBUM_V4, album.to_spotify_uri()) |
| 241 | + md = Metadata.Album() |
| 242 | + md.ParseFromString(mdb) |
| 243 | + return md |
254 | 244 |
|
255 | 245 | def get_metadata_4_artist(self, artist: ArtistId) -> Metadata.Artist: |
256 | 246 | """ |
257 | 247 |
|
258 | 248 | :param artist: ArtistId: |
259 | 249 |
|
260 | 250 | """ |
261 | | - response = self.sendToUrl("GET", "https://spclient.wg.spotify.com", |
262 | | - "/metadata/4/artist/{}".format(artist.hex_id()), |
263 | | - None, None) |
264 | | - ApiClient.StatusCodeException.check_status(response) |
265 | | - body = response.content |
266 | | - if body is None: |
267 | | - raise IOError() |
268 | | - proto = Metadata.Artist() |
269 | | - proto.ParseFromString(body) |
270 | | - return proto |
| 251 | + mdb = self.get_ext_metadata(ExtensionKind.ARTIST_V4, artist.to_spotify_uri()) |
| 252 | + md = Metadata.Artist() |
| 253 | + md.ParseFromString(mdb) |
| 254 | + return md |
271 | 255 |
|
272 | 256 | def get_metadata_4_show(self, show: ShowId) -> Metadata.Show: |
273 | 257 | """ |
274 | 258 |
|
275 | 259 | :param show: ShowId: |
276 | 260 |
|
277 | 261 | """ |
278 | | - response = self.sendToUrl("GET", "https://spclient.wg.spotify.com", |
279 | | - "/metadata/4/show/{}".format(show.hex_id()), None, |
280 | | - None) |
281 | | - ApiClient.StatusCodeException.check_status(response) |
282 | | - body = response.content |
283 | | - if body is None: |
284 | | - raise IOError() |
285 | | - proto = Metadata.Show() |
286 | | - proto.ParseFromString(body) |
287 | | - return proto |
| 262 | + mdb = self.get_ext_metadata(ExtensionKind.SHOW_V4, show.to_spotify_uri()) |
| 263 | + md = Metadata.Show() |
| 264 | + md.ParseFromString(mdb) |
| 265 | + return md |
288 | 266 |
|
289 | 267 | def get_playlist(self, |
290 | 268 | _id: PlaylistId) -> Playlist4External.SelectedListContent: |
|
0 commit comments