Add clementine media player support
Based on #438 by @printesoi Fixes #422 Closes #438
This commit is contained in:
parent
cd9811806c
commit
7c587f5c20
|
@ -1077,33 +1077,54 @@ class NowPlayingSegment(Segment):
|
||||||
'total': self._convert_seconds(now_playing.get('time', 0)),
|
'total': self._convert_seconds(now_playing.get('time', 0)),
|
||||||
}
|
}
|
||||||
|
|
||||||
def player_spotify_dbus(self, pl, dbus=None):
|
def player_dbus(self, player_name, bus_name, player_path, iface_prop, iface_player):
|
||||||
try:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pl.exception('Could not add Spotify segment: requires python-dbus.')
|
pl.exception('Could not add {0} segment: requires python-dbus', player_name)
|
||||||
return
|
return
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
DBUS_IFACE_PROPERTIES = 'org.freedesktop.DBus.Properties'
|
|
||||||
DBUS_IFACE_PLAYER = 'org.freedesktop.MediaPlayer2'
|
|
||||||
try:
|
try:
|
||||||
player = bus.get_object('com.spotify.qt', '/')
|
player = bus.get_object(bus_name, player_path)
|
||||||
iface = dbus.Interface(player, DBUS_IFACE_PROPERTIES)
|
iface = dbus.Interface(player, iface_prop)
|
||||||
info = iface.Get(DBUS_IFACE_PLAYER, 'Metadata')
|
info = iface.Get(iface_player, 'Metadata')
|
||||||
status = iface.Get(DBUS_IFACE_PLAYER, 'PlaybackStatus')
|
status = iface.Get(iface_player, 'PlaybackStatus')
|
||||||
except dbus.exceptions.DBusException:
|
except dbus.exceptions.DBusException:
|
||||||
return
|
return
|
||||||
if not info:
|
if not info:
|
||||||
return
|
return
|
||||||
|
album = u(info.get('xesam:album'))
|
||||||
|
title = u(info.get('xesam:title'))
|
||||||
|
artist = info.get('xesam:artist')
|
||||||
state = self._convert_state(status)
|
state = self._convert_state(status)
|
||||||
|
if artist:
|
||||||
|
artist = u(artist[0])
|
||||||
return {
|
return {
|
||||||
'state': state,
|
'state': state,
|
||||||
'album': info.get('xesam:album'),
|
'album': album,
|
||||||
'artist': info.get('xesam:artist')[0],
|
'artist': artist,
|
||||||
'title': info.get('xesam:title'),
|
'title': title,
|
||||||
'total': self._convert_seconds(info.get('mpris:length') / 1e6),
|
'total': self._convert_seconds(info.get('mpris:length') / 1e6),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def player_spotify_dbus(self, pl):
|
||||||
|
return self.player_dbus(
|
||||||
|
player_name='Spotify',
|
||||||
|
bus_name='com.spotify.qt',
|
||||||
|
player_path='/',
|
||||||
|
iface_prop='org.freedesktop.DBus.Properties',
|
||||||
|
iface_player='org.freedesktop.MediaPlayer2',
|
||||||
|
)
|
||||||
|
|
||||||
|
def player_clementine(self, pl):
|
||||||
|
return self.player_dbus(
|
||||||
|
player_name='Clementine',
|
||||||
|
bus_name='org.mpris.MediaPlayer2.clementine',
|
||||||
|
player_path='/org/mpris/MediaPlayer2',
|
||||||
|
iface_prop='org.freedesktop.DBus.Properties',
|
||||||
|
iface_player='org.mpris.MediaPlayer2.Player',
|
||||||
|
)
|
||||||
|
|
||||||
def player_spotify_apple_script(self, pl):
|
def player_spotify_apple_script(self, pl):
|
||||||
status_delimiter = '-~`/='
|
status_delimiter = '-~`/='
|
||||||
ascript = '''
|
ascript = '''
|
||||||
|
|
Loading…
Reference in New Issue