MCPcopy Create free account
hub / github.com/Moosync/Moosync / get_canvas

Function get_canvas

src-tauri/librespot/src/player.rs:199–266  ·  view source on GitHub ↗
(track_uri: String, session: Session)

Source from the content-addressed store, hash-verified

197
198#[tracing::instrument(level = "debug", skip(track_uri, session))]
199pub fn get_canvas(track_uri: String, session: Session) -> Result<CanvazResponse> {
200 let (uri, type_) = validate_uri(&track_uri);
201 if let Some(type_) = type_ {
202 if type_ != "track" {
203 return Err(format!(
204 "Spotify URI is not of a track: {}, {}, {:?}",
205 track_uri, type_, uri
206 )
207 .into());
208 }
209
210 if uri.is_none() {
211 return Err(format!(
212 "Failed to parse spotify URI: {}, {}, {:?}",
213 track_uri, type_, uri
214 )
215 .into());
216 }
217 }
218
219 let uri = uri.unwrap();
220
221 let runtime = tokio::runtime::Builder::new_multi_thread()
222 .enable_io()
223 .enable_time()
224 .build()
225 .unwrap();
226
227 runtime.block_on(async {
228 let spclient = session.spclient();
229
230 let mut req = EntityCanvazRequest::new();
231 let mut entity = Entity::new();
232 entity.entity_uri.clone_from(&uri);
233 req.entities.push(entity.clone());
234
235 tracing::info!("{}", protobuf::text_format::print_to_string(&req));
236
237 let url = format!(
238 "{}/canvaz-cache/v0/canvases",
239 spclient.base_url().await.unwrap()
240 );
241 let token = session
242 .token_provider()
243 .get_token("playlist-read")
244 .await?
245 .access_token;
246
247 let body = req.write_to_bytes()?;
248
249 let resp = reqwest::Client::builder()
250 .build()
251 .unwrap()
252 .post(url)
253 .header(CONTENT_TYPE, "application/x-protobuf")
254 .bearer_auth(token)
255 .header(CONTENT_LENGTH, body.len())
256 .body(body)

Callers 1

handle_commandMethod · 0.85

Calls 4

validate_uriFunction · 0.85
parse_canvazFunction · 0.85
cloneMethod · 0.80
sendMethod · 0.80

Tested by

no test coverage detected