Replace not decodable characters returned from Spotify instead of crashing

This commit is contained in:
Stein Magnus Jodal 2011-06-02 18:38:11 +02:00
parent fc9875bf3d
commit 0e098e9b60
2 changed files with 7 additions and 4 deletions

View File

@ -26,6 +26,9 @@ No description yet.
- Improve :option:`--list-settings` output. (Fixes: :issue:`91`) - Improve :option:`--list-settings` output. (Fixes: :issue:`91`)
- Replace not decodable characters returned from Spotify instead of throwing an
exception, as we won't try to figure out the encoding of non-UTF-8-data.
v0.4.1 (2011-05-06) v0.4.1 (2011-05-06)
=================== ===================

View File

@ -16,7 +16,7 @@ class SpotifyTranslator(object):
return Artist(name=u'[loading...]') return Artist(name=u'[loading...]')
return Artist( return Artist(
uri=str(Link.from_artist(spotify_artist)), uri=str(Link.from_artist(spotify_artist)),
name=spotify_artist.name().decode(ENCODING), name=spotify_artist.name().decode(ENCODING, 'replace'),
) )
@classmethod @classmethod
@ -24,7 +24,7 @@ class SpotifyTranslator(object):
if spotify_album is None or not spotify_album.is_loaded(): if spotify_album is None or not spotify_album.is_loaded():
return Album(name=u'[loading...]') return Album(name=u'[loading...]')
# TODO pyspotify got much more data on albums than this # TODO pyspotify got much more data on albums than this
return Album(name=spotify_album.name().decode(ENCODING)) return Album(name=spotify_album.name().decode(ENCODING, 'replace'))
@classmethod @classmethod
def to_mopidy_track(cls, spotify_track): def to_mopidy_track(cls, spotify_track):
@ -38,7 +38,7 @@ class SpotifyTranslator(object):
date = None date = None
return Track( return Track(
uri=uri, uri=uri,
name=spotify_track.name().decode(ENCODING), name=spotify_track.name().decode(ENCODING, 'replace'),
artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()],
album=cls.to_mopidy_album(spotify_track.album()), album=cls.to_mopidy_album(spotify_track.album()),
track_no=spotify_track.index(), track_no=spotify_track.index(),
@ -57,7 +57,7 @@ class SpotifyTranslator(object):
try: try:
return Playlist( return Playlist(
uri=str(Link.from_playlist(spotify_playlist)), uri=str(Link.from_playlist(spotify_playlist)),
name=spotify_playlist.name().decode(ENCODING), name=spotify_playlist.name().decode(ENCODING, 'replace'),
# FIXME if check on link is a hackish workaround for is_local # FIXME if check on link is a hackish workaround for is_local
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist tracks=[cls.to_mopidy_track(t) for t in spotify_playlist
if str(Link.from_track(t, 0))], if str(Link.from_track(t, 0))],