Merge pull request #136 from jodal/feature/pyspotify-1.5-support
Feature/pyspotify 1.5 support
This commit is contained in:
commit
26388f1797
@ -13,13 +13,15 @@ class SpotifyContainerManager(PyspotifyContainerManager):
|
||||
def container_loaded(self, container, userdata):
|
||||
"""Callback used by pyspotify"""
|
||||
logger.debug(u'Callback called: playlist container loaded')
|
||||
|
||||
self.session_manager.refresh_stored_playlists()
|
||||
|
||||
playlist_container = self.session_manager.session.playlist_container()
|
||||
for playlist in playlist_container:
|
||||
self.session_manager.playlist_manager.watch(playlist)
|
||||
logger.debug(u'Watching %d playlist(s) for changes',
|
||||
len(playlist_container))
|
||||
count = 0
|
||||
for playlist in self.session_manager.session.playlist_container():
|
||||
if playlist.type() == 'playlist':
|
||||
self.session_manager.playlist_manager.watch(playlist)
|
||||
count += 1
|
||||
logger.debug(u'Watching %d playlist(s) for changes', count)
|
||||
|
||||
def playlist_added(self, container, playlist, position, userdata):
|
||||
"""Callback used by pyspotify"""
|
||||
|
||||
@ -139,10 +139,8 @@ class SpotifySessionManager(BaseThread, PyspotifySessionManager):
|
||||
def refresh_stored_playlists(self):
|
||||
"""Refresh the stored playlists in the backend with fresh meta data
|
||||
from Spotify"""
|
||||
playlists = []
|
||||
for spotify_playlist in self.session.playlist_container():
|
||||
playlists.append(
|
||||
SpotifyTranslator.to_mopidy_playlist(spotify_playlist))
|
||||
playlists = map(SpotifyTranslator.to_mopidy_playlist,
|
||||
self.session.playlist_container())
|
||||
playlists = filter(None, playlists)
|
||||
self.backend.stored_playlists.playlists = playlists
|
||||
logger.debug(u'Refreshed %d stored playlist(s)', len(playlists))
|
||||
@ -164,4 +162,5 @@ class SpotifySessionManager(BaseThread, PyspotifySessionManager):
|
||||
def logout(self):
|
||||
"""Log out from spotify"""
|
||||
logger.debug(u'Logging out from Spotify')
|
||||
self.session.logout()
|
||||
if self.session:
|
||||
self.session.logout()
|
||||
|
||||
@ -51,9 +51,8 @@ class SpotifyTranslator(object):
|
||||
def to_mopidy_playlist(cls, spotify_playlist):
|
||||
if not spotify_playlist.is_loaded():
|
||||
return Playlist(name=u'[loading...]')
|
||||
# FIXME Replace this try-except with a check on the playlist type,
|
||||
# which is currently not supported by pyspotify, to avoid handling
|
||||
# playlist folder boundaries like normal playlists.
|
||||
if spotify_playlist.type() != 'playlist':
|
||||
return
|
||||
try:
|
||||
return Playlist(
|
||||
uri=str(Link.from_playlist(spotify_playlist)),
|
||||
@ -63,5 +62,4 @@ class SpotifyTranslator(object):
|
||||
if str(Link.from_track(t, 0))],
|
||||
)
|
||||
except SpotifyError, e:
|
||||
logger.info(u'Failed translating Spotify playlist '
|
||||
'(probably a playlist folder boundary): %s', e)
|
||||
logger.warning(u'Failed translating Spotify playlist: %s', e)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user