Skip to content

Commit 336fa9a

Browse files
committed
fix: always use spclient.wg.spotify.com for metadata requests
1 parent a14f85b commit 336fa9a

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

librespot/core.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def build_request(
8080
suffix: str,
8181
headers: typing.Union[None, typing.Dict[str, str]],
8282
body: typing.Union[None, bytes],
83+
url: typing.Union[None, str],
8384
) -> requests.PreparedRequest:
8485
"""
8586
@@ -90,6 +91,8 @@ def build_request(
9091
:param str]]:
9192
:param body: typing.Union[None:
9293
:param bytes]:
94+
:param url: typing.Union[None:
95+
:param str]:
9396
9497
"""
9598
if self.__client_token_str is None:
@@ -107,7 +110,10 @@ def build_request(
107110
request.headers["Authorization"] = "Bearer {}".format(
108111
self.__session.tokens().get("playlist-read"))
109112
request.headers["client-token"] = self.__client_token_str
110-
request.url = self.__base_url + suffix
113+
if url is None:
114+
request.url = self.__base_url + suffix
115+
else:
116+
request.url = url + suffix
111117
return request
112118

113119
def send(
@@ -129,7 +135,31 @@ def send(
129135
130136
"""
131137
response = self.__session.client().send(
132-
self.build_request(method, suffix, headers, body))
138+
self.build_request(method, suffix, headers, body, None))
139+
return response
140+
141+
def sendToUrl(
142+
self,
143+
method: str,
144+
url: str,
145+
suffix: str,
146+
headers: typing.Union[None, typing.Dict[str, str]],
147+
body: typing.Union[None, bytes],
148+
) -> requests.Response:
149+
"""
150+
151+
:param method: str:
152+
:param url: str:
153+
:param suffix: str:
154+
:param headers: typing.Union[None:
155+
:param typing.Dict[str:
156+
:param str]]:
157+
:param body: typing.Union[None:
158+
:param bytes]:
159+
160+
"""
161+
response = self.__session.client().send(
162+
self.build_request(method, suffix, headers, body, url))
133163
return response
134164

135165
def put_connect_state(self, connection_id: str,
@@ -163,7 +193,7 @@ def get_metadata_4_track(self, track: TrackId) -> Metadata.Track:
163193
:param track: TrackId:
164194
165195
"""
166-
response = self.send("GET",
196+
response = self.sendToUrl("GET", "https://spclient.wg.spotify.com",
167197
"/metadata/4/track/{}".format(track.hex_id()),
168198
None, None)
169199
ApiClient.StatusCodeException.check_status(response)
@@ -180,7 +210,7 @@ def get_metadata_4_episode(self, episode: EpisodeId) -> Metadata.Episode:
180210
:param episode: EpisodeId:
181211
182212
"""
183-
response = self.send("GET",
213+
response = self.sendToUrl("GET", "https://spclient.wg.spotify.com",
184214
"/metadata/4/episode/{}".format(episode.hex_id()),
185215
None, None)
186216
ApiClient.StatusCodeException.check_status(response)

0 commit comments

Comments
 (0)