diff --git a/README.md b/README.md index accebbd..101ec11 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/blockify/cli.py b/blockify/cli.py index 5364f77..807e41b 100644 --- a/blockify/cli.py +++ b/blockify/cli.py @@ -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[:] @@ -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() @@ -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: @@ -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") @@ -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: @@ -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: diff --git a/blockify/gui.py b/blockify/gui.py index dc713d2..86442ce 100644 --- a/blockify/gui.py +++ b/blockify/gui.py @@ -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: diff --git a/blockify/util.py b/blockify/util.py index 900c437..47c93ac 100755 --- a/blockify/util.py +++ b/blockify/util.py @@ -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")