Created
May 11, 2016 23:56
-
-
Save lucas-tulio/51400fa7eea56ea9b43342e9e1818122 to your computer and use it in GitHub Desktop.
Spotify ad muter in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, dbus | |
from time import sleep | |
from subprocess import call | |
session_bus = dbus.SessionBus() | |
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2") | |
spotify_properties = dbus.Interface(spotify_bus, "org.freedesktop.DBus.Properties") | |
while True: | |
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata") | |
playback_status = str(spotify_properties.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")) | |
if playback_status == 'Playing': | |
song_title = str(metadata['xesam:title']) | |
song_length = int(metadata['mpris:length']) / 1000000 | |
if song_title.strip() == 'Spotify' or (song_length > 29 and song_length < 31): | |
call(['amixer', '-D', 'pulse', 'set', 'Master', 'mute'], stdout=open(os.devnull, 'w')) | |
sleep(30) | |
call(['amixer', '-D', 'pulse', 'set', 'Master', 'unmute'], stdout=open(os.devnull, 'w')) | |
sleep(0.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment