diff --git a/docs/changelog.rst b/docs/changelog.rst index ac0531a7..941dcd7c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -44,6 +44,12 @@ Models reuse instances. For the test data set this was developed against, a library of ~14000 tracks, went from needing ~75MB to ~17MB. (Fixes: :issue:`348`) +MPD frontend +------------ + +- The MPD command ``count`` now ignores tracks with no length, which would + previously cause a :exc:`TypeError`. (PR: :issue:`1192`) + Utils ----- diff --git a/mopidy/mpd/protocol/music_db.py b/mopidy/mpd/protocol/music_db.py index 510d3ac1..1b3a3ee7 100644 --- a/mopidy/mpd/protocol/music_db.py +++ b/mopidy/mpd/protocol/music_db.py @@ -105,7 +105,7 @@ def count(context, *args): result_tracks = _get_tracks(results) return [ ('songs', len(result_tracks)), - ('playtime', sum(track.length for track in result_tracks) / 1000), + ('playtime', sum(t.length for t in result_tracks if t.length) / 1000), ] diff --git a/tests/mpd/protocol/test_music_db.py b/tests/mpd/protocol/test_music_db.py index 73c3b300..acdfbe13 100644 --- a/tests/mpd/protocol/test_music_db.py +++ b/tests/mpd/protocol/test_music_db.py @@ -79,6 +79,16 @@ class MusicDatabaseHandlerTest(protocol.BaseTestCase): self.assertInResponse('playtime: 650') self.assertInResponse('OK') + def test_count_with_track_length_none(self): + self.backend.library.dummy_find_exact_result = SearchResult( + tracks=[ + Track(uri='dummy:b', date="2001", length=None), + ]) + self.send_request('count "date" "2001"') + self.assertInResponse('songs: 1') + self.assertInResponse('playtime: 0') + self.assertInResponse('OK') + def test_findadd(self): self.backend.library.dummy_find_exact_result = SearchResult( tracks=[Track(uri='dummy:a', name='A')])