Async Mopidy Client via JSON/RPC Websocket interface
Project description
Mopidy-Async-Client
Fork of Mopidy-json-client, but from scratch and async
Async Mopidy Client via JSON/RPC Websocket interface
Usage
mopidy-async-client provides a main class MopidyClient
, which manages the connection and methods to the Mopidy Server.
import asyncio
from mopidy_async_client import MopidyClient
async def playback_started_handler(data):
print(data)
async def all_events_handler(event, data):
print(event, data)
async def main1():
async with MopidyClient(url='ws://some_ip:6680/mopidy/ws') as mopidy: # close connection explicit
await mopidy.playback.play()
async def main2():
mopidy = await MopidyClient().connect()
mopidy.listener.bind('track_playback_started', playback_started_handler)
mopidy.listener.bind('*', all_events_handler)
# your app logic
for i in range(10):
await asyncio.sleep(5)
# end your app logic
await mopidy.disconnect() # close connection implicit
asyncio.run(main1())
# or
asyncio.run(main2())
Parse results
You can specify parse_results=True
in MopidyClient
and get Mopidy objects instead of json dictionaries.
To do this, you need to install Mopidy locally (only for importing models)
async with MopidyClient(parse_results=True) as mopidy:
res = await mopidy.tracklist.get_tracks()
print(res)
>>> [Track(date='2020-01-01', length=392533, name='audio.mp3', uri='file:///home/svin/Music/audio.mp3')]
# instead of
>>> [{'__model__': 'Track', 'uri': 'file:///home/svin/Music/audio.mp3', 'name': 'audio.mp3', 'date': '2020-01-01', 'length': 392533}]
Installation
pip install mopidy-async-client
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mopidy-async-client-0.6.2.tar.gz
(11.3 kB
view hashes)
Built Distribution
Close
Hashes for mopidy-async-client-0.6.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f528d6be004ad4082e149ffd8ac2e21d912f5d5ef89cf34a1c562378bfc09aab |
|
MD5 | b610ff0c2a0af85f33b170019a10de3d |
|
BLAKE2b-256 | 4426c404d0f228c0921e793176f7ac375c1ec67dc3152eff1d0e4de05e96ad5a |
Close
Hashes for mopidy_async_client-0.6.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb50bc224fc8b5bf6b735c6b6b9f599970595e975fe95b836fff417294b30971 |
|
MD5 | 19a3964ac54497f8f55e3b0a40279c99 |
|
BLAKE2b-256 | 37d0e5cb9200fd580bbc502e73dfc929c5ba82676f30521639c76f140d72d7cd |