mpd: Ignore tracks without length in the "count" command
This commit is contained in:
parent
10b0796bbd
commit
feb9963a8e
@ -44,6 +44,12 @@ Models
|
|||||||
reuse instances. For the test data set this was developed against, a library
|
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`)
|
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
|
Utils
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,7 @@ def count(context, *args):
|
|||||||
result_tracks = _get_tracks(results)
|
result_tracks = _get_tracks(results)
|
||||||
return [
|
return [
|
||||||
('songs', len(result_tracks)),
|
('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),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -79,6 +79,16 @@ class MusicDatabaseHandlerTest(protocol.BaseTestCase):
|
|||||||
self.assertInResponse('playtime: 650')
|
self.assertInResponse('playtime: 650')
|
||||||
self.assertInResponse('OK')
|
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):
|
def test_findadd(self):
|
||||||
self.backend.library.dummy_find_exact_result = SearchResult(
|
self.backend.library.dummy_find_exact_result = SearchResult(
|
||||||
tracks=[Track(uri='dummy:a', name='A')])
|
tracks=[Track(uri='dummy:a', name='A')])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user