added next, previous and current songpos to backends
This commit is contained in:
parent
c22fd44760
commit
0606d82e69
@ -10,6 +10,9 @@ class BaseBackend(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Status methods
|
# Status methods
|
||||||
|
def status_consume(self):
|
||||||
|
return 0
|
||||||
|
|
||||||
def status_volume(self):
|
def status_volume(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -22,7 +25,7 @@ class BaseBackend(object):
|
|||||||
def status_single(self):
|
def status_single(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def status_consume(self):
|
def status_song_id(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def status_playlist(self):
|
def status_playlist(self):
|
||||||
@ -38,6 +41,9 @@ class BaseBackend(object):
|
|||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
# Control methods
|
# Control methods
|
||||||
|
def next(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
self.state = self.PAUSE
|
self.state = self.PAUSE
|
||||||
|
|
||||||
@ -47,6 +53,9 @@ class BaseBackend(object):
|
|||||||
def play_id(self, songid):
|
def play_id(self, songid):
|
||||||
self.state = self.PLAY
|
self.state = self.PLAY
|
||||||
|
|
||||||
|
def previous(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
self.state = self.PLAY
|
self.state = self.PLAY
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,23 @@ class SpotifyBackend(BaseBackend):
|
|||||||
self._x_current_playlist_version = 0
|
self._x_current_playlist_version = 0
|
||||||
return self._x_current_playlist_version
|
return self._x_current_playlist_version
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _current_song_id(self):
|
||||||
|
if not hasattr(self, '_x_current_song_id'):
|
||||||
|
self._x_current_song_id = 0
|
||||||
|
return self._x_current_song_id
|
||||||
|
|
||||||
|
@_current_song_id.setter
|
||||||
|
def _current_song_id(self, songid):
|
||||||
|
if (self._current_playlist is None
|
||||||
|
or len(self._current_playlist) == 0
|
||||||
|
or songid < 0):
|
||||||
|
self._x_current_song_id = 0
|
||||||
|
elif songid >= len(self._current_playlist):
|
||||||
|
self._x_current_song_id = len(self._current_playlist) - 1
|
||||||
|
else:
|
||||||
|
self._x_current_song_id = songid
|
||||||
|
|
||||||
def _format_playlist(self, playlist, pos_range=None):
|
def _format_playlist(self, playlist, pos_range=None):
|
||||||
if pos_range is None:
|
if pos_range is None:
|
||||||
pos_range = range(len(playlist))
|
pos_range = range(len(playlist))
|
||||||
@ -90,27 +107,46 @@ class SpotifyBackend(BaseBackend):
|
|||||||
return u', '.join(artist_names)
|
return u', '.join(artist_names)
|
||||||
|
|
||||||
|
|
||||||
### MPD handlers
|
# Control methods
|
||||||
|
def next(self):
|
||||||
def current_song(self):
|
self._current_song_id += 1
|
||||||
track = self.spotify.current_track
|
self.play_id(self._current_song_id)
|
||||||
if track is not None and self.state in (self.PLAY, self.PAUSE):
|
|
||||||
return self._format_track(track)
|
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
self.state = self.PAUSE
|
self.state = self.PAUSE
|
||||||
self.spotify.pause()
|
self.spotify.pause()
|
||||||
|
|
||||||
def play_pos(self, songpos):
|
def play_pos(self, songpos):
|
||||||
self.state = self.PLAY
|
self.play_id(songpos)
|
||||||
track = self._current_playlist[songpos]
|
|
||||||
self.spotify.play(track)
|
|
||||||
|
|
||||||
def play_id(self, songid):
|
def play_id(self, songid):
|
||||||
self.state = self.PLAY
|
self.state = self.PLAY
|
||||||
|
self._current_song_id = songid
|
||||||
track = self._current_playlist[songid]
|
track = self._current_playlist[songid]
|
||||||
self.spotify.play(track)
|
self.spotify.play(track)
|
||||||
|
|
||||||
|
def previous(self):
|
||||||
|
self._current_song_id -= 1
|
||||||
|
self.play_id(self._current_song_id)
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
self.state = self.PLAY
|
||||||
|
self.spotify.resume()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self.state is not self.STOP:
|
||||||
|
self.state = self.STOP
|
||||||
|
self.spotify.stop()
|
||||||
|
|
||||||
|
### MPD handlers
|
||||||
|
|
||||||
|
def current_song(self):
|
||||||
|
try:
|
||||||
|
track = self._current_playlist[self._current_song_id]
|
||||||
|
return self._format_track(track)
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
def playlist_load(self, name):
|
def playlist_load(self, name):
|
||||||
playlists = filter(lambda p: decode(p.name) == name, self._playlists)
|
playlists = filter(lambda p: decode(p.name) == name, self._playlists)
|
||||||
if playlists:
|
if playlists:
|
||||||
@ -141,19 +177,15 @@ class SpotifyBackend(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
return self._format_playlist(self._current_playlist)
|
return self._format_playlist(self._current_playlist)
|
||||||
|
|
||||||
def resume(self):
|
# Status methods
|
||||||
self.state = self.PLAY
|
|
||||||
self.spotify.resume()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.state = self.STOP
|
|
||||||
self.spotify.stop()
|
|
||||||
|
|
||||||
def status_playlist(self):
|
def status_playlist(self):
|
||||||
return self._current_playlist_version
|
return self._current_playlist_version
|
||||||
|
|
||||||
def status_playlist_length(self):
|
def status_playlist_length(self):
|
||||||
return len(self._current_playlist)
|
return len(self._current_playlist)
|
||||||
|
|
||||||
|
def status_song_id(self):
|
||||||
|
return self._current_song_id
|
||||||
|
|
||||||
def url_handlers(self):
|
def url_handlers(self):
|
||||||
return [u'spotify:', u'http://open.spotify.com/']
|
return [u'spotify:', u'http://open.spotify.com/']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user