Fix crash for Spotify users with playlist folders

This commit is contained in:
Stein Magnus Jodal 2011-01-09 22:54:18 +01:00
parent 85d4dde338
commit a14f114d2a
3 changed files with 21 additions and 6 deletions

View File

@ -21,6 +21,10 @@ No description yet.
- Support high bitrate (320k) audio. See
:attr:`mopidy.settings.SPOTIFY_HIGH_BITRATE` for details.
- Catch and log error caused by playlist folder boundaries being threated as
normal playlists. More permanent fix requires support for checking playlist
types in pyspotify.
- Last.fm frontend:
- If you use the Last.fm frontend, you need to upgrade to pylast 0.5.

View File

@ -54,6 +54,7 @@ class LibspotifySessionManager(SpotifySessionManager, BaseThread):
for spotify_playlist in session.playlist_container():
playlists.append(
LibspotifyTranslator.to_mopidy_playlist(spotify_playlist))
playlists = filter(None, playlists)
self.core_queue.put({
'command': 'set_stored_playlists',
'playlists': playlists,

View File

@ -1,11 +1,14 @@
import datetime as dt
import logging
from spotify import Link
from spotify import Link, SpotifyError
from mopidy import settings
from mopidy.backends.libspotify import ENCODING
from mopidy.models import Artist, Album, Track, Playlist
logger = logging.getLogger('mopidy.backends.libspotify.translator')
class LibspotifyTranslator(object):
@classmethod
def to_mopidy_artist(cls, spotify_artist):
@ -47,8 +50,15 @@ class LibspotifyTranslator(object):
def to_mopidy_playlist(cls, spotify_playlist):
if not spotify_playlist.is_loaded():
return Playlist(name=u'[loading...]')
return Playlist(
uri=str(Link.from_playlist(spotify_playlist)),
name=spotify_playlist.name().decode(ENCODING),
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist],
)
# 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.
try:
return Playlist(
uri=str(Link.from_playlist(spotify_playlist)),
name=spotify_playlist.name().decode(ENCODING),
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist],
)
except SpotifyError, e:
logger.warning(u'Failed translating Spotify playlist '
'(probably a playlist folder boundary): %s', e)