Skip to content

Commit

Permalink
Merge pull request #3215 from arcresu/bpd-compat
Browse files Browse the repository at this point in the history
bpd: support short form of list command for albums
  • Loading branch information
arcresu authored Apr 15, 2019
2 parents 818f5bd + 7ddde2a commit 7b910c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
15 changes: 15 additions & 0 deletions beetsplug/bpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,16 +1404,31 @@ def cmd_list(self, conn, show_tag, *kv):
filtered by matching match_tag to match_term.
"""
show_tag_canon, show_key = self._tagtype_lookup(show_tag)
if len(kv) == 1:
if show_tag_canon == 'Album':
# If no tag was given, assume artist. This is because MPD
# supports a short version of this command for fetching the
# albums belonging to a particular artist, and some clients
# rely on this behaviour (e.g. MPDroid, M.A.L.P.).
kv = ('Artist', kv[0])
else:
raise BPDError(ERROR_ARG, u'should be "Album" for 3 arguments')
elif len(kv) % 2 != 0:
raise BPDError(ERROR_ARG, u'Incorrect number of filter arguments')
query = self._metadata_query(dbcore.query.MatchQuery, None, kv)

clause, subvals = query.clause()
statement = 'SELECT DISTINCT ' + show_key + \
' FROM items WHERE ' + clause + \
' ORDER BY ' + show_key
self._log.debug(statement)
with self.lib.transaction() as tx:
rows = tx.query(statement, subvals)

for row in rows:
if not row[0]:
# Skip any empty values of the field.
continue
yield show_tag_canon + u': ' + six.text_type(row[0])

def cmd_count(self, conn, tag, value):
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ Fixes:
:bug:`3207` :bug:`2752`
* Fix an unhandled exception when pruning empty directories.
:bug:`1996` :bug:`3209`
* :doc:`/plugins/bpd`: Fix a crash triggered when certain clients tried to list
the albums belonging to a particular artist.
:bug:`3007` :bug:`3215`

.. _python-itunes: https://github.com/ocelma/python-itunes

Expand Down
14 changes: 12 additions & 2 deletions test/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,21 @@ def test_cmd_list(self):
with self.run_bpd() as client:
responses = client.send_commands(
('list', 'album'),
('list', 'track'))
self._assert_ok(*responses)
('list', 'track'),
('list', 'album', 'artist', 'Artist Name', 'track'))
self._assert_failed(responses, bpd.ERROR_ARG, pos=2)
self.assertEqual('Album Title', responses[0].data['Album'])
self.assertEqual(['1', '2'], responses[1].data['Track'])

def test_cmd_list_three_arg_form(self):
with self.run_bpd() as client:
responses = client.send_commands(
('list', 'album', 'artist', 'Artist Name'),
('list', 'album', 'Artist Name'),
('list', 'track', 'Artist Name'))
self._assert_failed(responses, bpd.ERROR_ARG, pos=2)
self.assertEqual(responses[0].data, responses[1].data)

def test_cmd_lsinfo(self):
with self.run_bpd() as client:
response1 = client.send_command('lsinfo')
Expand Down

0 comments on commit 7b910c3

Please sign in to comment.