Compare commits

...

4 Commits

Author SHA1 Message Date
7e4807f95a Добавлено более подробное описание ошибки
All checks were successful
Verify Dev Build / publish (push) Successful in 33s
2026-03-08 21:48:27 +03:00
88f6bbb7db Фикс статус кода при отсутствии модели
All checks were successful
Verify Dev Build / publish (push) Successful in 31s
2026-03-08 17:55:24 +03:00
c7ffb2608d Добавлено 2 эндпоинта на скип текущего и возврат прошлого сонга
All checks were successful
Verify Dev Build / publish (push) Successful in 32s
2026-03-08 10:10:21 +03:00
93644882a0 Фикс получения и обновления токенов
Some checks failed
Verify Dev Build / publish (push) Has been cancelled
2026-03-08 08:05:05 +03:00
3 changed files with 28 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[project]
name = "oxidespotify"
version = "0.1.0"
version = "0.2.2"
description = "Client for Spotify API"
readme = "README.md"
authors = [{ name = "Miwory", email = "miwory.uwu@gmail.com" }]

View File

@ -36,7 +36,9 @@ class SpotifyAPIClient(OxideHTTP):
async def _process[T: BaseModel](
self, req: Response | CachedResponse, schema: type[T] | None
) -> T | None:
if req.status_code == 204:
if req.status_code == 204 or (
req.status_code == 200 and schema is None
):
return None
if req.status_code >= 500:
@ -128,11 +130,27 @@ class SpotifyAPIClient(OxideHTTP):
async def pause_playback(self) -> NoReturn:
raise NotImplementedError
async def skip_to_next(self) -> NoReturn:
raise NotImplementedError
async def skip_to_next(self, access_token: str, device_id: str) -> None:
req = self.post(
'/me/player/next',
params={'device_id': device_id},
headers=self._auth(access_token),
)
async def skip_to_previous(self) -> NoReturn:
raise NotImplementedError
req = await self._process_request(req)
return await self._process(req, None)
async def skip_to_previous(
self, access_token: str, device_id: str
) -> None:
req = self.post(
'/me/player/previous',
params={'device_id': device_id},
headers=self._auth(access_token),
)
req = await self._process_request(req)
return await self._process(req, None)
async def seek_to_position(self) -> NoReturn:
raise NotImplementedError

View File

@ -41,14 +41,15 @@ class SpotifyAuthClient(OxideHTTP):
data = await req.json()
if req.status_code >= 400:
raise s.ClientError(req.status_code, data['error']['message'])
err = f'{data["error"]}: {data["error_description"]}'
raise s.ClientError(req.status_code, err)
return schema.model_validate(data)
async def user_access_token(self, code: str) -> s.UserAccessToken:
req = await self.post(
'/token',
json={
form={
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': self.__redirect_uri,
@ -60,7 +61,7 @@ class SpotifyAuthClient(OxideHTTP):
async def refresh_access_token(self, refresh_token: str) -> s.Token:
req = await self.post(
'/token',
json={
form={
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': self.__client_id,