### Install PyYtLounge Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Install the PyYtLounge library using pip. This is the first step to begin using the library. ```console (.venv) $ pip install pyytlounge ``` -------------------------------- ### Install pyytlounge Source: https://github.com/fabiognr/pyytlounge/blob/master/README.md Install the pyytlounge package using pip. This command should be run in your terminal. ```bash pip install pyytlounge ``` -------------------------------- ### Install Development Requirements Source: https://github.com/fabiognr/pyytlounge/blob/master/README.md Install the package in editable mode along with its development dependencies. ```bash pip install -e .[dev] ``` -------------------------------- ### Seek to Specific Time Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Submit a command to seek to a specific time in the currently playing video. This example seeks to 10 seconds. ```python # seek to 10 seconds seek_success = await api.seek_to(time=10) ``` -------------------------------- ### Get Screen ID from DIAL Endpoint Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/discovery.md Use this snippet after obtaining the DIAL endpoint URL. It retrieves the screen ID and name, then pairs with the screen using the `YtLoungeApi`. ```python from pyytlounge.dial import get_screen_id_from_dial dial_url = ... result = get_screen_id_from_dial(dial_url) async with YtLoungeApi('Test client') as api: paired = api.pair_with_screen_id(result.screen_id, result.screen_name) print(paired) ``` -------------------------------- ### View Local Documentation Source: https://github.com/fabiognr/pyytlounge/blob/master/CONTRIBUTING.md Navigate to the docs directory and execute the view_docs.sh script to serve the documentation locally. Access it via http://localhost:8000. ```bash cd docs ./view_docs.sh ``` -------------------------------- ### Run Interactive Demo Source: https://github.com/fabiognr/pyytlounge/blob/master/README.md Execute the interactive demo script for the pyytlounge library. ```bash python test.py ``` -------------------------------- ### Activate Virtual Environment Source: https://github.com/fabiognr/pyytlounge/blob/master/README.md Activate the created virtual environment. The command differs based on your operating system. ```bash source .venv/bin/activate ``` -------------------------------- ### Connect to Screen Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Establish a connection to the screen after successful pairing and authentication. This prepares the API for sending commands. ```python connected = await api.connect() ``` -------------------------------- ### Initialize YtLoungeApi with Async Context Manager Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Create an instance of YtLoungeApi using an asynchronous context manager. This ensures proper cleanup of the aiohttp session upon exiting the block. ```python async with YtLoungeApi('Test client') as api: ... ``` -------------------------------- ### Create Virtual Environment Source: https://github.com/fabiognr/pyytlounge/blob/master/README.md Create a new virtual environment for the project using Python's venv module. ```bash python -m venv .venv ``` -------------------------------- ### Pair with Screen using Pairing Code Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Pair the API instance with a screen using a pairing code obtained from the app's settings. This establishes a linked state with the screen. ```python pairing_code = input("Enter pairing code: ") # or from another source paired_and_linked = await api.pair(pairing_code) ``` -------------------------------- ### Migrate to Event Listener (v3.x.x) Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/updating.md Before updating, use a direct callback function for event subscriptions. After updating, subclass EventListener and override methods for specific event types. ```python async def receive_state(state: PlaybackState): print(f"New state: {state}") await api.subscribe(receive_state) ``` ```python from pyytlounge import EventListener class CustomListener(EventListener): def __init__(self): self.last_video_id: Optional[str] = None async def playback_state_changed(self, event: PlaybackStateEvent) -> None: """Called when playback state changes (position, play/pause)""" print( f"New state: {event.state} = id: {self.last_video_id} pos: {event.current_time} duration: {event.duration}" ) async def now_playing_changed(self, event: NowPlayingEvent) -> None: """Called when active video changes""" print( f"New state: {event.state} = id: {event.video_id} pos: {event.current_time} duration: {event.duration}" ) self.last_video_id = event.video_id with YtLoungeApi("Some device", CustomListener()) as api: ... await api.subscribe() ``` -------------------------------- ### Initialize YtLoungeApi Manually Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Initialize YtLoungeApi and manually close the session. This alternative method requires explicit calling of the .close() method. ```python api = YtLoungeApi('test client') ... await api.close() ``` -------------------------------- ### Subscribe to Screen Status Updates Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Subscribe to real-time status updates from the screen, such as changes in the currently playing video. The subscription blocks until it ends. ```python class YtListener(EventListener): async def now_playing_changed(self, event: NowPlayingEvent) -> None: """Called when active video changes""" print( f"New state: {event.state} = id: {event.video_id} pos: {event.current_time} duration: {event.duration}" ) listener = YtListener() async with YtLoungeApi('Test client', listener) as api: # this will block until the subscription ends subscribed = await api.subscribe() ``` -------------------------------- ### Refresh Authentication Token Source: https://github.com/fabiognr/pyytlounge/blob/master/docs/usage.md Refresh the lounge ID token if it has changed. This ensures continued access to the screen's services. ```python linked = await api.refresh_auth() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.