Skip to content

Commit ba3d501

Browse files
authored
spclient: Specify base url for metadata requests (#1528)
Fixes #1527
1 parent 3a700f0 commit ba3d501

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5151
- [connect] Correctly apply playing/paused state when transferring playback
5252
- [player] Saturate invalid seek positions to track duration
5353
- [audio] Fall back to other URLs in case of a failure when downloading from CDN
54+
- [core] Metadata requests failing with 500 Internal Server Error
5455

5556
### Deprecated
5657

core/src/spclient.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ const CONNECTION_ID: HeaderName = HeaderName::from_static("x-spotify-connection-
5555
const NO_METRICS_AND_SALT: RequestOptions = RequestOptions {
5656
metrics: false,
5757
salt: false,
58+
base_url: None,
59+
};
60+
61+
const SPCLIENT_FALLBACK_ENDPOINT: RequestOptions = RequestOptions {
62+
metrics: true,
63+
salt: true,
64+
base_url: Some("https://spclient.wg.spotify.com"),
5865
};
5966

6067
#[derive(Debug, Error)]
@@ -86,13 +93,15 @@ impl Default for RequestStrategy {
8693
pub struct RequestOptions {
8794
metrics: bool,
8895
salt: bool,
96+
base_url: Option<&'static str>,
8997
}
9098

9199
impl Default for RequestOptions {
92100
fn default() -> Self {
93101
Self {
94102
metrics: true,
95103
salt: true,
104+
base_url: None,
96105
}
97106
}
98107
}
@@ -449,7 +458,10 @@ impl SpClient {
449458

450459
// Reconnection logic: retrieve the endpoint every iteration, so we can try
451460
// another access point when we are experiencing network issues (see below).
452-
let mut url = self.base_url().await?;
461+
let mut url = match options.base_url {
462+
Some(base_url) => base_url.to_string(),
463+
None => self.base_url().await?,
464+
};
453465
url.push_str(endpoint);
454466

455467
// Add metrics. There is also an optional `partner` key with a value like
@@ -566,7 +578,17 @@ impl SpClient {
566578

567579
pub async fn get_metadata(&self, scope: &str, id: &SpotifyId) -> SpClientResult {
568580
let endpoint = format!("/metadata/4/{}/{}", scope, id.to_base16()?);
569-
self.request(&Method::GET, &endpoint, None, None).await
581+
// For unknown reasons, metadata requests must now be sent through spclient.wg.spotify.com.
582+
// Otherwise, the API will respond with 500 Internal Server Error responses.
583+
// Context: https://github.com/librespot-org/librespot/issues/1527
584+
self.request_with_options(
585+
&Method::GET,
586+
&endpoint,
587+
None,
588+
None,
589+
&SPCLIENT_FALLBACK_ENDPOINT,
590+
)
591+
.await
570592
}
571593

572594
pub async fn get_track_metadata(&self, track_id: &SpotifyId) -> SpClientResult {

0 commit comments

Comments
 (0)