Skip to content

Commit

Permalink
fix playback status (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmdfalk committed Dec 31, 2015
1 parent 0186b92 commit 1641a53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ If you can't find or fix the issue you are having by yourself, you are welcome t


## Changelog
- v3.2.0 (2015-12-31): Reintroduce playback status (see [issue #68](https://github.com/mikar/blockify/issues/68))
- v3.1.0 (2015-12-31): Remove wmctrl dependency (see [issue #67](https://github.com/mikar/blockify/issues/67))
- v3.0.0 (2015-10-16): Remove beta status and port to python3 and gstreamer1.0 (see [issue #59](https://github.com/mikar/blockify/issues/59)).
- v2.0.1 (2015-10-05): (prerelease) Fix [issue #58](https://github.com/mikar/blockify/issues/58) and [issue #38](https://github.com/mikar/blockify/issues/38).
Expand Down
24 changes: 12 additions & 12 deletions blockify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
from blockify import interludeplayer
from blockify import util


log = logging.getLogger("cli")


class Blockify(object):

def __init__(self, blocklist):
self.blocklist = blocklist
self.orglist = blocklist[:]
Expand All @@ -64,7 +62,7 @@ def __init__(self, blocklist):
# The gst library used by interludeplayer for some reason modifies
# argv, overwriting some of docopts functionality in the process,
# so we import gst here, where docopts cannot be broken anymore.
#import interludeplayer
# import interludeplayer
self.player = interludeplayer.InterludePlayer(self)

self.initialize_mute_method()
Expand Down Expand Up @@ -303,7 +301,8 @@ def current_song_is_ad(self):

def get_current_song(self):
"""Checks if a Spotify window exists and returns the current songname."""
return self.dbus.get_song_artist().decode("utf-8") + self.song_delimiter + self.dbus.get_song_title().decode("utf-8")
return self.dbus.get_song_artist().decode("utf-8") + self.song_delimiter + self.dbus.get_song_title().decode(
"utf-8")

def block_current(self):
if self.current_song:
Expand Down Expand Up @@ -366,9 +365,9 @@ def pulse_mute(self, mode):
subprocess.Popen(["amixer", "-qD", "pulse", "set", channel, state])

def extract_pulse_sink_status(self, pacmd_out):
sink_status = ("", "")
sink_status = ("", "", "") # index, playback_status, muted_value
# Match muted_value and application.process.id values.
pattern = re.compile(r"(?: index|muted|application\.process\.id).*?(\w+)")
pattern = re.compile(r"(?: index|state|muted|application\.process\.id).*?(\w+)")
# Put valid spotify PIDs in a list
output = pacmd_out.decode("utf-8")

Expand All @@ -377,16 +376,17 @@ def extract_pulse_sink_status(self, pacmd_out):
if len(spotify_sink_list) and self.spotify_pids:
sink_infos = [pattern.findall(sink) for sink in spotify_sink_list]
# Every third element per sublist is a key, the value is the preceding
# two elements in the form of a tuple - {pid : (index, muted_value)}
idxd = {sink_status[2]: (sink_status[0], sink_status[1]) for sink_status in sink_infos if len(sink_status) == 3}
# two elements in the form of a tuple - {pid : (index, playback_status, muted_value)}
idxd = {sink_status[3]: (sink_status[0], sink_status[1], sink_status[2]) for sink_status in sink_infos if
4 == len(sink_status)}

pid = [k for k in idxd.keys() if k in self.spotify_pids][0]
sink_status = idxd[pid] # tuple of 2 elements: (index, muted_value)
sink_status = idxd[pid]

return sink_status

def pulsesink_mute(self, mode):
"Finds spotify's audio sink and toggles its mute state."
"""Finds spotify's audio sink and toggles its mute state."""
try:
pacmd_out = subprocess.check_output(["pacmd", "list-sink-inputs"])
except subprocess.CalledProcessError:
Expand All @@ -395,8 +395,8 @@ def pulsesink_mute(self, mode):
self.use_interlude_music = False
return

index, muted_value = self.extract_pulse_sink_status(pacmd_out)

index, playback_state, muted_value = self.extract_pulse_sink_status(pacmd_out)
self.song_status = "Playing" if playback_state == "RUNNING" else "Paused"
self.is_sink_muted = False if muted_value == self.pulse_unmuted_value else True

if index:
Expand Down
1 change: 1 addition & 0 deletions blockify/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ def on_togglelist(self, widget):
self.editor.destroy()

def on_toggleplay_btn(self, widget):
print(self.b.song_status)
if not self.b.spotify_is_playing():
self.b.player.try_resume_spotify_playback(True)
else:
Expand Down
2 changes: 1 addition & 1 deletion blockify/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
log.error("ImportError: Please install docopt to use the CLI.")

VERSION = "3.1.0"
VERSION = "3.2.0"
CONFIG = None
CONFIG_DIR = os.path.expanduser("~/.config/blockify")
CONFIG_FILE = os.path.join(CONFIG_DIR, "blockify.ini")
Expand Down

0 comments on commit 1641a53

Please sign in to comment.