Giter VIP home page Giter VIP logo

mopidy-json-client's People

Contributors

ismailof avatar joergrs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mopidy-json-client's Issues

mopidy-json-client don't work with mopidy 3.3.0

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 ?

Refactor the Listener events interface

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.

No 'now playing' event on Pi Musicbox

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.

Error reading responses mopidy 3.2

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):

Implement logging (debug) features

The code should implement basic logging

  • Change the remaining 'print' lines to logger.debug
  • Add useful debugging information
  • Add debug option in call to MopidyWSClient

Raise TimeoutException

At least at RequestManager level a timeout on a request should raise an exception. Not only returning None

error on adding Uris in tracklist

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)

No modules_2_0

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?

Don't expose Listener

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.

  • Remove the SimpleListener function
  • Do not import from mopidy's Corelistener.
  • Allowed events shall be added manually in code. Make it version aware.
  • Add a global event, to pass every event, suchs as on_event function currently does, with event name as a parameter.

Error while trying to launch demo_volume_gpio

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

Getting RequestTimeoutError after sending any command to mopidy

Problem description

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)

Solution

The traceback hints to the following line:

def _server_response(self, ws, message):

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!

Extend connection status information

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:

  • Connected
  • Disconnected
  • Reconnecting (and attemp number)

And other info such as WebSocket URL (ws_url)

Improve threading management

Currently the threading just works, but it seems a little bit messy.
Proper threading management should be done on requests, delayed responses and events.

Mopidy API version selectable

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

  1. Add option version when calling MopidyWSClient
  2. Check the server version using core.version to import the right/closest API version
  3. If the methods are not created automatically generate API using core.describe if (maybe this one is a bit over-ingenieried/not good idea)

ImportError: No module named websocket

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

Error if calling a method inside a callback function

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

Provide an event loop

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.

Manage connection with Mopidy server

Currently there is no connection/status management with mopidy server.

Several changes must be implemented:

  • Provide events: on_connect / on_disconnect to clients
  • Provide connect() / close() methods: Connect method may include websocket_url parameter

Improve formatting of data

Useful for demo.py and with debugging

  • Change common.py to formatter.py or similar
  • Make print-nice recursive
  • Automatically format mopidy models

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.