Fix crash in lastfm frontend on tracks that does not contain the expected data

This commit is contained in:
Stein Magnus Jodal 2011-01-20 17:05:32 +01:00
parent b187e93440
commit 2992a81ce0
2 changed files with 8 additions and 6 deletions

View File

@ -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**

View File

@ -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 ''))