Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
* release/3.3.0:
  perf(gui): reduce cpu usage by cutting redundant update actions
  • Loading branch information
gmdfalk committed Jan 3, 2016
2 parents eacb141 + 052a4f1 commit c698fd2
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 178 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ If you can't find or fix the issue you are having by yourself, you are welcome t


## Changelog
- v3.3.0 (2016-01-03): Add tray icon toolip, fix playback button and title status functionality and add missing gui screenshot.
- v3.3.0 (2016-01-03): Enable profiling, improve GUI performance, fix playback button & title status functionality and add tray icon toolip.
- v3.2.1 (2016-01-03): Remove unnecessary imports and other cleanups.
- 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))
Expand Down
45 changes: 25 additions & 20 deletions blockify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import re
import signal
import subprocess
import sys
import time

from gi import require_version
Expand Down Expand Up @@ -52,12 +51,14 @@ def __init__(self, blocklist):
self.song_delimiter = " - " # u" \u2013 "
self.found = False
self.current_song = ""
self.current_song_artist = ""
self.current_song_title = ""
self.previous_song = ""
self.song_status = ""
self.is_fully_muted = False
self.is_sink_muted = False
self.dbus = self.init_dbus()
self.channels = self.init_channels()
self.dbus = self.initialize_dbus()
self.channels = self.initialize_channels()
# 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.
Expand All @@ -82,13 +83,13 @@ def start_spotify_if_necessary(self):

if not util.CONFIG["general"]["start_spotify"]:
log.info("Exiting. Bye.")
sys.exit()
Gtk.main_quit()

self.start_spotify()
if not self.check_for_spotify_process():
log.error("Failed to start Spotify!")
log.info("Exiting. Bye.")
sys.exit()
Gtk.main_quit()

def is_localized_pulseaudio(self):
"""Pulseaudio versions below 7.0 are localized."""
Expand Down Expand Up @@ -144,14 +145,14 @@ def install_locale(self):

def check_for_blockify_process(self):
try:
pid = subprocess.check_output(["pgrep", "-f", "python.*blockify"])
pid = subprocess.check_output(["pgrep", "-f", "^python.*blockify"])
except subprocess.CalledProcessError:
# No blockify process found. Great, this is what we want.
pass
else:
if pid.strip().decode("utf-8") != str(os.getpid()):
log.error("A blockify process is already running. Exiting.")
sys.exit()
Gtk.main_quit()

def check_for_spotify_process(self):
try:
Expand All @@ -172,7 +173,7 @@ def start_spotify(self):
log.info("Spotify launched!")
break

def init_channels(self):
def initialize_channels(self):
channel_list = ["Master"]
amixer_output = subprocess.check_output("amixer")
if "'Speaker',0" in amixer_output.decode("utf-8"):
Expand All @@ -182,12 +183,12 @@ def init_channels(self):

return channel_list

def init_dbus(self):
def initialize_dbus(self):
try:
return dbusclient.DBusClient()
except Exception as e:
log.error("Cannot connect to DBus. Exiting.\n ({}).".format(e))
sys.exit()
Gtk.main_quit()

def refresh_spotify_process_state(self):
"""Check if Spotify is running periodically. If it's not, suspend blockify."""
Expand Down Expand Up @@ -255,7 +256,7 @@ def update(self):
def find_ad(self):
"""Main loop. Checks for ads and mutes accordingly."""
self.previous_song = self.current_song
self.current_song = self.get_current_song()
self.update_current_song_info()

# Manual control is enabled so we exit here.
if not self.automute:
Expand Down Expand Up @@ -299,11 +300,12 @@ def unmute_with_delay(self):
return False

def current_song_is_ad(self):
return self.dbus.get_song_title() and not self.dbus.get_song_artist()
return self.current_song_title and not self.current_song_artist

def get_current_song(self):
return self.dbus.get_song_artist().decode("utf-8") + self.song_delimiter + self.dbus.get_song_title().decode(
"utf-8")
def update_current_song_info(self):
self.current_song_artist = self.dbus.get_song_artist().decode("utf-8")
self.current_song_title = self.dbus.get_song_title().decode("utf-8")
self.current_song = self.current_song_artist + self.song_delimiter + self.current_song_title

def block_current(self):
if self.current_song:
Expand Down Expand Up @@ -464,7 +466,7 @@ def signal_toggle_autoresume_received(self, sig, hdl):
self.player.toggle_autoresume()

def bind_signals(self):
"Catch signals because it seems like a great idea, right? ... Right?"
"""Catch signals because it seems like a great idea, right? ... Right?"""
signal.signal(signal.SIGINT, self.signal_stop_received) # 9
signal.signal(signal.SIGTERM, self.signal_stop_received) # 15

Expand All @@ -481,7 +483,7 @@ def bind_signals(self):
signal.signal(signal.SIGRTMIN + 12, self.signal_playpause_interlude_received) # 46
signal.signal(signal.SIGRTMIN + 13, self.signal_toggle_autoresume_received) # 47

def stop(self):
def prepare_stop(self):
log.info("Exiting safely. Bye.")
# Stop the interlude player.
if self.use_interlude_music:
Expand All @@ -492,10 +494,13 @@ def stop(self):
self.blocklist.save()
# Unmute before exiting.
self.toggle_mute(2)
sys.exit()

def stop(self):
self.prepare_stop()
Gtk.main_quit()

def toggle_block(self):
"Block/unblock the current song."
"""Block/unblock the current song."""
if self.found:
self.unblock_current()
else:
Expand Down Expand Up @@ -529,7 +534,7 @@ def initialize(doc=__doc__):


def main():
"Entry point for the CLI-version of Blockify."
"""Entry point for the CLI-version of Blockify."""
cli = initialize()
cli.start()

Expand Down
36 changes: 18 additions & 18 deletions blockify/dbusclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


class DBusClient(object):
"Wrapper for Spotify's DBus interface."
"""Wrapper for Spotify's DBus interface."""

def __init__(self, bus=None):
self.obj_path = "/org/mpris/MediaPlayer2"
Expand Down Expand Up @@ -59,7 +59,7 @@ def connect_to_spotify_dbus(self, bus):
log.error("Could not connect to Spotify dbus session: {}".format(e))

def get_property(self, key):
"Gets the value from any available property."
"""Gets the value from any available property."""
prop = None
try:
prop = self.properties.Get(self.player_path, key)
Expand All @@ -69,50 +69,50 @@ def get_property(self, key):
return prop

def set_property(self, key, value):
"Sets the value for any available property."
"""Sets the value for any available property."""
try:
self.properties.Set(self.player_path, key, value)
except Exception as e:
self.connect_to_spotify_dbus(None)
log.warn("Cannot Set Property: {}".format(e))

def playpause(self):
"Toggles the current song between Play and Pause."
"""Toggles the current song between Play and Pause."""
try:
self.player.PlayPause()
except Exception as e:
log.warn("Cannot Play/Pause: {}".format(e))

def play(self):
"Tries to play the current title."
"""Tries to play the current title."""
try:
self.player.Play()
except Exception as e:
log.warn("Cannot Play: {}".format(e))

def pause(self):
"Tries to pause the current title."
"""Tries to pause the current title."""
try:
self.player.Pause()
except Exception as e:
log.warn("Cannot Pause: {}".format(e))

def stop(self):
"Tries to stop playback. PlayPause is probably preferable."
"""Tries to stop playback. PlayPause is probably preferable."""
try:
self.player.Stop()
except Exception as e:
log.warn("Cannot Stop playback: {}".format(e))

def next(self):
"Tries to skip to next song."
"""Tries to skip to next song."""
try:
self.player.Next()
except Exception as e:
log.warn("Cannot Go Next: {}".format(e))

def prev(self):
"Tries to go back to last song."
"""Tries to go back to last song."""
try:
self.player.Previous()
except Exception as e:
Expand All @@ -133,14 +133,14 @@ def open_uri(self, uri):


def seek(self, seconds):
"Skips n seconds forward."
"""Skips n seconds forward."""
try:
self.player.Seek(seconds)
except Exception as e:
log.warn("Cannot Seek: {}".format(e))

def get_art_url(self):
"Get album cover"
"""Get album cover"""
url = ""
try:
metadata = self.get_property("Metadata")
Expand All @@ -150,7 +150,7 @@ def get_art_url(self):
return url

def get_song_status(self):
"Get current PlaybackStatus (Paused/Playing...)."
"""Get current PlaybackStatus (Paused/Playing...)."""
status = ""
try:
status = self.get_property("PlaybackStatus")
Expand All @@ -160,7 +160,7 @@ def get_song_status(self):
return status

def get_song_length(self):
"Gets the length of current song from metadata (in seconds)."
"""Gets the length of current song from metadata (in seconds)."""
length = 0
try:
metadata = self.get_property("Metadata")
Expand All @@ -171,7 +171,7 @@ def get_song_length(self):
return length

def get_song_title(self):
"Gets title of current song from metadata"
"""Gets title of current song from metadata"""
title = ""
try:
metadata = self.get_property("Metadata")
Expand All @@ -182,7 +182,7 @@ def get_song_title(self):
return title

def get_song_album(self):
"Gets album of current song from metadata"
"""Gets album of current song from metadata"""
album = ""
try:
metadata = self.get_property("Metadata")
Expand All @@ -193,7 +193,7 @@ def get_song_album(self):
return album

def get_song_artist(self):
"Gets the artist of current song from metadata"
"""Gets the artist of current song from metadata"""
artist = ""
try:
metadata = self.get_property("Metadata")
Expand All @@ -204,7 +204,7 @@ def get_song_artist(self):
return artist

def print_info(self):
"Print all the DBus info we can get our hands on."
"""Print all the DBus info we can get our hands on."""
try:
metadata = self.get_property("Metadata")

Expand All @@ -227,7 +227,7 @@ def print_info(self):


def main():
"Entry point for the CLI DBus interface."
"""Entry point for the CLI DBus interface."""
args = docopt(__doc__, version="0.2")
util.init_logger(args["--log"], args["-v"], args["--quiet"])
dbus = DBusClient()
Expand Down
Loading

0 comments on commit c698fd2

Please sign in to comment.