From 50cce23d822841550677794796b5b51c606b73fa Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 23 Mar 2013 20:46:43 +0100 Subject: [PATCH] mpris: Add artUrl support --- docs/changes.rst | 4 ++++ mopidy/frontends/mpris/objects.py | 4 ++++ .../frontends/mpris/player_interface_test.py | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/docs/changes.rst b/docs/changes.rst index 4e0a9639..92f52356 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -20,6 +20,10 @@ v0.13.0 (in development) - Upgrade Mopidy.js' dependencies when.js from 1.6.1 to 1.8.1. +**MPRIS frontend** + +- Publish album art URIs if available. + v0.12.0 (2013-03-12) ==================== diff --git a/mopidy/frontends/mpris/objects.py b/mopidy/frontends/mpris/objects.py index 15ef9383..4c72a85b 100644 --- a/mopidy/frontends/mpris/objects.py +++ b/mopidy/frontends/mpris/objects.py @@ -375,6 +375,10 @@ class MprisObject(dbus.service.Object): artists.sort(key=lambda a: a.name) metadata['xesam:albumArtist'] = dbus.Array( [a.name for a in artists if a.name], signature='s') + if track.album and track.album.images: + url = list(track.album.images)[0] + if url: + metadata['mpris:artUrl'] = url if track.track_no: metadata['xesam:trackNumber'] = track.track_no return dbus.Dictionary(metadata, signature='sv') diff --git a/tests/frontends/mpris/player_interface_test.py b/tests/frontends/mpris/player_interface_test.py index c48ffa98..5832c710 100644 --- a/tests/frontends/mpris/player_interface_test.py +++ b/tests/frontends/mpris/player_interface_test.py @@ -200,6 +200,30 @@ class PlayerInterfaceTest(unittest.TestCase): self.assertIn('xesam:albumArtist', result.keys()) self.assertEqual(result['xesam:albumArtist'], ['a', 'b']) + def test_get_metadata_use_first_album_image_as_art_url(self): + # XXX Currently, the album image order isn't preserved because they + # are stored as a frozenset(). We pick the first in the set, which is + # sorted alphabetically, thus we get 'bar.jpg', not 'foo.jpg', which + # would probably make more sense. + self.core.tracklist.add([Track(album=Album(images=[ + 'http://example.com/foo.jpg', 'http://example.com/bar.jpg']))]) + self.core.playback.play() + result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') + self.assertIn('mpris:artUrl', result.keys()) + self.assertEqual(result['mpris:artUrl'], 'http://example.com/bar.jpg') + + def test_get_metadata_has_no_art_url_if_no_album(self): + self.core.tracklist.add([Track()]) + self.core.playback.play() + result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') + self.assertNotIn('mpris:artUrl', result.keys()) + + def test_get_metadata_has_no_art_url_if_no_album_images(self): + self.core.tracklist.add([Track(Album(images=[]))]) + self.core.playback.play() + result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') + self.assertNotIn('mpris:artUrl', result.keys()) + def test_get_metadata_has_track_number_in_album(self): self.core.tracklist.add([Track(track_no=7)]) self.core.playback.play()