ismailof / mopidy-json-client Goto Github PK
View Code? Open in Web Editor NEWMopidy Client via JSON/RPC Websocket interface
License: Apache License 2.0
Mopidy Client via JSON/RPC Websocket interface
License: Apache License 2.0
The code exits with a WebSocket exception if mopidy is not running and available.
Reference use examples for diferent cases:
SimpleListener/MopidyListener
Hi !
I installed your software in the VM containing mopidy (3.3.0) but it seems to not work properly:
python3 now_playing.py
File "now_playing.py", line 9
print 'No Track'
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('No Track')?
Can you help me please ?
Currently the listener interface is not very user friendly to client users.
MopidyWSClient class should have a default Listener, where client users could register
It should allow to extend the listener with extra events (related to #3) including connection ones.
Installed and ran the now_playing example script on a Pi MusicBox. The log indicates it connects fine:
[CONNECTION] Connecting to Mopidy Server at ws://localhost:6680/mopidy/ws
[CONNECTION] Mopidy Server is connected at ws://localhost:6680/mopidy/ws
When I start playing via Spotify Connect or Airplay, no event is generated.
json client would not read any responses from mopidy 3.2
Running mopidy -v shows that requests are being received and processed OK, but the json client is not interpreting the result correctly.
I added websocket.enableTrace(True) to Client.py inside def _ws_connect(self): (just before line 112) to see the error which indicated the call to _server_response was missing a parameter.
Since this was a class method the fix was to change the method signature on Line 195
from: def _server_response(self, message):
to: def _server_response(self, ws, message):
The code should implement basic logging
At least at RequestManager level a timeout on a request should raise an exception. Not only returning None
When adding items in trackless with the add function and the Uris parameter. The deprecated parameter uri is still sent and cause an error in Mopidy :
Sent WebSocket message to 127.0.0.1: '{"jsonrpc": "2.0", "id": 1, "error": {"code": -32602, "message": "Invalid params", "data": {"type": "TypeError", "message": "add() got an unexpected keyword argument \'uri\'", "traceback": "Traceback (most recent call last):\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/mopidy/internal/jsonrpc.py\\", line 131, in _handle_single_request\\n result = self._unwrap_result(result)\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/mopidy/internal/jsonrpc.py\\", line 228, in _unwrap_result\\n result = result.get()\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/pykka/_threading.py\\", line 45, in get\\n _compat.reraise(*self._data[\'exc_info\'])\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/pykka/_compat/__init__.py\\", line 29, in reraise\\n raise value\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/pykka/_actor.py\\", line 193, in _actor_loop\\n response = self._handle_receive(envelope.message)\\n File \\"/usr/local/Cellar/mopidy/3.0.1/libexec/lib/python3.7/site-packages/pykka/_actor.py\\", line 299, in _handle_receive\\n return callee(*message.args, **message.kwargs)\\nTypeError: add() got an unexpected keyword argument \'uri\'\\n"}}}'
When removing the uri parameter in tracklist.py on line 112 everything works fine.
return self.mopidy_request('core.tracklist.add', tracks=tracks, at_position=at_position, uris=uris, **options)
I'm trying to run this code on a Mopidy server I'm involved in maintaining and I'm having a ModuleNotFound error that I can't seem to resolve:
Traceback (most recent call last):
File "cleartracks.py", line 4, in <module>
mopidy = MopidyClient(ws_url="URL_OF_THE_SERVER")
File "C:\Users\mvada\Documents\Anaconda\lib\site-packages\mopidy_json_client\client.py", line 244, in __init__
MopidyAPI.set_version(version)
File "C:\Users\mvada\Documents\Anaconda\lib\site-packages\mopidy_json_client\mopidy_api.py", line 21, in set_version
import methods_2_0 as methods
ModuleNotFoundError: No module named 'methods_2_0'
How do I resolve this issue?
MopidyListener and SimpleListener classes are hard to understand and have a very narrow use case.
Furthermore, it imports from mopidy which shouldn't be necessary for a remote client. Events will be added only using the bind_event function.
Hi,
when i try to launch your demo_volume_gpio i get the error
"ImportError: No module named gpio_controls"
Im pretty sure i have installed the RPI.GPIO libraries so i don't know what else i am missing.
Thanks
What are the attributes for server_request method?
I'm trying to do a play next/previous script in python.
Thanks for your work and support
I've struggled a bit with using mopidy-json-client to control mopidy over the network. Everytime I send a request (e.g., m.playback.play()
) the command obviously reached Mopidy (as I could hear it started to play), although, the call did not return normally but I got the following after 20 seconds:
Traceback (most recent call last):
File "mopidy-json-client/mopidy_json_client/client.py", line 188, in _server_request
server_result = request.wait_for_result()
File "mopidy-json-client/mopidy_json_client/messages.py", line 65, in wait_for_result
raise RequestTimeoutError(self.method, self.timeout)
RequestTimeoutError
It took me a while to figure out that I could use websocket.enableTrace(True)
to gain more information. I received the following message multiple times:
error from callback <bound method MopidyClient._server_response of <mopidy_json_client.client.MopidyClient object at 0x7f1e80b47e90>>: _server_response() takes exactly 3 arguments (2 given)
File "/home/jorg/.local/lib/python2.7/site-packages/websocket/_app.py", line 343, in _callback
callback(*args)
The traceback hints to the following line:
The unused argument ws
must be removed and everything works as expected :-)
I'm wondering why no one else has come across this problem so far (at least I couldn't find any complaints anywhere). But I'm happy to have solved it for myself and hopefully this is of use for other people.
Thanks for the great work on mopidy!
Currently, only the is_connected()
functions return boolean state
It would be useful for the clients (specially graphic) to know the state of the connection:
And other info such as WebSocket URL (ws_url)
Ping server using core.version to auto detect connection losses
Currently the threading just works, but it seems a little bit messy.
Proper threading management should be done on requests, delayed responses and events.
Altough JSON methods provided by Mopidy API haven't change in Mopidy 2.0, they will likely do in the near future. First, some refactor is needed to make it possible to switch between different APIs
Later, several options can be provided, in order of complexity/utility
version
when calling MopidyWSClientcore.version
to import the right/closest API versioncore.describe
if (maybe this one is a bit over-ingenieried/not good idea)Hi all,
after install the mopidy-json-client written in the readme description.
Using the simpe example below I got this fault on the CLI Ubuntu:
./mopidyevent.py
Traceback (most recent call last):
File "./mopidyevent.py", line 4, in
from mopidy_json_client import MopidyClient
File "/usr/local/lib/python2.7/dist-packages/mopidy_json_client/init.py", line 6, in
from .client import MopidyClient, SimpleClient
File "/usr/local/lib/python2.7/dist-packages/mopidy_json_client/client.py", line 5, in
import websocket
ImportError: No module named websocket
#!/usr/bin/python
import time
from mopidy_json_client import MopidyClient
def print_track_info(tl_track):
track = tl_track.get('track') if tl_track else None
if not track:
print 'No Track'
return
trackinfo = {
'name': track.get('name'),
'artists': ', '.join([artist.get('name') for artist in track.get('artists')])
}
print('Now playing: {artists} - {name}'.format(**trackinfo))
mopidy = MopidyClient()
mopidy.bind_event('track_playback_started', print_track_info)
if name == 'main':
# Main loop
try:
while True:
time.sleep(0.2)
except KeyboardInterrupt:
pass
An example of this happens in demo.py/options_changed()
It seems to be caused by a bad threading control. The solution is to modify the RequestManager
and MopidyWSClient
to use Threading
calls instead of manually blocking the thread inside a while
loop.
It should also improve the general request handling
Providing an event loop would help simple scripts aimed as event listeners. An stop funcion should also be included to stop the loop.
Easiest way is to use a simple while not stop_loop
. Threading wait would be preferible.
Currently there is no connection/status management with mopidy server.
Several changes must be implemented:
Useful for demo.py and with debugging
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.