Restyled by black

This commit is contained in:
Restyled.io
2021-05-22 01:26:33 +00:00
parent 58e8ba2347
commit 544c57ff1f
52 changed files with 3303 additions and 2729 deletions

View File

@@ -17,9 +17,12 @@ class ApiClient(Closeable):
self._baseUrl = "https://{}".format(ApResolver.get_random_spclient())
def build_request(
self, method: str, suffix: str,
headers: typing.Union[None, typing.Dict[str, str]],
body: typing.Union[None, bytes]) -> requests.PreparedRequest:
self,
method: str,
suffix: str,
headers: typing.Union[None, typing.Dict[str, str]],
body: typing.Union[None, bytes],
) -> requests.PreparedRequest:
request = requests.PreparedRequest()
request.method = method
request.data = body
@@ -27,37 +30,53 @@ class ApiClient(Closeable):
if headers is not None:
request.headers = headers
request.headers["Authorization"] = "Bearer {}".format(
self._session.tokens().get("playlist-read"))
self._session.tokens().get("playlist-read")
)
request.url = self._baseUrl + suffix
return request
def send(self, method: str, suffix: str,
headers: typing.Union[None, typing.Dict[str, str]],
body: typing.Union[None, bytes]) -> requests.Response:
def send(
self,
method: str,
suffix: str,
headers: typing.Union[None, typing.Dict[str, str]],
body: typing.Union[None, bytes],
) -> requests.Response:
resp = self._session.client().send(
self.build_request(method, suffix, headers, body))
self.build_request(method, suffix, headers, body)
)
return resp
def put_connect_state(self, connection_id: str,
proto: Connect.PutStateRequest) -> None:
def put_connect_state(
self, connection_id: str, proto: Connect.PutStateRequest
) -> None:
resp = self.send(
"PUT",
"/connect-state/v1/devices/{}".format(self._session.device_id()), {
"/connect-state/v1/devices/{}".format(self._session.device_id()),
{
"Content-Type": "application/protobuf",
"X-Spotify-Connection-Id": connection_id
}, proto.SerializeToString())
"X-Spotify-Connection-Id": connection_id,
},
proto.SerializeToString(),
)
if resp.status_code == 413:
self._LOGGER.warning(
"PUT state payload is too large: {} bytes uncompressed.".
format(len(proto.SerializeToString())))
"PUT state payload is too large: {} bytes uncompressed.".format(
len(proto.SerializeToString())
)
)
elif resp.status_code != 200:
self._LOGGER.warning("PUT state returned {}. headers: {}".format(
resp.status_code, resp.headers))
self._LOGGER.warning(
"PUT state returned {}. headers: {}".format(
resp.status_code, resp.headers
)
)
def get_metadata_4_track(self, track: TrackId) -> Metadata.Track:
resp = self.send("GET", "/metadata/4/track/{}".format(track.hex_id()),
None, None)
resp = self.send(
"GET", "/metadata/4/track/{}".format(track.hex_id()), None, None
)
ApiClient.StatusCodeException.check_status(resp)
body = resp.content
@@ -68,9 +87,9 @@ class ApiClient(Closeable):
return proto
def get_metadata_4_episode(self, episode: EpisodeId) -> Metadata.Episode:
resp = self.send("GET",
"/metadata/4/episode/{}".format(episode.hex_id()),
None, None)
resp = self.send(
"GET", "/metadata/4/episode/{}".format(episode.hex_id()), None, None
)
ApiClient.StatusCodeException.check_status(resp)
body = resp.content
@@ -81,8 +100,9 @@ class ApiClient(Closeable):
return proto
def get_metadata_4_album(self, album: AlbumId) -> Metadata.Album:
resp = self.send("GET", "/metadata/4/album/{}".format(album.hex_id()),
None, None)
resp = self.send(
"GET", "/metadata/4/album/{}".format(album.hex_id()), None, None
)
ApiClient.StatusCodeException.check_status(resp)
body = resp.content
@@ -93,9 +113,9 @@ class ApiClient(Closeable):
return proto
def get_metadata_4_artist(self, artist: ArtistId) -> Metadata.Artist:
resp = self.send("GET",
"/metadata/4/artist/{}".format(artist.hex_id()), None,
None)
resp = self.send(
"GET", "/metadata/4/artist/{}".format(artist.hex_id()), None, None
)
ApiClient.StatusCodeException.check_status(resp)
body = resp.content
@@ -106,8 +126,7 @@ class ApiClient(Closeable):
return proto
def get_metadata_4_show(self, show: ShowId) -> Metadata.Show:
resp = self.send("GET", "/metadata/4/show/{}".format(show.hex_id()),
None, None)
resp = self.send("GET", "/metadata/4/show/{}".format(show.hex_id()), None, None)
ApiClient.StatusCodeException.check_status(resp)
body = resp.content