spotify module#

Module to handle talking to the Spotify API.

This exposes a single instance, and the main class should not be instantiated more than once.

async get_new_tokens(req: Request)[source]#
async get_now_playing(req: Request)[source]#
class TokenHandler[source]#

Bases: object

async get_token()[source]#

Get the Spotify token used for accessing the API.

If the token is expired, obtain a new one. Otherwise, return the one saved on disk.

property session#

The aiohttp session to connect to the Spotify API.

load_tokens(filename=None)[source]#

Load the access and refresh tokens from disk.

save_tokens(filename=None)[source]#

Save the access and refresh tokens to disk.

async get_new_access_token(*, code=None)[source]#

Obtain a new access token using the refresh token.

This doesn’t return any value.

Request authentication from Spotify API and pass it on to the client.

This is used once at first, and then whenever the refresh token expires.

populate_tokens(data: dict[str, str | int])[source]#

Tokens freshly obtained from Spotify.

class Spotify[source]#

Bases: object

property session#

The aiohttp session to connect to the Spotify API.

async is_token_valid()[source]#

Check if the tokens are still valid.

authenticate()[source]#

Trigger a handshake to get new OAuth2 credentials.

async now_playing()[source]#

Obtain the currently-playing song using the Spotify API.