From 2c303436aef8d9cd5d31dfafc6cfda4025e76ef3 Mon Sep 17 00:00:00 2001 From: Max Demian Date: Thu, 31 Dec 2015 21:00:19 +0100 Subject: [PATCH 1/2] remove wmctrl dependency (see #67) --- .gitignore | 1 - README.md | 12 ++++---- blockify/cli.py | 78 +++++++----------------------------------------- blockify/util.py | 2 +- 4 files changed, 17 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 3c609c1..48df1ef 100644 --- a/.gitignore +++ b/.gitignore @@ -130,5 +130,4 @@ fabric.properties *.un~ Session.vim .netrwhist -*~ diff --git a/README.md b/README.md index a48013e..accebbd 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,12 @@ Blockify is a linux only application that allows you to automatically mute songs ##### Basic Requirements: - Python3 - Pulseaudio -- Wmctrl - Gstreamer1.0 (including the plugins you need for the audio formats you want to be able to play as interlude music) - Spotify > 1.0.12 (to get the latest version follow the instructions given here [Spotify-Client-1-x-beta-] (https://community.spotify.com/t5/Spotify-Community-Blog/Spotify-Client-1-x-beta-for-Linux-has-been-released/ba-p/1147084)) ##### Dependencies Before installing blockify, please make sure you have the appropriate dependencies installed: -`pacman -S python pulseaudio wmctrl gst-python alsa-utils libwnck3 pygtk python-dbus python-setuptools python-gobject python-docopt` +`pacman -S python pulseaudio gst-python alsa-utils pygtk python-dbus python-setuptools python-gobject python-docopt` Package names are for ArchLinux and will probably differ slightly between distributions. @@ -35,9 +34,9 @@ If there is no blockify package available on your distribution, you'll have to i First, the dependencies: ``` bash # Dependencies on Ubuntu -sudo apt-get install python-pip libwnck3 gst-python1.0 wmctrl +sudo apt-get install python-pip gst-python1.0 # Dependencies on Fedora -sudo dnf install python-dbus gstreamer-python libwnck3 +sudo dnf install python-dbus gstreamer-python ``` Then blockify itself: ``` bash @@ -45,7 +44,7 @@ git clone https://github.com/mikar/blockify cd blockify sudo pip install . # Create optional desktop icon -echo -e '[Desktop Entry]\nName=Blockify\nComment=Blocks Spotify commercials\nExec=blockify-ui\nIcon='$(python -c 'import pkg_resources; print pkg_resources.resource_filename("blockify", "data/icon-red-512.png")')'\nType=Application\nCategories=AudioVideo' | sudo tee /usr/share/applications/blockify.desktop +echo -e '[Desktop Entry]\nName=Blockify\nComment=Blocks Spotify commercials\nExec=blockify-ui\nIcon='$(python3 -c 'import pkg_resources; print(pkg_resources.resource_filename("blockify", "data/icon-red-512.png"))')'\nType=Application\nCategories=AudioVideo' | sudo tee /usr/share/applications/blockify.desktop ``` ## Usage @@ -169,8 +168,9 @@ If you can't find or fix the issue you are having by yourself, you are welcome t ## Changelog +- 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). +- 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). - v2.0.0 (2015-09-05): (prerelease) Added rudimentary support for Spotify v1.0 and higher. Fixed autoplay option. - v1.9.0 (2015-08-15): Fix [issue #52](https://github.com/mikar/blockify/issues/52), introduce autoplay option and change start_spotify option to boolean type - v1.8.8 (2015-07-11): Fix [issue #46](https://github.com/mikar/blockify/issues/46) and [issue #47](https://github.com/mikar/blockify/issues/47) diff --git a/blockify/cli.py b/blockify/cli.py index 341a783..5364f77 100644 --- a/blockify/cli.py +++ b/blockify/cli.py @@ -20,6 +20,7 @@ import time from gi import require_version + require_version('Gtk', '3.0') require_version('Wnck', '3.0') from gi.repository import Gtk @@ -240,7 +241,7 @@ def spotify_is_playing(self): return self.song_status == "Playing" def update(self): - "Main update routine, looped every self.update_interval milliseconds." + """Main update routine, looped every self.update_interval milliseconds.""" if not self.suspend_blockify: # Determine if a commercial is running and act accordingly. self.found = self.find_ad() @@ -251,10 +252,9 @@ def update(self): return True def find_ad(self): - "Main loop. Checks for ads and mutes accordingly." + """Main loop. Checks for ads and mutes accordingly.""" self.previous_song = self.current_song self.current_song = self.get_current_song() - # self.song_status = self.dbus.get_song_status() # Manual control is enabled so we exit here. if not self.automute: @@ -292,76 +292,18 @@ def ad_found(self): # log.debug("Ad found: {0}".format(self.current_song)) self.toggle_mute(1) - def current_song_is_ad(self): - "Compares the wnck song info to dbus song info." - try: - song_artist = self.dbus.get_song_artist() - song_title = self.dbus.get_song_title() - try: - song_artist = song_artist.decode("utf-8") - song_title = song_title.decode("utf-8") - except AttributeError as e: - log.debug("AttributeError during ad detection: {}".format(e)) - dbus_song = song_artist + self.song_delimiter + song_title - is_ad = self.current_song != dbus_song - return is_ad - except TypeError as e: - # Spotify has technically stopped playing and sending dbus - # metadata so we get NoneType-errors. - # However, it might still play one last ad so we assume that - # is the case here. - log.debug("TypeError during ad detection: {}".format(e)) - return True - def unmute_with_delay(self): if not self.found: self.toggle_mute() return False - def find_spotify_window_wmctrl(self): - spotify_window = [] - try: - pipe = subprocess.Popen(['wmctrl', '-lx'], stdout=subprocess.PIPE).stdout - window_list = pipe.read().decode("utf-8").split("\n") - for window in window_list: - if window.find("spotify.Spotify") >= 0: - # current_song = " ".join(window.split()[5:]) - spotify_window.append(window) - break - - except OSError: - log.error("Please install wmctrl first! Exiting.") - sys.exit(1) - - return spotify_window - - def find_spotify_window(self): - "Libwnck list of currently open windows." - Gtk.init([]) - # Get the current screen. - screen = Wnck.Screen.get_default() - - # recommended per Wnck documentation - screen.force_update() - - # Object list of windows in screen. - windows = screen.get_windows() - - # Return the Spotify window or an empty list. - return [win.get_icon_name() for win in windows\ - if len(windows) and "Spotify" in win.get_application().get_name()] + def current_song_is_ad(self): + """Compares the wnck song info to dbus song info.""" + return self.dbus.get_song_title() and not self.dbus.get_song_artist() def get_current_song(self): - "Checks if a Spotify window exists and returns the current songname." - song = "" - spotify_window = self.find_spotify_window_wmctrl() - if spotify_window: - try: - song = " ".join(map(str, spotify_window[0].split()[4:])) - except Exception as e: - log.debug("Could not match spotify pid to sink pid: %s".format(e), exc_info=1) - - return song + """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") def block_current(self): if self.current_song: @@ -406,7 +348,7 @@ def get_state(self, mode): return state def alsa_mute(self, mode): - "Mute method for systems without Pulseaudio. Mutes sound system-wide." + """Mute method for systems without Pulseaudio. Mutes sound system-wide.""" state = self.get_state(mode) if not state: return @@ -415,7 +357,7 @@ def alsa_mute(self, mode): subprocess.Popen(["amixer", "-q", "set", channel, state]) def pulse_mute(self, mode): - "Used if pulseaudio is installed but no sinks are found. System-wide." + """Used if pulseaudio is installed but no sinks are found. System-wide.""" state = self.get_state(mode) if not state: return diff --git a/blockify/util.py b/blockify/util.py index c981bb9..900c437 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.0.2" +VERSION = "3.1.0" CONFIG = None CONFIG_DIR = os.path.expanduser("~/.config/blockify") CONFIG_FILE = os.path.join(CONFIG_DIR, "blockify.ini") From 0186b92ed88072132fb45290813db30b6d5c9df2 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 31 Dec 2015 21:06:15 +0100 Subject: [PATCH 2/2] adjust name in license --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 35b24a4..96a84e4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Max Demian +Copyright (c) 2014 Max Falk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE.