Fix lyrics and add simpler endpoint

This commit is contained in:
Roderick van Domburg 2021-12-08 20:27:15 +01:00
parent 9b2ca1442e
commit f74c574c9f
No known key found for this signature in database
GPG key ID: A9EF5222A26F0451

View file

@ -84,7 +84,7 @@ impl SpClient {
format!("https://{}:{}", ap.0, ap.1) format!("https://{}:{}", ap.0, ap.1)
} }
pub async fn protobuf_request( pub async fn request_with_protobuf(
&self, &self,
method: &str, method: &str,
endpoint: &str, endpoint: &str,
@ -100,6 +100,19 @@ impl SpClient {
.await .await
} }
pub async fn request_as_json(
&self,
method: &str,
endpoint: &str,
headers: Option<HeaderMap>,
body: Option<String>,
) -> SpClientResult {
let mut headers = headers.unwrap_or_else(HeaderMap::new);
headers.insert("Accept", "application/json".parse()?);
self.request(method, endpoint, Some(headers), body).await
}
pub async fn request( pub async fn request(
&self, &self,
method: &str, method: &str,
@ -199,7 +212,7 @@ impl SpClient {
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
headers.insert("X-Spotify-Connection-Id", connection_id.parse()?); headers.insert("X-Spotify-Connection-Id", connection_id.parse()?);
self.protobuf_request("PUT", &endpoint, Some(headers), &state) self.request_with_protobuf("PUT", &endpoint, Some(headers), &state)
.await .await
} }
@ -228,29 +241,36 @@ impl SpClient {
self.get_metadata("show", show_id).await self.get_metadata("show", show_id).await
} }
pub async fn get_lyrics(&self, track_id: SpotifyId, image_id: FileId) -> SpClientResult { pub async fn get_lyrics(&self, track_id: SpotifyId) -> SpClientResult {
let endpoint = format!("/color-lyrics/v1/track/{}", track_id.to_base62(),);
self.request_as_json("GET", &endpoint, None, None).await
}
pub async fn get_lyrics_for_image(
&self,
track_id: SpotifyId,
image_id: FileId,
) -> SpClientResult {
let endpoint = format!( let endpoint = format!(
"/color-lyrics/v2/track/{}/image/spotify:image:{}", "/color-lyrics/v2/track/{}/image/spotify:image:{}",
track_id.to_base16(), track_id.to_base62(),
image_id image_id
); );
let mut headers = HeaderMap::new(); self.request_as_json("GET", &endpoint, None, None).await
headers.insert("Content-Type", "application/json".parse()?);
self.request("GET", &endpoint, Some(headers), None).await
} }
// TODO: Find endpoint for newer canvas.proto and upgrade to that. // TODO: Find endpoint for newer canvas.proto and upgrade to that.
pub async fn get_canvases(&self, request: EntityCanvazRequest) -> SpClientResult { pub async fn get_canvases(&self, request: EntityCanvazRequest) -> SpClientResult {
let endpoint = "/canvaz-cache/v0/canvases"; let endpoint = "/canvaz-cache/v0/canvases";
self.protobuf_request("POST", endpoint, None, &request) self.request_with_protobuf("POST", endpoint, None, &request)
.await .await
} }
pub async fn get_extended_metadata(&self, request: BatchedEntityRequest) -> SpClientResult { pub async fn get_extended_metadata(&self, request: BatchedEntityRequest) -> SpClientResult {
let endpoint = "/extended-metadata/v0/extended-metadata"; let endpoint = "/extended-metadata/v0/extended-metadata";
self.protobuf_request("POST", endpoint, None, &request) self.request_with_protobuf("POST", endpoint, None, &request)
.await .await
} }
} }