class MediaPlayer (object):
    def __init__(self, dbus_obj):
        self._dbus_obj = dbus_obj
        entry = self.get_root_property('DesktopEntry')
        # TODO: handle case of absent DesktopEntry (DesktopEntry is optional according to MPRIS2)
        self.desktop_app_info = DesktopAppInfo(entry + '.desktop')

    @property
    def root(self):
        return dbus.Interface(self._dbus_obj, dbus_interface='org.mpris.MediaPlayer2')

    @property
    def player(self):
        return dbus.Interface(self._dbus_obj, dbus_interface='org.mpris.MediaPlayer2.Player')

    @property
    def playlists(self):
        return dbus.Interface(self._dbus_obj, dbus_interface='org.mpris.MediaPlayer2.Playlists')

    @property
    def supports_playlists(self):
        try:
            self.get_playlists_property('PlaylistCount')
            return True
        except:
            return False

    @property
    def name(self):
        return self.get_root_property('DesktopEntry')

    @property
    def is_playing(self):
        playback_status = self.get_player_property('PlaybackStatus')
        return playback_status == 'Playing'

    def _get_property(self, target, property_name):
        properties_manager = dbus.Interface(self._dbus_obj, 'org.freedesktop.DBus.Properties')
        return properties_manager.Get(target, property_name)

    def get_player_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2.Player', property_name)

    def get_root_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2', property_name)

    def get_playlists_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2.Playlists', property_name)

    @property
    def icon(self):
        return self.desktop_app_info.get_icon()

    @property
    def description(self):
        return self.desktop_app_info.get_description()
Exemple #2
0
 def finish(self, require_x=False):
     """Try to set self.object from init's parameters"""
     item = None
     if self.init_item:
         item = self.init_item
     else:
         # Construct an AppInfo item from either path or item_id
         from gio.unix import DesktopAppInfo, desktop_app_info_new_from_filename
         if self.init_path and (not require_x
                                or os.access(self.init_path, os.X_OK)):
             # serilizable if created from a "loose file"
             self.serializable = 1
             item = desktop_app_info_new_from_filename(self.init_path)
         elif self.init_item_id:
             try:
                 item = DesktopAppInfo(self.init_item_id)
             except RuntimeError:
                 pretty.print_debug(__name__, "Application not found:",
                                    self.init_item_id)
     self.object = item
     if not self.object:
         raise InvalidDataError
 def __init__(self, dbus_obj):
     self._dbus_obj = dbus_obj
     entry = self.get_root_property('DesktopEntry')
     # TODO: handle case of absent DesktopEntry (DesktopEntry is optional according to MPRIS2)
     self.desktop_app_info = DesktopAppInfo(entry + '.desktop')
class MediaPlayer(object):
    def __init__(self, dbus_obj):
        self._dbus_obj = dbus_obj
        entry = self.get_root_property('DesktopEntry')
        # TODO: handle case of absent DesktopEntry (DesktopEntry is optional according to MPRIS2)
        self.desktop_app_info = DesktopAppInfo(entry + '.desktop')

    @property
    def root(self):
        return dbus.Interface(self._dbus_obj,
                              dbus_interface='org.mpris.MediaPlayer2')

    @property
    def player(self):
        return dbus.Interface(self._dbus_obj,
                              dbus_interface='org.mpris.MediaPlayer2.Player')

    @property
    def playlists(self):
        return dbus.Interface(
            self._dbus_obj, dbus_interface='org.mpris.MediaPlayer2.Playlists')

    @property
    def supports_playlists(self):
        try:
            self.get_playlists_property('PlaylistCount')
            return True
        except:
            return False

    @property
    def name(self):
        return self.get_root_property('DesktopEntry')

    @property
    def is_playing(self):
        playback_status = self.get_player_property('PlaybackStatus')
        return playback_status == 'Playing'

    def _get_property(self, target, property_name):
        properties_manager = dbus.Interface(self._dbus_obj,
                                            'org.freedesktop.DBus.Properties')
        return properties_manager.Get(target, property_name)

    def get_player_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2.Player',
                                  property_name)

    def get_root_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2', property_name)

    def get_playlists_property(self, property_name):
        return self._get_property('org.mpris.MediaPlayer2.Playlists',
                                  property_name)

    @property
    def icon(self):
        return self.desktop_app_info.get_icon()

    @property
    def description(self):
        return self.desktop_app_info.get_description()
 def __init__(self, dbus_obj):
     self._dbus_obj = dbus_obj
     entry = self.get_root_property('DesktopEntry')
     # TODO: handle case of absent DesktopEntry (DesktopEntry is optional according to MPRIS2)
     self.desktop_app_info = DesktopAppInfo(entry + '.desktop')