mpd:Update protocol version to 0.19

Since mpd 0.19, it has concatenated multiple values using
a ';' character. Mopidy has been using ', '. This makes mopidy
use a ';' for all artist-related values.

In mpd 0.18, multiple values were displayed as multiple lines in
the output, hence this change bumps the mpd protocol version to
0.19 to reflect the new behaviour.
This commit is contained in:
Mark Greenwood 2015-07-05 13:17:39 +01:00
parent 3b1b0dd2e9
commit 1e46e9a94d
2 changed files with 39 additions and 22 deletions

View File

@ -22,8 +22,8 @@ ENCODING = 'UTF-8'
#: The MPD protocol uses ``\n`` as line terminator.
LINE_TERMINATOR = '\n'
#: The MPD protocol version is 0.17.0.
VERSION = '0.17.0'
#: The MPD protocol version is 0.19.0.
VERSION = '0.19.0'
def load_protocol_modules():

View File

@ -37,7 +37,7 @@ def track_to_mpd_format(track, position=None, stream_title=None):
# TODO: only show length if not none, see:
# https://github.com/mopidy/mopidy/issues/923#issuecomment-79584110
('Time', track.length and (track.length // 1000) or 0),
('Artist', artists_to_mpd_format(track.artists)),
('Artist', concatenate_multiple_values(track.artists, 'name')),
('Title', track.name or ''),
('Album', track.album and track.album.name or ''),
]
@ -58,26 +58,37 @@ def track_to_mpd_format(track, position=None, stream_title=None):
result.append(('Id', tlid))
if track.album is not None and track.album.musicbrainz_id is not None:
result.append(('MUSICBRAINZ_ALBUMID', track.album.musicbrainz_id))
# FIXME don't use first and best artist?
# FIXME don't duplicate following code?
if track.album is not None and track.album.artists:
artists = artists_to_mpd_format(track.album.artists)
result.append(('AlbumArtist', artists))
artists = [
a for a in track.album.artists if a.musicbrainz_id is not None]
if artists:
result.append(
('MUSICBRAINZ_ALBUMARTISTID', artists[0].musicbrainz_id))
result.append(
('AlbumArtist',
concatenate_multiple_values(track.album.artists, 'name')))
musicbrainz_ids = concatenate_multiple_values(
track.album.artists, 'musicbrainz_id')
if musicbrainz_ids:
result.append(('MUSICBRAINZ_ALBUMARTISTID', musicbrainz_ids))
if track.artists:
artists = [a for a in track.artists if a.musicbrainz_id is not None]
if artists:
result.append(('MUSICBRAINZ_ARTISTID', artists[0].musicbrainz_id))
musicbrainz_ids = concatenate_multiple_values(
track.artists, 'musicbrainz_id')
if musicbrainz_ids:
result.append(('MUSICBRAINZ_ARTISTID', musicbrainz_ids))
if track.composers:
result.append(('Composer', artists_to_mpd_format(track.composers)))
result.append(
(
'Composer',
concatenate_multiple_values(track.composers, 'name')
)
)
if track.performers:
result.append(('Performer', artists_to_mpd_format(track.performers)))
result.append(
(
'Performer',
concatenate_multiple_values(track.performers, 'name')
)
)
if track.genre:
result.append(('Genre', track.genre))
@ -90,17 +101,23 @@ def track_to_mpd_format(track, position=None, stream_title=None):
return result
def artists_to_mpd_format(artists):
def concatenate_multiple_values(artists, attribute):
"""
Format track artists for output to MPD client.
Format track artist values for output to MPD client.
:param artists: the artists
:type track: array of :class:`mopidy.models.Artist`
:param attribute: the artist attribute to use
:type string
:rtype: string
"""
artists = list(artists)
artists.sort(key=lambda a: a.name)
return ', '.join([a.name for a in artists if a.name])
# Don't sort the values. MPD doesn't appear to (or if it does it's not
# strict alphabetical). If we just use them in the order in which they come
# in then the musicbrainz ids have a higher chance of staying in sync
return ';'.join(
getattr(a, attribute)
for a in artists if getattr(a, attribute, None) is not None
)
def tracks_to_mpd_format(tracks, start=0, end=None):