-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f31d6f
commit 90e8499
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,57 @@ | ||
# Usage | ||
|
||
To use this package, import it: | ||
Here's an example of how to use the library to connect to a VLC instance: | ||
|
||
```python | ||
import aiovlc | ||
from aiovlc.client import Client | ||
from aiovlc.exceptions import AIOVLCError | ||
from aiovlc.model.command import Info, Status | ||
|
||
LOGGER = logging.getLogger("aiovlc") | ||
|
||
|
||
def run_client() -> None: | ||
"""Run a VLC client.""" | ||
LOGGER.info("Starting client") | ||
host = "localhost" | ||
password = "a1ve3ry4ha6rd7pas9wo1rd" | ||
port = 4212 | ||
try: | ||
asyncio.run(start_client(host, password, port)) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
LOGGER.info("Stopped client") | ||
|
||
|
||
async def start_client(host: str, password: str, port: int) -> None: | ||
"""Start the client.""" | ||
try: | ||
async with Client(password, host=host, port=port) as vlc_client: | ||
await vlc_client.login() | ||
await handle_client(vlc_client) | ||
except AIOVLCError as err: | ||
LOGGER.error("Error '%s'", err) | ||
|
||
|
||
async def handle_client(vlc_client: Client) -> None: | ||
"""Handle the client calls.""" | ||
while True: | ||
command = Status() | ||
output = await command.send(vlc_client) | ||
LOGGER.debug("Received: %s", output) | ||
info_command = Info() | ||
info_output = await info_command.send(vlc_client) | ||
LOGGER.debug("Received: %s", info_output) | ||
await asyncio.sleep(10) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_client() | ||
``` | ||
|
||
TODO: Document usage | ||
There's also a CLI to test the library. | ||
|
||
```sh | ||
aiovlc --debug client | ||
``` |