Skip to content

Commit

Permalink
Bump to 1.8.6. Remove incomplete fix for #44.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Demian committed May 10, 2015
1 parent 4fd2ccc commit 01ed317
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ http://skyserver5.skydisc.net:8000
You can use relative and absolute paths as well as basically any audio source/format, as long as you have the respective gstreamer codec installed.

## Changelog
- v1.8.6 (2015-05-10): Minor refactoring and removed incomplete "fix" for [issue #44](https://github.com/mikar/blockify/issues/44).
- v1.8.5 (2015-05-09): Signal cleanups and [issue #44](https://github.com/mikar/blockify/issues/44) again.
- v1.8.4 (2015-05-08): Add additional signals for both spotify and interlude controls (prev/next/playpause, ...), see Controls/Actions section in this README
- v1.8.3 (2015-05-06): Fix [issue #44](https://github.com/mikar/blockify/issues/44): Cancel current interlude song and resume spotify playback if next spotify song button is clicked when no ad is playing
Expand Down
21 changes: 14 additions & 7 deletions blockify/blockify.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, blocklist):
self.env["LC_ALL"] = "en_US"
self.found = False
self.current_song = ""
self.previous_song = ""
self.song_status = ""
self.is_fully_muted = False
self.is_sink_muted = False
Expand Down Expand Up @@ -120,25 +121,31 @@ def start(self):
log.info("Blockify started.")
gtk.main()

def adjust_interlude(self):
if self.use_interlude_music:
# if self.current_song != self.previous_song and not self.spotify_is_playing():
# self.player.try_resume_spotify_playback()
# else:
self.player.toggle_music()

def spotify_is_playing(self):
return self.song_status == "Playing"

def update(self):
"Main update routine, looped every self.update_interval milliseconds."
# Determine if a commercial is running and act accordingly.
self.found = self.find_ad()

# Adjust playback of interlude music.
if self.use_interlude_music:
self.player.toggle_music()
self.adjust_interlude()

# Always return True to keep looping this method.
return True

def find_ad(self):
"Main loop. Checks for ads and mutes accordingly."
if self.current_song != self.get_current_song() and self.player.is_playing() and not self.dbus.is_playing:
self.player.pause()
self.previous_song = self.current_song
self.current_song = self.get_current_song()
self.song_status = self.dbus.get_song_status()
self.dbus.is_playing = self.song_status == "Playing"

# Manual control is enabled so we exit here.
if not self.automute:
Expand Down Expand Up @@ -180,7 +187,7 @@ def current_song_is_ad(self):
"Compares the wnck song info to dbus song info."
try:
is_ad = self.current_song != self.dbus.get_song_artist() + u" \u2013 " + self.dbus.get_song_title()
return self.dbus.is_playing and is_ad
return self.spotify_is_playing() and is_ad
except TypeError as e:
# Spotify has technically stopped playing and sending dbus
# metadata so we get NoneType-errors.
Expand Down
1 change: 0 additions & 1 deletion blockify/blockifydbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, bus=None):
self.prop_path = "org.freedesktop.DBus.Properties"
self.player_path = "org.mpris.MediaPlayer2.Player"
self.spotify_path = None
self.is_playing = False

if not bus:
bus = dbus.SessionBus()
Expand Down
12 changes: 5 additions & 7 deletions blockify/blockifyui.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,7 @@ def update(self):
# (True/False) depending on whether a song to be blocked was found.
self.b.found = self.b.find_ad()

# Adjust playback of interlude music.
if self.b.use_interlude_music:
self.b.player.toggle_music()
self.b.adjust_interlude()

self.update_labels()
self.update_buttons()
Expand Down Expand Up @@ -558,7 +556,7 @@ def update_buttons(self):
self.toggle_block_btn.set_label("Block")
self.set_title("Blockify")

if self.b.dbus.is_playing and self.b.current_song:
if self.b.spotify_is_playing() and self.b.current_song:
self.toggleplay_btn.set_label("Pause")
else:
self.toggleplay_btn.set_label("Play")
Expand Down Expand Up @@ -706,7 +704,7 @@ def on_autoresume(self, widget):
if not self.b.player.autoresume:
self.b.player.autoresume = True
self.b.player.manual_control = False
if not self.b.found and not self.b.dbus.is_playing:
if not self.b.found and not self.b.spotify_is_playing():
self.b.dbus.playpause()
else:
self.b.player.autoresume = False
Expand All @@ -715,7 +713,7 @@ def disable_interlude_box(self):
self.b.use_interlude_music = False
self.interlude_box.hide()
self.b.player.pause()
if not self.b.dbus.is_playing:
if not self.b.spotify_is_playing():
self.b.dbus.playpause()
self.toggle_interlude_btn.set_label("Enable player")
self.restore_size()
Expand Down Expand Up @@ -761,7 +759,7 @@ def toggle_interlude(self):
else:
self.b.player.manual_control = True
self.b.player.pause()
if not self.b.found and (not self.b.dbus.is_playing or
if not self.b.found and (not self.b.spotify_is_playing() or
not self.b.current_song):
self.b.dbus.playpause()

Expand Down
9 changes: 5 additions & 4 deletions blockify/interludeplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def on_about_to_finish(self, player):
"Song is ending. What do we do?"
self.queue_next()
log.debug("Interlude song finished. Queued: {}.".format(self.get_current_uri()))
if not self.autoresume and not self.b.dbus.is_playing:
if not self.autoresume and not self.b.spotify_is_playing():
self.pause()
self.b.dbus.playpause()

Expand Down Expand Up @@ -140,11 +140,12 @@ def is_valid_uri(self, item):
def try_resume_spotify_playback(self):
if self.is_playing() and not self.b.found:
self.pause()
self.b.dbus.playpause()
if not self.b.spotify_is_playing():
self.b.dbus.playpause()

def resume_spotify_playback(self):
if not self.b.found:
if not self.b.dbus.is_playing:
if not self.b.spotify_is_playing():
self.b.dbus.playpause()
self.pause()
log.info("Switched from radio back to Spotify.")
Expand Down Expand Up @@ -190,7 +191,7 @@ def toggle_music(self):
if self.autoresume or self.temp_autoresume:
self.pause()
self.temp_autoresume = False
elif self.b.dbus.is_playing:
elif self.b.spotify_is_playing():
self.b.dbus.playpause()

def is_playing(self):
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 = "1.8.5"
VERSION = "1.8.6"
CONFIG = None
CONFIG_DIR = os.path.join(os.path.expanduser("~"), ".config/blockify")
CONFIG_FILE = os.path.join(CONFIG_DIR, "blockify.ini")
Expand Down

0 comments on commit 01ed317

Please sign in to comment.