From fe67b767bef6f307084b4a0993c5e84b26f5c487 Mon Sep 17 00:00:00 2001 From: rixx Date: Mon, 30 Mar 2015 13:42:31 +0200 Subject: python3 compatibility --- py3status/modules/player_control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py3status/modules') diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index ba8f37d..6144462 100644 --- a/py3status/modules/player_control.py +++ b/py3status/modules/player_control.py @@ -117,7 +117,7 @@ class Py3status: fn = os.path.join('/proc', pid, 'cmdline') try: with open(fn, 'rb') as f: - player_name = f.read().rstrip('\0') + player_name = f.read().decode().rstrip('\0') except: continue -- cgit v1.3 From 93c060a45f8de813caf7bd1b277b6c63490a5b80 Mon Sep 17 00:00:00 2001 From: rixx Date: Mon, 30 Mar 2015 14:26:31 +0200 Subject: use /proc//comm instead of /proc//cmdline In cmdline there is the complete call executed, which includes filenames if you want to start a file directly (probably mostly important for mplayer users). In comm, there is only the name of the executable. --- py3status/modules/player_control.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'py3status/modules') diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index 6144462..062db49 100644 --- a/py3status/modules/player_control.py +++ b/py3status/modules/player_control.py @@ -114,10 +114,10 @@ class Py3status: 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().decode().rstrip('\0') + player_name = f.read().decode().rstrip() except: continue -- cgit v1.3 From ec31f28ff1aaf777aedc74970b9b752141114ad3 Mon Sep 17 00:00:00 2001 From: rixx Date: Mon, 30 Mar 2015 15:11:39 +0200 Subject: adds VLC support uses only dbus and communicates via the MPRIS MusicPlayer2 interface --- py3status/modules/player_control.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'py3status/modules') diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index 062db49..acae24a 100644 --- a/py3status/modules/player_control.py +++ b/py3status/modules/player_control.py @@ -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 @@ -33,7 +34,7 @@ class Py3status: """ debug = False - supported_players = 'audacious' + supported_players = 'audacious vlc' volume_tick = 1 def __init__(self): @@ -83,6 +84,10 @@ class Py3status: 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' @@ -90,6 +95,10 @@ class Py3status: 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' @@ -97,6 +106,10 @@ class Py3status: 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 @@ -135,6 +148,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, -- cgit v1.3 From f72b0fd5e63f3e0e01ad07de15e227cd84fc9330 Mon Sep 17 00:00:00 2001 From: rixx Date: Mon, 30 Mar 2015 15:26:46 +0200 Subject: configurable icons for player_control --- py3status/modules/player_control.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'py3status/modules') diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index acae24a..3de3890 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 +@author Federico Ceratto , rixx @license BSD """ # Any contributor to this module should add his/her name to the @author @@ -34,12 +34,15 @@ class Py3status: """ debug = False + 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): """ @@ -80,7 +83,7 @@ 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']) @@ -91,7 +94,7 @@ class Py3status: 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']) @@ -102,7 +105,7 @@ class Py3status: 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']) -- cgit v1.3 From 7b535275cb776ccc3340697a10f18ab157434a28 Mon Sep 17 00:00:00 2001 From: rixx Date: Mon, 30 Mar 2015 15:58:34 +0200 Subject: change list format to comma separated --- py3status/modules/player_control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'py3status/modules') diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py index 3de3890..1651327 100644 --- a/py3status/modules/player_control.py +++ b/py3status/modules/player_control.py @@ -28,7 +28,7 @@ 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) """ @@ -37,7 +37,7 @@ class Py3status: pause_icon = u'❚❚' play_icon = u'▶' stop_icon = u'◼' - supported_players = 'audacious vlc' + supported_players = 'audacious,vlc' volume_tick = 1 def __init__(self): @@ -124,7 +124,7 @@ 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(): -- cgit v1.3