Skip to content

Commit

Permalink
mpd: Ignore tracks without length in the "count" command
Browse files Browse the repository at this point in the history
  • Loading branch information
Naglis Jonaitis committed May 27, 2015
1 parent 10b0796 commit feb9963
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down
2 changes: 1 addition & 1 deletion mopidy/mpd/protocol/music_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]


Expand Down
10 changes: 10 additions & 0 deletions tests/mpd/protocol/test_music_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def test_count_correct_length(self):
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')])
Expand Down

0 comments on commit feb9963

Please sign in to comment.