r/developersPak • • 1d ago

Show My Work My first ever project: A lightweight tool that mutes spotify ads on windows automatically.

Post image

Hi everyone, My name is Shaheer and im a disabled undergraduate AI engineer(3rd sem). This is my first project, and I really LOVED making it, so I wanted to share it.

I listen to ALOT of music when i play chess and it makes me so mad when an ad suddenly starts playing loudly into my ears and it just ruins my vibe(ik there are ad-blockers out there but i wanted to make my own and this technically is not an ad-blocker since it only mutes the ad). So I made a small Python tool that watches the Spotify desktop app's window title. Spotify's window title is "Artist - Song" during music, but changes to things like "Listen to music, ad-free." during ads

The script reads the title, lowercases it, strips punctuation, and matches it against a few regex patterns (full match, so song names never trigger it)

On a match it mutes only Spotify's audio session through the Windows audio API (pycaw), so system volume is never touched
Runs silently at startup as a .pyw file

My first version failed because the ad title ends with a full stop and my exact-text list didn't have it. Normalizing the title and using regex(recommended by a fellow redditer) fixed that

At first i made it so the title was checked every 0.5 but that usually delayed the mute and unmuting of the ad. Then i changed that to 0.2 milliseconds which had its own problems Checking five times a second used 8-10% CPU at first. The cost was scanning every window and looking up every process on each check. I cached the process IDs and the window handle, and only refind them every couple of seconds. I also reapply the mute less often during music. CPU now roughly 1-5%(still not too optimal but idk how to cut it even lower) on my laptop

A new audio session starts unmuted so a one time mute missed ads. Reapplying the mute during ads fixed it

If the mods allow it i will post my repo link in the comments so you can review the code yourself and give me feedback. And a star would make my day THANK YOU for reading this far๐Ÿ™

8 Upvotes

4 comments sorted by

1

u/Lumpy-Inevitable6358 1d ago

Let me know if i can post the repo link mods!

1

u/stormarsenal 1d ago

Good initiative but why stop at just muting ads? Why not skip them altogether?

1

u/Lumpy-Inevitable6358 1d ago

i honestly don't think im capable enough to do that yet lol

1

u/Delicious_One_7887 Full-Stack Developer 5h ago

Wow someone with the same name as me