Rename all internal methods in SptifyBackend

This commit is contained in:
Stein Magnus Jodal 2009-12-25 18:40:39 +01:00
parent 9f3a5a2307
commit fb4215a292

View File

@ -18,70 +18,70 @@ class SpotifyBackend(BaseBackend):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SpotifyBackend, self).__init__(*args, **kwargs) super(SpotifyBackend, self).__init__(*args, **kwargs)
logger.info(u'Connecting to Spotify') logger.info(u'Connecting to Spotify')
self.spotify = spytify.Spytify(self.username, self.password) self.spotify = spytify.Spytify(self._username, self._password)
logger.info(u'Preloading data') logger.info(u'Preloading data')
self.playlists self._playlists
logger.info(u'Done preloading data') logger.debug(u'Done preloading data')
@property @property
def username(self): def _username(self):
username = encode(settings.SPOTIFY_USERNAME) username = encode(settings.SPOTIFY_USERNAME)
if not username: if not username:
sys.exit(u'Setting SPOTIFY_USERNAME is not set.') sys.exit(u'Setting SPOTIFY_USERNAME is not set.')
return username return username
@property @property
def password(self): def _password(self):
password = encode(settings.SPOTIFY_PASSWORD) password = encode(settings.SPOTIFY_PASSWORD)
if not password: if not password:
sys.exit(u'Setting SPOTIFY_PASSWORD is not set.') sys.exit(u'Setting SPOTIFY_PASSWORD is not set.')
return password return password
@property @property
def playlists(self): def _playlists(self):
if not hasattr(self, '_cached_playlists') or not self._cached_playlists: if not hasattr(self, '_x_playlists') or not self._x_playlists:
logger.debug(u'Caching stored playlists') logger.debug(u'Caching stored playlists')
self._cached_playlists = [] self._x_playlists = []
for playlist in self.spotify.stored_playlists: for playlist in self.spotify.stored_playlists:
self._cached_playlists.append(playlist) self._x_playlists.append(playlist)
return self._cached_playlists return self._x_playlists
@property @property
def current_playlist(self): def _current_playlist(self):
if not hasattr(self, '_current_playlist'): if not hasattr(self, '_x_current_playlist'):
self._current_playlist = [] self._x_current_playlist = []
return self._current_playlist return self._x_current_playlist
@_current_playlist.setter
def _current_playlist(self, tracks):
self._x_current_playlist = tracks
self._x_current_playlist_version += 1
@property @property
def current_playlist_version(self): def _current_playlist_version(self):
if not hasattr(self, '_current_playlist_version'): if not hasattr(self, '_x_current_playlist_version'):
self._current_playlist_version = 0 self._x_current_playlist_version = 0
return self._current_playlist_version return self._x_current_playlist_version
@current_playlist.setter
def current_playlist(self, tracks):
self._current_playlist = tracks
self._current_playlist_version += 1
### MPD handlers ### MPD handlers
def play_id(self, songid): def play_id(self, songid):
track = self.current_playlist[songid] track = self._current_playlist[songid]
self.spotify.play(track) self.spotify.play(track)
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:
self.current_playlist = playlists[0].tracks self._current_playlist = playlists[0].tracks
else: else:
self.current_playlist = [] self._current_playlist = []
def playlists_list(self): def playlists_list(self):
return [u'playlist: %s' % decode(p.name) for p in self.playlists] return [u'playlist: %s' % decode(p.name) for p in self._playlists]
def playlist_changes(self, songpos): def playlist_changes(self, songpos):
tracks = [] tracks = []
for i, track in enumerate(self.current_playlist): for i, track in enumerate(self._current_playlist):
tracks.append(u'file: %s' % decode(track.track_id)) tracks.append(u'file: %s' % decode(track.track_id))
tracks.append(u'Time: %d' % (track.length // 1000)) tracks.append(u'Time: %d' % (track.length // 1000))
tracks.append(u'Artist: %s' % decode(track.artists[0].name)) tracks.append(u'Artist: %s' % decode(track.artists[0].name))
@ -96,10 +96,10 @@ class SpotifyBackend(BaseBackend):
self.spotify.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 url_handlers(self): def url_handlers(self):
return [u'spotify:', u'http://open.spotify.com/'] return [u'spotify:', u'http://open.spotify.com/']