Skip to content

Commit

Permalink
mpris plugin: Catch OverflowError when passing too large values to db…
Browse files Browse the repository at this point in the history
…us. Fixes #2698

Just use 0 in that case, not much we can do.
  • Loading branch information
lazka committed Jan 10, 2018
1 parent eda98b7 commit 4d251e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions quodlibet/quodlibet/ext/events/mpris/mpris2.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,25 @@ def __get_current_track_id(self):
return dbus.ObjectPath(path + "/" + str(id(app.player.info)))

def __get_metadata(self):
"""http://xmms2.org/wiki/MPRIS_Metadata"""
"""
https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/
"""

metadata = {}
metadata["mpris:trackid"] = self.__get_current_track_id()

def ignore_overflow(dbus_type, value):
try:
return dbus_type(value)
except OverflowError:
return 0

song = app.player.info
if not song:
return metadata

metadata["mpris:length"] = dbus.Int64(song("~#length") * 10 ** 6)
metadata["mpris:length"] = ignore_overflow(
dbus.Int64, song("~#length") * 10 ** 6)

self.__cover = cover = app.cover_manager.get_cover(song)
is_temp = False
Expand Down Expand Up @@ -270,10 +279,11 @@ def __get_metadata(self):
for xesam, tag in iteritems(num_val):
val = song("~#" + tag, None)
if val is not None:
metadata["xesam:" + xesam] = int(val)
metadata["xesam:" + xesam] = ignore_overflow(dbus.Int32, val)

# Rating
metadata["xesam:userRating"] = float(song("~#rating"))
metadata["xesam:userRating"] = ignore_overflow(
dbus.Double, song("~#rating"))

# Dates
ISO_8601_format = "%Y-%m-%dT%H:%M:%S"
Expand Down
4 changes: 3 additions & 1 deletion quodlibet/tests/plugin/test_mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
A2 = AudioFile(
{'album': u'greatness2\ufffe', 'title': 'superlative',
'artist': u'fooman\ufffe', '~#lastplayed': 1234, '~#rating': 1.0,
'~filename': fsnative(u'/foo')})
'~filename': fsnative(u'/foo'), 'discnumber': '4294967296'})
A2.sanitize()

MAX_TIME = 3
Expand Down Expand Up @@ -231,3 +231,5 @@ def test_metadata(self):
resp = self._wait()[0]
self.failUnlessEqual(resp["xesam:album"], u'greatness2\ufffd')
self.failUnlessEqual(resp["xesam:artist"], [u'fooman\ufffd'])
# overflow
assert resp["xesam:discNumber"] == 0

0 comments on commit 4d251e8

Please sign in to comment.