Simple python script that mutes sound when Spotify app runs an ad
Hey guys, was a bit distracted by the fact that Spotify Free is killing the mood sometimes in a foreign language, so decided to create a script that mutes all the sound whenever there is an ad playing.
This script only works on Windows.
This script get windll libraries and uses them to create a process name list (mostly copied code).
After the list is built, it is checked for Process names "Advertisement" and "Spotify" to see if an ad is playing. These names are specific to the moment when ad is being played in Spotify.
The script is run in an interval, and does not fetch data real-time, so has small delays in runtime. As it is short and easily processed, does not load up CPU and doesn't leak memory.
The code: (Requires ctypes and pycaw libraries)
import ctypes #process find
import time #sleep
from pycaw.pycaw import AudioUtilities #mute
while True:
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
/r/Python
https://redd.it/cefijn
Hey guys, was a bit distracted by the fact that Spotify Free is killing the mood sometimes in a foreign language, so decided to create a script that mutes all the sound whenever there is an ad playing.
This script only works on Windows.
This script get windll libraries and uses them to create a process name list (mostly copied code).
After the list is built, it is checked for Process names "Advertisement" and "Spotify" to see if an ad is playing. These names are specific to the moment when ad is being played in Spotify.
The script is run in an interval, and does not fetch data real-time, so has small delays in runtime. As it is short and easily processed, does not load up CPU and doesn't leak memory.
The code: (Requires ctypes and pycaw libraries)
import ctypes #process find
import time #sleep
from pycaw.pycaw import AudioUtilities #mute
while True:
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
/r/Python
https://redd.it/cefijn
reddit
r/Python - Simple python script that mutes sound when Spotify app runs an ad
139 votes and 35 comments so far on Reddit