3.16: MPD: stop state bugfix, mute/unmute on rightclick

Yes, I currently just increase the minor version number on every fix
This commit is contained in:
enkore 2013-07-18 22:36:52 +02:00
parent eb44638b87
commit 5ee67aaefd
2 changed files with 18 additions and 5 deletions

View File

@ -17,6 +17,8 @@ class MPD(IntervalModule):
* pos (Position of current song in playlist, one-based)
* len (Length of current playlist)
* status
Left click on the module play/pauses, right click (un)mutes.
"""
interval = 1
@ -27,7 +29,6 @@ class MPD(IntervalModule):
)
port = 6600
format = "{title} {status}"
status = {
"pause": "",
@ -35,10 +36,11 @@ class MPD(IntervalModule):
"stop": "",
}
vol = 100
def _mpd_command(self, sock, command):
sock.send((command + "\n").encode("utf-8"))
reply = sock.recv(16384)
reply = reply.decode("utf-8")
reply = sock.recv(16384).decode("utf-8")
replylines = reply.split("\n")[:-2]
return dict(
@ -56,7 +58,7 @@ class MPD(IntervalModule):
fdict["status"] = self.status[status["state"]]
currentsong = self._mpd_command(s, "currentsong")
fdict["title"] = currentsong["Title"]
fdict["title"] = currentsong.get("Title", "")
fdict["album"] = currentsong.get("Album", "")
fdict["artist"] = currentsong.get("Artist", "")
@ -74,3 +76,14 @@ class MPD(IntervalModule):
s.recv(8192)
self._mpd_command(s, "pause %i" % (0 if self._mpd_command(s, "status")["state"] == "pause" else 1))
def on_rightclick(self):
with socket.create_connection(("localhost", self.port)) as s:
s.recv(8192)
vol = int(self._mpd_command(s, "status")["volume"])
if vol == 0:
self._mpd_command(s, "setvol %i" % self.vol)
else:
self.vol = vol
self._mpd_command(s, "setvol 0")

View File

@ -3,7 +3,7 @@
from setuptools import setup
setup(name="i3pystatus",
version="3.15",
version="3.16",
description="Like i3status, this generates status line for i3bar / i3wm",
url="http://github.com/enkore/i3pystatus",
license="MIT",