Merge pull request #3215 from arcresu/bpd-compat

bpd: support short form of list command for albums
This commit is contained in:
Carl Suster 2019-04-15 13:39:23 +10:00 committed by GitHub
commit 7b910c3fde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -1404,16 +1404,31 @@ class Server(BaseServer):
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):

View file

@ -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

View file

@ -774,11 +774,21 @@ class BPDDatabaseTest(BPDTestHelper):
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')