[Python] Spotify Adblocker

Posts 1–3 of 3 · Page 1 of 1
[Python] Spotify Adblocker
SPOTIFY AD BLOCKER
My first release and I'm learning Python again after years.
IT IS VERY SIMPLE

Project is open source

spotify_adblocker.py

Code:
from __future__ import print_function
import platform
from random import random
import urllib.request
import shutil
from shutil import copyfileobj




if "Windows" in platform.system():
    
    file = "C:\Windows\System32\drivers\etc\hosts";
    
    urllib.request.urlretrieve("https://gist.githubusercontent.com/opus-x/3e673a9d5db2a214df05929a4eee6a57/raw?"+ str(random()), "hostfile.txt")
    
    #  shutil.copy(file, 'hosts.bak')
    #  ^ If this is emitted, please backup your hosts manually
    #  If you decide to go back, this is your original file content of hosts
    
    with open('C:\Windows\System32\drivers\etc\hosts', 'ab') as output, open('hostfile.txt', 'rb') as input:
        copyfileobj(input, output)
    
else:
    print("Windows Only")
Run this program with administrator privilege to avoid errors

MAKE A BACKUP OF YOUR HOSTS FILE C:\Windows\System32\drivers\etc

What this program does is retrieves data from a list on github which is updated daily of servers that contain Spotify advertisements. It then copies it to your hosts file to block them.

You're better of using the browser application of Spotify and using Ad blocker there, but I just wanted to release something incase you wanted to see the method.
Fun project. But you can use Notepad to edit the hosts file. No need to use an entire programming language to do it for you.
True however this retrieves a list which is updated daily, automatically so you don't have to do anything except run the program rather than navigating to your hosts file and finding a good list to paste on there
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us