From 2992a81ce0090b690523fca72d0e2b3a06c6bb1d Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 20 Jan 2011 17:05:32 +0100 Subject: [PATCH] Fix crash in lastfm frontend on tracks that does not contain the expected data --- docs/changes.rst | 2 ++ mopidy/frontends/lastfm.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 86137c1a..326ae4af 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -46,6 +46,8 @@ No description yet. - Update to use Last.fm's new Scrobbling 2.0 API, as the old Submissions Protocol 1.2.1 is deprecated. (Fixes: :issue:`33`) + - Fix crash when track object does not contain all the expected meta data. + **Changes** diff --git a/mopidy/frontends/lastfm.py b/mopidy/frontends/lastfm.py index e2d58b1e..69d1c8bc 100644 --- a/mopidy/frontends/lastfm.py +++ b/mopidy/frontends/lastfm.py @@ -92,14 +92,14 @@ class LastfmFrontendThread(BaseThread): def started_playing(self, track): artists = ', '.join([a.name for a in track.artists]) - duration = track.length // 1000 + duration = track.length and track.length // 1000 or 0 self.last_start_time = int(time.time()) logger.debug(u'Now playing track: %s - %s', artists, track.name) try: self.lastfm.update_now_playing( artists, - track.name, - album=track.album.name, + (track.name or ''), + album=(track.album and track.album.name or ''), duration=str(duration), track_number=str(track.track_no), mbid=(track.musicbrainz_id or '')) @@ -108,7 +108,7 @@ class LastfmFrontendThread(BaseThread): def stopped_playing(self, track, stop_position): artists = ', '.join([a.name for a in track.artists]) - duration = track.length // 1000 + duration = track.length and track.length // 1000 or 0 stop_position = stop_position // 1000 if duration < 30: logger.debug(u'Track too short to scrobble. (30s)') @@ -123,9 +123,9 @@ class LastfmFrontendThread(BaseThread): try: self.lastfm.scrobble( artists, - track.name, + (track.name or ''), str(self.last_start_time), - album=track.album.name, + album=(track.album and track.album.name or ''), track_number=str(track.track_no), duration=str(duration), mbid=(track.musicbrainz_id or ''))