mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
bpd: support short form of list command for albums
Some clients list the albums belonging to an artist by issuing the command `list album <ARTIST NAME>`. This change inserts the tag `artist` before the artist name so that this succeeds. Fixes #3007
This commit is contained in:
parent
818f5bd07b
commit
9182f18e6f
2 changed files with 27 additions and 2 deletions
|
|
@ -1404,16 +1404,31 @@ class Server(BaseServer):
|
||||||
filtered by matching match_tag to match_term.
|
filtered by matching match_tag to match_term.
|
||||||
"""
|
"""
|
||||||
show_tag_canon, show_key = self._tagtype_lookup(show_tag)
|
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)
|
query = self._metadata_query(dbcore.query.MatchQuery, None, kv)
|
||||||
|
|
||||||
clause, subvals = query.clause()
|
clause, subvals = query.clause()
|
||||||
statement = 'SELECT DISTINCT ' + show_key + \
|
statement = 'SELECT DISTINCT ' + show_key + \
|
||||||
' FROM items WHERE ' + clause + \
|
' FROM items WHERE ' + clause + \
|
||||||
' ORDER BY ' + show_key
|
' ORDER BY ' + show_key
|
||||||
|
self._log.debug(statement)
|
||||||
with self.lib.transaction() as tx:
|
with self.lib.transaction() as tx:
|
||||||
rows = tx.query(statement, subvals)
|
rows = tx.query(statement, subvals)
|
||||||
|
|
||||||
for row in rows:
|
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])
|
yield show_tag_canon + u': ' + six.text_type(row[0])
|
||||||
|
|
||||||
def cmd_count(self, conn, tag, value):
|
def cmd_count(self, conn, tag, value):
|
||||||
|
|
|
||||||
|
|
@ -774,11 +774,21 @@ class BPDDatabaseTest(BPDTestHelper):
|
||||||
with self.run_bpd() as client:
|
with self.run_bpd() as client:
|
||||||
responses = client.send_commands(
|
responses = client.send_commands(
|
||||||
('list', 'album'),
|
('list', 'album'),
|
||||||
('list', 'track'))
|
('list', 'track'),
|
||||||
self._assert_ok(*responses)
|
('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('Album Title', responses[0].data['Album'])
|
||||||
self.assertEqual(['1', '2'], responses[1].data['Track'])
|
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):
|
def test_cmd_lsinfo(self):
|
||||||
with self.run_bpd() as client:
|
with self.run_bpd() as client:
|
||||||
response1 = client.send_command('lsinfo')
|
response1 = client.send_command('lsinfo')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue