Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpd: support short form of list command for albums #3215

Merged
merged 2 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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