# Buggy code
def __get_metadata(self):
    """http://xmms2.org/wiki/MPRIS_Metadata"""

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

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

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

    self.__cover = cover = app.cover_manager.get_cover(song)
    is_temp = False
    if cover:
        name = cover.name
        is_temp = name.startswith(tempfile.gettempdir())
        # This doesn't work for embedded images.. the file gets unlinked
        # after loosing the file handle
        metadata["mpris:artUrl"] = fsn2uri(name)

    if not is_temp:
        self.__cover = None

    # All list values
    list_val = {
        "artist": "artist",
        "albumArtist": "albumartist",
        "comment": "comment",
        "composer": "composer",
        "genre": "genre",
        "lyricist": "lyricist",
    }
    for xesam, tag in iteritems(list_val):
        vals = song.list(tag)
        if vals:
            metadata["xesam:" + xesam] = listmap(unival, vals)

    # All single values
    sing_val = {"album": "album", "title": "title", "asText": "~lyrics"}
    for xesam, tag in iteritems(sing_val):
        vals = song.comma(tag)
        if vals:
            metadata["xesam:" + xesam] = unival(vals)

    # URI
    metadata["xesam:url"] = song("~uri")

    # Integers
    num_val = {
        "audioBPM": "bpm",
        "discNumber": "disc",
        "trackNumber": "track",
        "useCount": "playcount",
    }

    for xesam, tag in iteritems(num_val):
        val = song("~#" + tag, None)
        if val is not None:
            metadata["xesam:" + xesam] = int(val)

    # Rating
    metadata["xesam:userRating"] = float(song("~#rating"))

    # Dates
    ISO_8601_format = "%Y-%m-%dT%H:%M:%S"
    tuple_time = time.gmtime(song("~#lastplayed"))
    iso_time = time.strftime(ISO_8601_format, tuple_time)
    metadata["xesam:lastUsed"] = iso_time

    year = song("~year")
    if year:
        try:
            tuple_time = time.strptime(year, "%Y")
            iso_time = time.strftime(ISO_8601_format, tuple_time)
        except ValueError:
            pass
        else:
            metadata["xesam:contentCreated"] = iso_time

    return metadata


# Traceback (OverflowError)
Traceback (most recent call last):

File "/usr/lib/python2.7/site-packages/quodlibet/ext/events/mpris/mpris2.py", line 151, in __library_changed
self.emit_properties_changed(self.PLAYER_IFACE, ["Metadata"])

File "/usr/lib/python2.7/site-packages/quodlibet/util/dbusutils.py", line 307, in emit_properties_changed
self.PropertiesChanged(iface, values, inval)

File "/usr/lib64/python2.7/site-packages/dbus/decorators.py", line 323, in emit_signal
message.append(signature=signature, *args)

OverflowError: long too big to convert


Version: 3.9.1
Python: 2.7.14 (default, Dec 11 2017, 14:52:53)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
Platform: Linux-4.14.8-300.fc27.x86_64-x86_64-with-fedora-27-Twenty_Seven

# Fixed code
def __get_metadata(self):
    """
    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"] = ignore_overflow(dbus.Int64, song("~#length") * 10**6)

    self.__cover = cover = app.cover_manager.get_cover(song)
    is_temp = False
    if cover:
        name = cover.name
        is_temp = name.startswith(tempfile.gettempdir())
        # This doesn't work for embedded images.. the file gets unlinked
        # after loosing the file handle
        metadata["mpris:artUrl"] = fsn2uri(name)

    if not is_temp:
        self.__cover = None

    # All list values
    list_val = {
        "artist": "artist",
        "albumArtist": "albumartist",
        "comment": "comment",
        "composer": "composer",
        "genre": "genre",
        "lyricist": "lyricist",
    }
    for xesam, tag in iteritems(list_val):
        vals = song.list(tag)
        if vals:
            metadata["xesam:" + xesam] = listmap(unival, vals)

    # All single values
    sing_val = {"album": "album", "title": "title", "asText": "~lyrics"}
    for xesam, tag in iteritems(sing_val):
        vals = song.comma(tag)
        if vals:
            metadata["xesam:" + xesam] = unival(vals)

    # URI
    metadata["xesam:url"] = song("~uri")

    # Integers
    num_val = {
        "audioBPM": "bpm",
        "discNumber": "disc",
        "trackNumber": "track",
        "useCount": "playcount",
    }

    for xesam, tag in iteritems(num_val):
        val = song("~#" + tag, None)
        if val is not None:
            metadata["xesam:" + xesam] = ignore_overflow(dbus.Int32, val)

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

    # Dates
    ISO_8601_format = "%Y-%m-%dT%H:%M:%S"
    tuple_time = time.gmtime(song("~#lastplayed"))
    iso_time = time.strftime(ISO_8601_format, tuple_time)
    metadata["xesam:lastUsed"] = iso_time

    year = song("~year")
    if year:
        try:
            tuple_time = time.strptime(year, "%Y")
            iso_time = time.strftime(ISO_8601_format, tuple_time)
        except ValueError:
            pass
        else:
            metadata["xesam:contentCreated"] = iso_time

    return metadata