Skip to content

Commit

Permalink
Merge pull request #1230 from fatg3erman/feature/mpd-protocol-extensions
Browse files Browse the repository at this point in the history
mpd: Add additional metadata fields for album URIs and image URIs
  • Loading branch information
adamcik committed Jul 27, 2015
2 parents 3810089 + 9649dc0 commit 2faf668
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ MPD frontend
- Exclude empty tags fields from metadata output. (Fixes: :issue:`1045`, PR:
:issue:`1235`)

- Implement protocol extensions to output Album URIs and Album Images when
outputting track data to clients. (PR: :issue:`1230`)

Stream backend
--------------

Expand Down
2 changes: 2 additions & 0 deletions mopidy/mpd/protocol/tagtype_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
'MUSICBRAINZ_ALBUMID',
'MUSICBRAINZ_ALBUMARTISTID',
'MUSICBRAINZ_TRACKID',
'X-AlbumUri',
'X-AlbumImage',
]
6 changes: 6 additions & 0 deletions mopidy/mpd/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def track_to_mpd_format(track, position=None, stream_title=None):
if track.musicbrainz_id is not None:
result.append(('MUSICBRAINZ_TRACKID', track.musicbrainz_id))

if track.album and track.album.uri:
result.append(('X-AlbumUri', track.album.uri))
if track.album and track.album.images:
images = ';'.join(i for i in track.album.images if i is not '')
result.append(('X-AlbumImage', images))

result = [element for element in result if _has_value(*element)]

return result
Expand Down
7 changes: 5 additions & 2 deletions tests/mpd/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class TrackMpdFormatTest(unittest.TestCase):
name='a name',
album=Album(
name='an album', num_tracks=13,
artists=[Artist(name='an other artist')]),
artists=[Artist(name='an other artist')],
uri='urischeme:album:12345', images=['image1']),
track_no=7,
composers=[Artist(name='a composer')],
performers=[Artist(name='a performer')],
Expand Down Expand Up @@ -76,8 +77,10 @@ def test_track_to_mpd_format_for_nonempty_track(self):
self.assertIn(('Disc', 1), result)
self.assertIn(('Pos', 9), result)
self.assertIn(('Id', 122), result)
self.assertIn(('X-AlbumUri', 'urischeme:album:12345'), result)
self.assertIn(('X-AlbumImage', 'image1'), result)
self.assertNotIn(('Comment', 'a comment'), result)
self.assertEqual(len(result), 14)
self.assertEqual(len(result), 16)

def test_track_to_mpd_format_with_last_modified(self):
track = self.track.replace(last_modified=995303899000)
Expand Down

0 comments on commit 2faf668

Please sign in to comment.