Usage¶
Installation¶
To use PyYtLounge, first install it using pip:
(.venv) $ pip install pyytlounge
Initialization¶
Create an instance of the pyytlounge.YtLoungeApi class, which takes a device name and optionally a logger:
with YtLoungeApi('Test client') as api:
...
As you can see with …: is used. The class is an asynchronous context manager as on close it needs to clean up the aiohttp session. Alternatively, you can call .close() manually:
api = YtLoungeApi('test client')
...
await api.close()
When we have an instance of the class, we need to pair() with a screen.
Currently this can only be done through a pairing code (this can be found in the app’s settings).
pairing_code = input("Enter pairing code: ") # or from another source
paired_and_linked = await api.pair(pairing_code)
If this succeeds the api is now in a linked state.
This means we have the two requirements to connect to a screen: the screen identifier and the lounge id token.
The screen identifier should remain the same, but the lounge id token can change.
If needed, you can refresh the lounge id token using pyytlounge.YtLoungeApi.refresh_auth():
linked = await api.refresh_auth()
From a linked state, the api is ready to connect():
connected = await api.connect()
If this succeeds, commands can now be submitted, such as seek_to():
# seek to 10 seconds
seek_success = await api.seek_to(self, time=10)
You can also subscribe() to the screen’s status:
def receive_state(state: State):
print(state)
# this will block until the subscription ends
subscribed = await api.subscribe(receive_state)