@@ -55,6 +55,13 @@ const CONNECTION_ID: HeaderName = HeaderName::from_static("x-spotify-connection-
5555const 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 {
8693pub struct RequestOptions {
8794 metrics : bool ,
8895 salt : bool ,
96+ base_url : Option < & ' static str > ,
8997}
9098
9199impl 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