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.3.tar.gz
(11.4 kB
view hashes)
Built Distribution
Close
Hashes for mopidy-async-client-0.6.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b829dba5b356faee4ffc632fc0999da3cb1348dc339e2c2b7aabff477d9d07b |
|
MD5 | c45dfae548db314049dc5e616e87b818 |
|
BLAKE2b-256 | 68e08418a089933ad253cd0908ba8a99cb3921daea0fd0a1da20001ea5c3736a |
Close
Hashes for mopidy_async_client-0.6.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3488abc78f3ebd5da83983baaa1224a202bc15b08534ae169eb67b2ec256b44d |
|
MD5 | eb3b7afab40148fc908803228d035d9c |
|
BLAKE2b-256 | 1729b56de62dd41cd17ed830d10f274ac711b7d8ea0e409b7c94e4ccd626df0b |