Skip to content

Commit

Permalink
feat(wmctrl): Remove wmctrl dependency
Browse files Browse the repository at this point in the history
* develop:
  adjust name in license
  remove wmctrl dependency (see #67)

Closes #67
  • Loading branch information
gmdfalk committed Dec 31, 2015
2 parents 2cc01ab + 0186b92 commit b0ea6c9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 77 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,4 @@ fabric.properties
*.un~
Session.vim
.netrwhist
*~

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
SOFTWARE.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
78 changes: 10 additions & 68 deletions blockify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
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.0.2"
VERSION = "3.1.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 b0ea6c9

Please sign in to comment.