diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2015-03-30 16:22:51 +0200 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2015-03-30 16:22:51 +0200 |
| commit | 9c70a7e8fd92908ddb7eb0ffb347e7e83c79483e (patch) | |
| tree | cf00b34d7f394274484c69da45e18932e893068e /py3status/modules | |
| parent | a1c5c0ce1028c17e4e314fc5a980158a49d5ef65 (diff) | |
| parent | 7b535275cb776ccc3340697a10f18ab157434a28 (diff) | |
Merge pull request #88 from rixx/player_control
add VLC support to player_control module by @rixx
Diffstat (limited to 'py3status/modules')
| -rw-r--r-- | py3status/modules/player_control.py | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index ba8f37d..1651327 100644 --- a/py3status/modules/player_control.py +++ b/py3status/modules/player_control.py @@ -7,7 +7,7 @@ Provides an icon to control simple functions of audio/video players: - stop (left click) - pause (middle click) -@author Federico Ceratto <federico.ceratto@gmail.com> +@author Federico Ceratto <federico.ceratto@gmail.com>, rixx @license BSD """ # Any contributor to this module should add his/her name to the @author @@ -15,6 +15,7 @@ Provides an icon to control simple functions of audio/video players: from syslog import syslog, LOG_INFO from time import time, sleep +import dbus import os import subprocess @@ -27,18 +28,21 @@ class Py3status: """ Configuration parameters: - debug: enable verbose logging (bool) (default: False) - - supported_players: supported players (str) (whitespace separated list) + - supported_players: supported players (str) (comma separated list) - volume_tick: percentage volume change on mouse wheel (int) (positive number or None to disable it) """ debug = False - supported_players = 'audacious' + pause_icon = u'❚❚' + play_icon = u'▶' + stop_icon = u'◼' + supported_players = 'audacious,vlc' volume_tick = 1 def __init__(self): self.status = 'stop' - self.icon = u'▶' + self.icon = self.play_icon def on_click(self, i3s_output_list, i3s_config, event): """ @@ -79,24 +83,36 @@ class Py3status: def _play(self): self.status = 'play' - self.icon = u'◼' + self.icon = self.stop_icon player_name = self._detect_running_player() if player_name == 'audacious': self._run(['/usr/bin/audacious', '-p']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Play() def _stop(self): self.status = 'stop' - self.icon = u'▶' + self.icon = self.play_icon player_name = self._detect_running_player() if player_name == 'audacious': self._run(['/usr/bin/audacious', '-s']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Stop() def _pause(self): self.status = 'pause' - self.icon = u'❚❚' + self.icon = self.pause_icon player_name = self._detect_running_player() if player_name == 'audacious': self._run(['/usr/bin/audacious', '-u']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Pause() def _change_volume(self, increase): """Change volume using amixer @@ -108,16 +124,16 @@ class Py3status: def _detect_running_player(self): """Detect running player process, if any """ - supported_players = self.supported_players.split(' ') + supported_players = self.supported_players.split(',') running_players = [] for pid in os.listdir('/proc'): if not pid.isdigit(): continue - fn = os.path.join('/proc', pid, 'cmdline') + fn = os.path.join('/proc', pid, 'comm') try: with open(fn, 'rb') as f: - player_name = f.read().rstrip('\0') + player_name = f.read().decode().rstrip() except: continue @@ -135,6 +151,13 @@ class Py3status: return None + def _get_vlc(self): + mpris = 'org.mpris.MediaPlayer2' + mpris_slash = '/' + mpris.replace('.', '/') + bus = dbus.SessionBus() + proxy = bus.get_object(mpris+'.vlc', mpris_slash) + return dbus.Interface(proxy, dbus_interface=mpris+'.Player') + def player_control(self, i3s_output_list, i3s_config): return dict( full_text=self.icon, |
