Add support for returning lists of two-tuples since we dont have ordered dicts

This commit is contained in:
Stein Magnus Jodal 2009-12-25 22:45:51 +01:00
parent c4aef48915
commit c22fd44760
3 changed files with 28 additions and 24 deletions

View File

@ -68,20 +68,21 @@ class SpotifyBackend(BaseBackend):
pos_range = range(len(playlist))
tracks = []
for track, pos in zip(playlist, pos_range):
tracks.extend(self._format_track(track, pos))
tracks.append(self._format_track(track, pos))
return tracks
def _format_track(self, track, pos=0):
result = []
result.append(u'file: %s' % track.get_uri())
result.append(u'Time: %d' % (track.length // 1000))
result.append(u'Artist: %s' % self._format_artists(track.artists))
result.append(u'Title: %s' % decode(track.title))
result.append(u'Album: %s' % decode(track.album))
result.append(u'Track: %d/0' % track.tracknumber)
result.append(u'Date: %s' % track.year)
result.append(u'Pos: %d' % pos)
result.append(u'Id: %d' % pos)
result = [
('file', track.get_uri()),
('Time', (track.length // 1000)),
('Artist', self._format_artists(track.artists)),
('Title', decode(track.title)),
('Album', decode(track.album)),
('Track', '%d/0' % track.tracknumber),
('Date', track.year),
('Pos', pos),
('Id', pos),
]
return result
def _format_artists(self, artists):

View File

@ -332,17 +332,17 @@ class MpdHandler(object):
@register(r'^status$')
def _status(self):
return {
'volume': self.backend.status_volume(),
'repeat': self.backend.status_repeat(),
'random': self.backend.status_random(),
'single': self.backend.status_single(),
'consume': self.backend.status_consume(),
'playlist': self.backend.status_playlist(),
'playlistlength': self.backend.status_playlist_length(),
'xfade': self.backend.status_xfade(),
'state': self.backend.status_state(),
}
return [
('volume', self.backend.status_volume()),
('repeat', self.backend.status_repeat()),
('random', self.backend.status_random()),
('single', self.backend.status_single()),
('consume', self.backend.status_consume()),
('playlist', self.backend.status_playlist()),
('playlistlength', self.backend.status_playlist_length()),
('xfade', self.backend.status_xfade()),
('state', self.backend.status_state()),
]
@register(r'^swap (?P<songpos1>\d+) (?P<songpos2>\d+)$')
def _swap(self, songpos1, songpos2):

View File

@ -46,8 +46,11 @@ class MpdSession(asynchat.async_chat):
for line in response:
self.handle_response(line)
elif isinstance(response, dict):
for key, value in response.items():
self.send_response(u'%s: %s' % (key, value))
for item in response.items():
self.handle_response(item)
elif isinstance(response, tuple):
(key, value) = response
self.send_response(u'%s: %s' % (key, value))
elif response is not None:
self.send_response(response)