From a14f114d2aed2f45a41ca8809da095f684b6ca2d Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 9 Jan 2011 22:54:18 +0100 Subject: [PATCH] Fix crash for Spotify users with playlist folders --- docs/changes.rst | 4 ++++ mopidy/backends/libspotify/session_manager.py | 1 + mopidy/backends/libspotify/translator.py | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 624f7ef4..72e9217b 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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. diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py index 8a79088f..f736a40e 100644 --- a/mopidy/backends/libspotify/session_manager.py +++ b/mopidy/backends/libspotify/session_manager.py @@ -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, diff --git a/mopidy/backends/libspotify/translator.py b/mopidy/backends/libspotify/translator.py index 09303eda..4a42cf97 100644 --- a/mopidy/backends/libspotify/translator.py +++ b/mopidy/backends/libspotify/translator.py @@ -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)