Add empty handler methods for enough MPD commands to get Sonata to 'connected' mode
This commit is contained in:
parent
ecd5e686f6
commit
15b5968d5c
56
mopidy/handler.py
Normal file
56
mopidy/handler.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
from mopidy import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger('handler')
|
||||||
|
|
||||||
|
class MpdHandler(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.request_handlers = [
|
||||||
|
(r'^currentsong$', self._currentsong),
|
||||||
|
(r'^listplaylists$', self._listplaylists),
|
||||||
|
(r'^lsinfo( "(?P<uri>[^"]*)")*$', self._lsinfo),
|
||||||
|
(r'^ping$', self._ping),
|
||||||
|
(r'^plchanges "(?P<version>\d+)"$', self._plchanges),
|
||||||
|
(r'^status$', self._status),
|
||||||
|
]
|
||||||
|
|
||||||
|
def handle_request(self, request):
|
||||||
|
for request_pattern, request_handling_method in self.request_handlers:
|
||||||
|
matches = re.match(request_pattern, request)
|
||||||
|
if matches is not None:
|
||||||
|
groups = matches.groupdict()
|
||||||
|
return request_handling_method(**groups)
|
||||||
|
logger.warning(u'Unhandled request: %s', request)
|
||||||
|
|
||||||
|
def _currentsong(self):
|
||||||
|
return None # TODO
|
||||||
|
|
||||||
|
def _listplaylists(self):
|
||||||
|
return None # TODO
|
||||||
|
|
||||||
|
def _lsinfo(self, uri):
|
||||||
|
if uri == u'/':
|
||||||
|
return self._listplaylists()
|
||||||
|
return None # TODO
|
||||||
|
|
||||||
|
def _ping(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _plchanges(self, version):
|
||||||
|
return None # TODO
|
||||||
|
|
||||||
|
def _status(self):
|
||||||
|
# TODO
|
||||||
|
return [
|
||||||
|
'volume: 0',
|
||||||
|
'repeat: 0',
|
||||||
|
'random: 0',
|
||||||
|
'single: 0',
|
||||||
|
'consume: 0',
|
||||||
|
'playlist: 0',
|
||||||
|
'playlistlength: 0',
|
||||||
|
'xfade: 0',
|
||||||
|
'state: stop',
|
||||||
|
]
|
||||||
@ -2,14 +2,16 @@ import asynchat
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from mopidy import get_version, settings
|
from mopidy import get_version, settings
|
||||||
|
from mopidy.handler import MpdHandler
|
||||||
|
|
||||||
logger = logging.getLogger(u'session')
|
logger = logging.getLogger(u'session')
|
||||||
|
|
||||||
class MpdSession(asynchat.async_chat):
|
class MpdSession(asynchat.async_chat):
|
||||||
def __init__(self, client_socket, client_address):
|
def __init__(self, client_socket, client_address, handler=MpdHandler):
|
||||||
asynchat.async_chat.__init__(self, sock=client_socket)
|
asynchat.async_chat.__init__(self, sock=client_socket)
|
||||||
self.input_buffer = []
|
self.input_buffer = []
|
||||||
self.set_terminator(settings.MPD_LINE_TERMINATOR)
|
self.set_terminator(settings.MPD_LINE_TERMINATOR)
|
||||||
|
self.handler = handler()
|
||||||
self.send_response(u'OK MPD (mopidy %s)' % get_version())
|
self.send_response(u'OK MPD (mopidy %s)' % get_version())
|
||||||
|
|
||||||
def collect_incoming_data(self, data):
|
def collect_incoming_data(self, data):
|
||||||
@ -23,7 +25,11 @@ class MpdSession(asynchat.async_chat):
|
|||||||
self.handle_request(input)
|
self.handle_request(input)
|
||||||
|
|
||||||
def handle_request(self, input):
|
def handle_request(self, input):
|
||||||
pass # TODO
|
response = self.handler.handle_request(input)
|
||||||
|
if response is not None:
|
||||||
|
for line in response:
|
||||||
|
self.send_response(line)
|
||||||
|
self.send_response(u'OK')
|
||||||
|
|
||||||
def send_response(self, output):
|
def send_response(self, output):
|
||||||
logger.debug(u'Output: %s', output)
|
logger.debug(u'Output: %s', output)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user